Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Generate Unique Number, Compare To Rest Of Numbers In A Field In Database


i am generating a unique 10 digit number for every entry in my database, as it is entered. you just click a button while you're entering data and it will generate this unique work order number via the code below. the command inserts it into the record in the Work_Order_Number field in my access 2000 database. it uses the year as the first four digits, the month as the 5th and 6th digits, and then uses a recordcount as the last four digits. it works, and there's no problem with the code below. my problem is that i want to compare the variable WORK_ORDER to the rest of the work order numbers in the database, to make sure i am not generating a duplicate work order number. somehow, i need to scan the recordset, compare every entry in the Work_Order_Number field to my WORK_ORDER variable. if there is a match, i.e, i'm trying to generate a duplicate work order number, then add something to the WORK_ORDER variable to make it unique. if there is no match, i.e., this work_order number is unique, then perform that last line of code where txtworkorder.text = WORK_ORDER. the unique 10 digit number doesn't have to be 10 digits, i just came up with that for the hell of it.

i don't really know where to start. any ideas? thanks.



private sub cmdworkorder()

dim recordcount as string
dim year as string
dim month as string
dim month_if as string
dim recordcount_if as string
dim work_order as string

year = DatePart("yyyy", Date, vbUseSystemDayOfWeek, vbFirstJan1)
month = DatePart("m", Date, vbUseSystemDayOfWeek, vbFirstJan1)

if month < 10 then
     month_if = "0" + month
end if

recordcount = adodc1.recordset.recordcount

if recordcount < 10 then
     recordcount_if = "000" + recordcount
elseif 10 <= recordcount < 100 then
     recordcount_if = "00" + recordcount
end if

work_order = year + month_if + recordcount_if

txtworkorder.text = work_order

end sub

 




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Generate Unique Numbers To Reference Individual Forms
Does anyone know how to write a macro for use in excel 2000 that would generate a unique number to be assigned to a form? I have seen something on an excel template for invoices but the workbook is password protect by the software. Would appreciate some help on this. Thanks

Anita (MacroVB6 novice)

Generate Unique Random Number (min And Max Length = 6)
hi all,

been looking into the rnd function that i have no experience with. i need to generate unique random numbers that are always a minimum and maximum length of six characters.

havent found anything on vbf that answers my question. can anyone give me any pointers? thanks in advance.

Generate A Unique Value To Form In VB At FORM LOAD. The Database Is SQL SERVER 2000. This
Hi,
The main purpose is that i need to generate a unique value to form in VB at FORM LOAD. The Database is SQL SERVER 2000. This application is a multiuser.

For this , I have a stored procedure which gets the maximum value and then add 1 to it and the same value is retrived into VB Form at ONLoad Event. I have noticed that i am not getting unique values into the form. i get this very rare once for every 5000 records (approx)
The stored procedure is

ALTER procedure taskno_sp
@max_tkpaid3 int=0
as
select @max_tkpaid3=max(tkpano)+1 from tkpaid
insert into tkpaid (tkpaid) values(@max_tkpaid3)

return @max_tkpaid3


Please help me in this issue and is there any way we could lock a stored procedure, so only once user can access it at a time.

Date Compare Database Field??
I am using this code here to compare a text box with a date and todays date.

dateD = DateDiff("d", Form2.Text26, Date)

I would like to be able to compare to a database record field I have but I cant seem to find a way that works. I want to compare the date with the record field in database.

thanks Nick

*RESOLVED* Copying Data From Database And Assign New Unique Number
I have a table that holds 5 fields, field1 is the unique number and field2-5 are the details.

i.e. If I have a number cars, the same make and model, all details are the same except for the unique car number. So how can I copy the details from CAR001 to CAR002?

How To Generate A Unique ID
I've recently downloaded some trial programs and I have seen that when you try to register them they generate some sord of Unique ID or machine code and then ask for a username/password. I was wondering if there is a way to generate a number or code that is unique to every PC in VB.
And if you regenerte the code after some time it must still match the code generated in the first place so I do not want a time-based one like GUID.
And it must not store the code somewhere on HD (like registry or encrypted file) becuse if someone manages to find this location it's bad going for my prog then. I also expect some APIs to do the job. So any hints???

How To Generate A Unique ID
Hi,
I have an registration page and instead of the user setting their own password, I want to generate a unique ID number, 6 digits or so, like an accout number that can use as their password,
does anyone know how to do this?
thanks

Auto Generate Unique Key
can MySQL auto generate a unique key. Because i want to auto generate a unique key for a field and it always keep on increment by 1 whenever a new record is insert. please help.

Code To Generate Unique ID ?
I have a form where the user enters values into a text-box and these values populate a table in a database.

All very well and good.

However, I have a column in this table called ID and I am wanting a special ID to be generate each time the user fills in a new entry.

It doesn't even have to be a unique ID, just an incriment of 1, 2, 3...

This HAS to be simple, right?

Generate Unique Table Name
Hi all,
I want to generate Unique Table Name in SQL Server on click of button. Then dump the data in the table, on unload of form the Table should be deleted from SQL. Is there any way to generate a Unique Table Name

Please Help

How To Compare Date Field In MS ACCESS That More Than 2year Compare To Sysdate In Sql
How to compare Date field in MS ACCESS that more than 2year compare to sysdate in sql


this is my simple logic... but not work....


Code:
SELECT ACName,year(InDate)
FROM ACInfo
HAVING (year(date()) - Max(year(InDate))>=2)
GROUP BY ACName

Can I Read Something Unique On Each PC To Generate Serial No?
Hi,
I want to create serial no that can use only in 1 PC and this serial
cannot use on other.
I need something that unique on each PC
Such as CPU Serial ...
for generate my serial no

Can I get its? and How to?

Thank you

Generate Unique Filenames At Runtime
Does anyone have any nifty(read easy) ways to generate random unique filenames at runtime? I was thinking maybe date and time stamp.

Want To Generate Unique File Name Everytime
i am creating a text file using some of the rows from a oracle table,using open stmt like
open "11:30:30feb 20.txt",filenum
but i want to have unique file name with current date and time, i.e. the text inside two double quotes ("txt.text") should be new one whenever i click a command btn.
e.g. - 11:30:30feb 20.txt
sub cmd_click()
open "11:30:30feb 20.txt",filenum
Print string
end sub
if anyone have an idea pl let me know.

Listbox Unique Or Compare
lets say I have 2 listboxes.. they both will hold names that will be use for replacing things... lets say list 1 is built.. now I building list 2 and I find a value that I know is in list one.. is there a quick method in the listbox to check if exists ? cause I dont want
to add it to list 2 if its in list 1.. then I was thinking I should
just have one list but then it still just adds it in twice..

so if anyone knows a quick way to do a compare.. (with
a method, I can write a loop if I need to)

or a way to set the listbox as unique...

tanks...

How Can You Generate A Unique Id Linked To A Clients Machine?
Linked to their hardware or windows serial or something..

Basically I want to distribute my app as a trial, and they will need an access code to unlock it. The access code will be only for their access key which is unique to their machine.. but I have no idea how i can create such an access key :P

Generate Unique Random Integer In Given Range
I am sure there must be a function available that can generate a unique random integer in a given range.

Inputs:

Upper limit
Lower Limit
Array of integers between upper and lower limit.

Output:

A random integer that does not exist in the [array of integers between upper and lower limit], but is not greater than the upper limit or not less than the lower limit.

Example:

Upper limit = 10
Lower limit = 1
Input Array = {1,6,2,9,4,3}

An allowed output is an element of the set {5,7,8,10)

If you have the solution I would be most grateful.

I received an email that shows that it does not matter in what sequence letters occur in a word, but providing the first and last letters of the word are the same, then you will be able to read the word correctly without even having to think about the order of the letters. So I am going to use this principle as part of a password generator to generate passwords that are easy for users to remember. An example:

My nmae is Mike and I am a cmptuoer pmeoramrgr.

How To Generate Unique Shuffled Alphanumeric Chars ?
Hai ........,
              Can anyone please help me to sort out the problem of generating shuffled alphanumeric character (can be upto 30 chars) . Each time the combination that is generated should not be repeated forever. I think it's just like the serial number that are generated by the companies for their product. Any suitable algorithm or idea is appreciated...

Thanx,
Hemant

[VB6] Compare, And Generate New
Hi

I would like to know how I should do the following :

I input 3 or more strings (eg "kf - 12", "kd - 13", "fd - 23"), and then I would like to generate another (eg "kk - 11").

I am using VB6

Thanks

Greets
Kosty

Need To Validate A Phone Number Field Which Will Be Called From An Access Database
I am building a beginner's database for school. I used VB to build a form out of an Access database. My assignment is to validate and automatically edit the phone number field to store the input in a specific format. I know that the logical thing to do would be to lock the input format in the properties, but the assignment is to remove the "1", parentheses, and dashes, if there are any, then display the number in this format...(xxx)xxx-xxxx, regardless of whether the user enters 1-xxx-xxxx, 1xxxxxxx, 1 xxx xxxx, 1(xxx)xxx-xxxx, (xxx)xxx-xxxx, or what have you. Is there a chunk o code out there? Thank you for being here to read these strings and attempt to help, by the way. It is admirable that some have come far enough in their learning and are still motivated to take time to help others....hope to be helping others one day myself...Peace, friends

P.S. Attached is the little database that I am using to build the form. It is in Access 97 format because the learning edition of VB6 will not accept anything else.

Unique Numbers
Hi,
I have an array of six textboxes on the form..(text1(0),text1(1),......text1(5) ) I need to fiil all the six text boxes with random numbers
between(1-20).. I mean each text box should have six unique numbers..I failed to figure it out.
for example:
text1(0).text=1,5,7,11,14,19
text1(1).text=4,5,8,11,16,20
text1(2).text=1,2,9,10,14,15
text1(3).text=7,3,13,16,14,19
...........................
.................................



Thanks for any help




VB Code:
Private Sub Command1_Click()Dim i As LongFor i = 0 To 5Text1(i).Text = Int(Rnd * 20) + 1 & ","NextEnd Sub

Unique Numbers
Hi,
I have 12 textboxes on the form..I need to store unique numbers in textboxes
I mean the number in a textbox should be differrent from the others..
How do you scramble the numbers..? I did the following one but some time ı get the same numbers..
thanks..

VB Code:
Private Sub Command1_Click()For n = 0 To 11Text1(n).Text = Int(Rnd * 12) + 1NextEnd Sub Private Sub Form_Load()RandomizeEnd Sub

Unique Numbers
Hi,
I have 9 textboxes on the form..
.and each textboxes should have a unique random number from 1 to 20
How can I achieve that?
Here is all I have so far...
Thanks in advance.


VB Code:
Dim rno0 As LongDim rno1 As LongDim rno2 As Long Private Sub Command1_Click()RandomizeFor a = 0 To 2rno0 = Int(Rnd * 20) + 1Text1(a).Text = rno0Next aFor b = 0 To 2rno1 = Int(Rnd * 20) + 1Text2(b).Text = rno1Next bFor c = 0 To 2rno2 = Int(Rnd * 20) + 1Text3(c).Text = rno2NextEnd Sub

Getting Unique Numbers?
I am writing a lottery program. I am using the rnd() function to generate random numbers, however, in a set of 6 numbers, sometimes there are duplicates. Anyone know how to eliminate that?

Thanks

Unique Numbers
I am developing a database that will store information about Electricity meters. Each meter has a MPAn(serial) number that is unique(thus it was made as the primary key).

I want to know how to do the following..


1) I type a number in, eg 123 and save it.It then gets put in the database table.

2) i go to the next record and type in 123 again...This is my problem..Instead of creating a new record,How do I get it to go back to the record that has the unique number 123.

I hope the prolem is clear to see.Any help would be helpful. I was trying to use recordsets, but I'm very clueless aout them at the moment.

Unique Numbers
Will somebody please help a newbie create unique numbers in VB6, hopefully using DateTime stripped of non-numeric characters?
Any help gratefully accepted.

Compare Numbers And Save Numbers
Hi pros,
set 1 52
set 2= 1325
Now i make a compare these two set of numbers.
if mid(set1,Acounter,1)<>mid(set2,Bcounter,1)then
set 1 first no.1 match with set 2 no.1 =right number
IF set 1 no.2 match with set 2 no.2 but at third position once it match will end the loop. How can i save the set 2 no.5 in fourth position?

Thank you.


Yahoo! Biztools
- Promote your business from just $5 a month!

Unique Random Numbers
heres one for you:
i have 9 labels
each label represents a playing card
they must be randomly assigned a number between one and 11
(ace, 2, 3, 4, 5, 6, 7 ,8 ,9 ,10, Jack)
but there can be no duplicate numbers
so you could have: 3 1 5 8 6 10 2 11 4 7 9
but not: 3 1 5 3 6 10 2 3 4 7 3

i can only get it to assign random numbers with duplicates...
can someone help me out with this?
im sure i could get it if i wrote 200 odd:
if ( cardNumber1 = cardNumber2)
statements.

thanks

Random But Unique Numbers ?
I've written a simple program that generates 6 random numbers
but I don't know how to keep the numbers unique.
(I.E textbox1 and textbox2 HAVE to be different numbers.
I'm using 6 textboxes in total)

Can anyone help and maybe provide some sample code?

And yes I have called the "Randomize" function on the
form load to stop the same numbers appearing.


EDIT:
This is the code i'm currently using to try and keep the numbers random.

If Text1.Text = Text2.Text Then Text1.Text = Rand(1, 49)
If Text1.Text = Text3.Text Then Text1.Text = Rand(1, 49)
If Text1.Text = Text4.Text Then Text1.Text = Rand(1, 49)
If Text1.Text = Text5.Text Then Text1.Text = Rand(1, 49)
If Text1.Text = Text6.Text Then Text1.Text = Rand(1, 49)

If Text2.Text = Text3.Text Then Text2.Text = Rand(1, 49)
If Text2.Text = Text4.Text Then Text2.Text = Rand(1, 49)
If Text2.Text = Text5.Text Then Text2.Text = Rand(1, 49)
If Text2.Text = Text6.Text Then Text2.Text = Rand(1, 49)

If Text3.Text = Text4.Text Then Text3.Text = Rand(1, 49)
If Text3.Text = Text5.Text Then Text3.Text = Rand(1, 49)
If Text3.Text = Text6.Text Then Text3.Text = Rand(1, 49)

If Text4.Text = Text5.Text Then Text4.Text = Rand(1, 49)
If Text4.Text = Text6.Text Then Text4.Text = Rand(1, 49)

If Text5.Text = Text6.Text Then Text5.Text = Rand(1, 49)


Is that ok or is there a better way to do it?
(I presume there is)

Randoming Unique Numbers
Hi guyz... One quick help, ummm I want to have a set of random numbers from 0 - 69. For example I have an array Set(70) and Set(0) will be 45, Set(1) will be 32, Set(2) will be 10, Set(3) will be 65, and so on.. What I need is to fill the entire Set() with numbers from 1 to 70 all randomly positioned, and no repeating numbers. Got it?

I tried this one with my code, It worked pretty well for 0 - 19, but when I was trying 0 - 69 im getting an endless loop with my code


VB Code:
Public Sub Randomize()   Dim aCtr As Long, bCtr As Long, nowIndex As Long, pastIndex  (TOTAL) As Long, duplicate As Boolean            duplicate = True   For aCtr = 0 To (TOTAL - 1)      pastIndex(aCtr) = -1   Next    For aCtr = 0 To TOTAL_CARDS - 1      Do While duplicate = True         nowIndex = Round(Rnd() * 20)                           For bCtr = 0 To TOTAL - 1            If pastIndex(bCtr) <> nowIndex Then               duplicate = False            Else               duplicate = True               Exit For            End If         Next      Loop            For bCtr = 0 To TOTAL - 1         If pastIndex(bCtr) = -1 Then            pastIndex(bCtr) = nowIndex            Exit For         End If      Next               duplicate = True   Next            End Sub


what could be wrong with my code? Have I over looped? or its just not the way its suppose to be. I havent done this randomizing exercise before..

Need Help... Thanks for all the help....Love yah guyz

Unique Random Numbers
Iam getting random numbers in specified range but some numbers are repeated when it is small range and less numbers to generate. Each time i run the code the same sequence is shown. can some one help me solve this problem.

Unique Random Numbers
I could have sworn I saw I method or API Call to generate a "unique" random number somewhere, but I can't find it.

Anyone know how to?

Thanks,
Josh

[Help] About Storing Unique Random Numbers
Hello, I'll take my time introducing myself, since this is my first post (yes, I know, I'm very sorry I only registered because I had this problem, but I wasn't connected to VB at all before this little issue). I take Economics at the Portuguese Catholic University, currently at my first year of undergraduation.

As you can see, I'm not very connected to computers (except I used to play games, that doesn't really count much) but I do have to do a work with Excel and VB.

Just before you keep on reading, I am very new at this, I do not understand most of the concepts, however interested I am, I lack of knowledge and I don't know where I can gain that knowledge, that is why I'm posting here. Having read some posts (about pseudo random numbers) and seeing how nice people are here, I decided to give it a shot.
Here's the game:

It's a memory game. There are 36 figures (equals in pairs), that must be hidden from the player, only two of them can be seen at the same time, if they're not equals, they go into hiding again (it's really like a memory game, I can explain it further, but I wish my problem was in that stage already ihihih) and I have to randomly assign a figure to a cell (Picture 1). I've spent the whole day... In this very first step. Could you imagine yourself in my position? I'd go nuts if I were me!

I thought: "I'll do it with only 6 figures (actually, just the cells, because I don't know how to move figures yet either) then I'll apply the method to the 36!". Yup, I really thought that would work... I turned with this:


Code:
Option Explicit
Dim players(5) As Integer
Dim a(1 To 6) As Integer


Private Sub CommandButton1_Click()
Range("F15", "H16").Delete

players(0) = Int(rnd() * 6) + 1

Do
players(1) = Int(rnd() * 6) + 1
Loop Until players(1) <> players(0)
Do
players(2) = Int(rnd() * 6) + 1
Loop Until (players(2) <> players(0) And players(2) <> players(1))
Do
players(3) = Int(rnd() * 6) + 1
Loop Until (players(3) <> players(0) And players(3) <> players(1) And players(3) <> players(2))
Do
players(4) = Int(rnd() * 6) + 1
Loop Until (players(4) <> players(0) And players(4) <> players(1) And players(4) <> players(2) And players(4) <> players(3))
Do
players(5) = Int(rnd() * 6) + 1
Loop Until (players(5) <> players(0) And players(5) <> players(1) And players(5) <> players(2) And players(5) <> players(3) And players(5) <> players(4))

a(1) = players(0)
a(2) = players(1)
a(3) = players(2)
a(4) = players(3)
a(5) = players(4)
a(6) = players(5)

If a(1) = 1 Then
Range("F11").Select
Selection.Copy
Range("F15").Select
ActiveSheet.Paste
Else
If a(1) = 2 Then
Range("f11").Select
Selection.Copy
Range("G15").Select
ActiveSheet.Paste
Else
If a(1) = 3 Then
Range("f11").Select
Selection.Copy
Range("H15").Select
ActiveSheet.Paste
Else
If a(1) = 4 Then
Range("f11").Select
Selection.Copy
Range("F16").Select
ActiveSheet.Paste
Else
If a(1) = 5 Then
Range("f11").Select
Selection.Copy
Range("G16").Select
ActiveSheet.Paste
Else
Range("f11").Select
Selection.Copy
Range("H16").Select
ActiveSheet.Paste
End If
End If
End If
End If
End If






If a(2) = 1 Then
Range("g11").Select
Selection.Copy
Range("F15").Select
ActiveSheet.Paste
Else
If a(2) = 2 Then
Range("g11").Select
Selection.Copy
Range("G15").Select
ActiveSheet.Paste
Else
If a(2) = 3 Then
Range("g11").Select
Selection.Copy
Range("H15").Select
ActiveSheet.Paste
Else
If a(2) = 4 Then
Range("g11").Select
Selection.Copy
Range("F16").Select
ActiveSheet.Paste
Else
If a(2) = 5 Then
Range("g11").Select
Selection.Copy
Range("G16").Select
ActiveSheet.Paste
Else
Range("g11").Select
Selection.Copy
Range("H16").Select
ActiveSheet.Paste
End If
End If
End If
End If
End If






If a(3) = 1 Then
Range("h11").Select
Selection.Copy
Range("F15").Select
ActiveSheet.Paste
Else
If a(3) = 2 Then
Range("h11").Select
Selection.Copy
Range("G15").Select
ActiveSheet.Paste
Else
If a(3) = 3 Then
Range("h11").Select
Selection.Copy
Range("H15").Select
ActiveSheet.Paste
Else
If a(3) = 4 Then
Range("h11").Select
Selection.Copy
Range("F16").Select
ActiveSheet.Paste
Else
If a(3) = 5 Then
Range("h11").Select
Selection.Copy
Range("G16").Select
ActiveSheet.Paste
Else
Range("h11").Select
Selection.Copy
Range("H16").Select
ActiveSheet.Paste
End If
End If
End If
End If
End If






If a(4) = 1 Then
Range("F12").Select
Selection.Copy
Range("F15").Select
ActiveSheet.Paste
Else
If a(4) = 2 Then
Range("f12").Select
Selection.Copy
Range("G15").Select
ActiveSheet.Paste
Else
If a(4) = 3 Then
Range("f12").Select
Selection.Copy
Range("H15").Select
ActiveSheet.Paste
Else
If a(4) = 4 Then
Range("f12").Select
Selection.Copy
Range("F16").Select
ActiveSheet.Paste
Else
If a(4) = 5 Then
Range("f12").Select
Selection.Copy
Range("G16").Select
ActiveSheet.Paste
Else
Range("f12").Select
Selection.Copy
Range("H16").Select
ActiveSheet.Paste
End If
End If
End If
End If
End If



If a(5) = 1 Then
Range("g12").Select
Selection.Copy
Range("F15").Select
ActiveSheet.Paste
Else
If a(5) = 2 Then
Range("g12").Select
Selection.Copy
Range("G15").Select
ActiveSheet.Paste
Else
If a(5) = 3 Then
Range("g12").Select
Selection.Copy
Range("H15").Select
ActiveSheet.Paste
Else
If a(5) = 4 Then
Range("g12").Select
Selection.Copy
Range("F16").Select
ActiveSheet.Paste
Else
If a(5) = 5 Then
Range("g12").Select
Selection.Copy
Range("G16").Select
ActiveSheet.Paste
Else
Range("g12").Select
Selection.Copy
Range("H16").Select
ActiveSheet.Paste
End If
End If
End If
End If
End If




If a(6) = 1 Then
Range("h12").Select
Selection.Copy
Range("F15").Select
ActiveSheet.Paste
Else
If a(6) = 2 Then
Range("h12").Select
Selection.Copy
Range("G15").Select
ActiveSheet.Paste
Else
If a(6) = 3 Then
Range("h12").Select
Selection.Copy
Range("H15").Select
ActiveSheet.Paste
Else
If a(6) = 4 Then
Range("h12").Select
Selection.Copy
Range("F16").Select
ActiveSheet.Paste
Else
If a(6) = 5 Then
Range("h12").Select
Selection.Copy
Range("G16").Select
ActiveSheet.Paste
Else
Range("h12").Select
Selection.Copy
Range("H16").Select
ActiveSheet.Paste
End If
End If
End If
End If
End If






End Sub
Then I thought again: "Wow imagine doing this with... 36 numbers! I need help!". Since the only thing I got from the books and slides were Ifs and Loops, here I am!

Could anyone help me? So that I come back a little later stuck at the... 2nd step?

Thanks a lot,
phredd


[edit]
Or, if it's a very silly question (and I'm sorry if it is; plus, it probably is for 99% of you ahah), could you please indicate me a site, guide or anything (computer based if possible, since I can't afford books at the moment) that might be able to help me, or teach me? If you're wondering, I did try to find one, but I failed miserably.

[EDIT 2]
Does a file exist with most of the commands for VB, with little to no information about them?
I'm sorry I keep editing.

Unique Sort Numbers Problem - Please Help!
Hi all! Need some code to get me going on a personal project (NOT homework in any form) which has me stumped (none of the fastsort methods really do what I need, and it has proven challenging to many VB gurus i've talked to):

First of all, I have some stats stored in arrays, including the character's league "points" stored in an array called wapoint(9), starting at element 1, which is already declared as a global. During the course of the game, the points may change.

I am now designing a league "standings" screen where I want to display all 9 characters displayed in descending order from the highest to the lowest based on the character's accumlated points so far. The code must account for ties as well, defaulting to the first character in order sequentially in the event of a tie.

Purely as an example, say this is the array:

wapoint(1)= 2
wapoint(2)= 1
wapoint(3)= 4

I need code that will go through the numbers, and assign the array subscript of the highest number (array subscript 3 in this case) to a separate variable called toppt1, then the array element of the second highest number (number 1 in this case) to the next variable, called toppt2, and so on. That way, it will be easy to display the stats for the characters. In my project, wastr() is the characters strength, waspe() is the characters speed, etc.

Example below that will be used for display purposes:

For 1st place points:
label1=wastr(toppt1):label2=waspe(toppt1)
For 2nd place:
label3=wastr(toppt2): label4=waspe(toppt2)
3rd place:
label5=wastr(toppt3):label6=waspe(toppt3)

Thanks for any help!

&lt;resolved&gt; 6 Unique Random Numbers
hello guys
siince I am giving up hope in becomeing millionaire by programming I am making a little program to give me 6 random numbers [unique] between 1 and 49.
I am using the code in the bottom of this question. It more or less works, but occasionally it gives me the same number despite my code. Can anyone tell me why? Also, this is a clumsy and bulky way to do this [I admit myself]. Does anyone have a more ellegant way of coding this?
Best ragrds SW
PS. If I did win the lotto I will share some with the guy who helped with the code

Here is my code:

Code:

Randomize
n0 = Int((Rnd * 49) + 1)

n1 = Int((Rnd * 49) + 1)
If n1 = n0 Then
n1 = Int((Rnd * 49) + 1)
End If

n2 = Int((Rnd * 49) + 1)
If n2 = n1 Or n2 = n0 Then
n2 = Int((Rnd * 49) + 1)
End If

n3 = Int((Rnd * 49) + 1)
If n3 = n2 Or n3 = n1 Or n3 = n0 Then
n3 = Int((Rnd * 49) + 1)
End If

n4 = Int((Rnd * 49) + 1)
If n4 = n3 Or n4 = n2 Or n4 = n1 Or n4 = n0 Then
n4 = Int((Rnd * 49) + 1)
End If

n5 = Int((Rnd * 49) + 1)
If n5 = n4 Or n5 = n3 Or n5 = n2 Or n5 = n1 Or n5 = n0 Then
n5 = Int((Rnd * 49) + 1)
End If


txtN(0).Text = n0
txtN(1).Text = n1
txtN(2).Text = n2
txtN(3).Text = n3
txtN(4).Text = n4
txtN(5).Text = n5

Generating A Unique Series Of Numbers.
I have an idea but not sure if it's possible, but should certainly present a challenge to the 'experts' out there.

I am currently working on an application that can update its data online. This part of it is not a problem, but I am wanting to implement a certain level of security.

I thought that one way would be to have the application generate a number that was used as a transaction validator and presented to the server when the update was requested. The server would check whether this was valid and if so start the update.

Each time the update was requested a new transaction validator would be created

I know how to create a unique ID but does anybody know If there is a way of created a list of numbers unique to a PC but that can also be re-created else where.

ie:

a users PC creates a 'random' list of numbers:
1434,3455,3244,4252

but the server can also re-create the same list.
1434,3455,3244,4252

Then each time they connect the generated number is compared. Each PC that might connect would have it's own seperate list of values, and the server would be able to produce a correct result for whichever PC was trying to perform an update.

Mmmmm hope I explained that well enough.

Unique Random Numbers In An Array
Could someone please help me out with understanding part of this code.  I can not remember where I got it from a few years ago.  Can someone explain how the mainloop does not generate dupes when ran?  Thanks.

Private Sub GenerateUniqCode()
    DoEvents
    ' ---------------------------------------
    ' Produces a series of X random numbers
    ' without repeating any
    ' *** Results can be used by using array B(X) ***
    '---------------------------------------
    MaxNumber = 205151 ' Must equal the Dim above in General Declarations Section

    ' Generates the list of numbers
    For seq = 0 To MaxNumber
        A(seq) = seq
    Next seq

    ' Main Loop (mix em all up)
    For MainLoop = MaxNumber To 0 Step -1
        ChosenNumber = Int(MainLoop * Rnd)
        B(MaxNumber - MainLoop) = A(ChosenNumber)
        Dict.Add A(ChosenNumber), A(ChosenNumber)
        A(ChosenNumber) = A(MainLoop)
    Next MainLoop

End Sub

Swi

Unique Random Numbers In An Array
Hi everbody,

I have this array called rotor which needs to be filled with random unique numbers from 1 to 127. Every number can be used only once. If I use this code:
Code:For y = 1 To 127
     rotor(y) = Int(127 * Rnd() + 1)
Next y
There is a chance a number occurs more then once and some numbers are missing.

Who has a better piece of code for me?

John

<-------------------------------------------------------------------------------------->
Please put [RESOLVED] in the subject line off your first post when your done.

Edited by - johnminkjan on 5/30/2004 11:00:37 AM

Create Unique Random Numbers
Would anyone help?

i need to create some random numbers within a range 0~100. but VB creates random numbers according to a sequence. so i end up with getting somewhat not so radom numbers. Or in next loop, some of them are the same as the previous loop.

this is the code i used:

...
Randomize
j(i) = Int((upperbound - lowerbound + 1) * Rnd() + lowerbound)
...

any help are appreciated. thanks a lot

[ADO] How To Know When A Field Is Unique?
With ADODB, how can i get information about wheter a field accepts all data or only unique data ?

In other words, how can i see if the field as an Index of type Unique?

Generate Numbers
hallo all. my problem is ....
i created one application for generating random numbers and using a one module for generating from vb page with code.. so..
i created a textbox named txtbox3 and txtbox1 for input user defined number for start and stop generating numbers.
everytime a program generating numbers starts from " 1 " to user defined number.
where is a problem but no start generating from textbox input number.
i gave a sample code of program.

interface having a
one listbox named text2
two textboxes named text1 and text3
one button named Command1

code of Form1.vb

Dim sequence() As Integer

Private Sub Command1_Click()
Text2 = ""
If Not (IsNumeric(text3.Text)) Then
MsgBox ("Pleace Enter a number")
Exit Sub
End If
If Val(text3) = 0 Then Exit Sub
ReDim sequence(Val(text3.Text))
If (getnewsequence(sequence, Val(text3.Text))) Then
'Debug.Print " sequence generated OK"
Else
'Debug.Print " sequence NOT generated "
End If
Dim Text1 As Integer
For Text1 = Text1 To Val(text3.Text)
Text2.AddItem (Text2 & sequence(Text1))
Next
End Sub

Private Sub Form_Load()
Text1 = Text1.Text
End Sub


code of module ... module named a " modrndnumgen "

Dim uniqueseq() As Integer
Dim numberofnumbers As Integer
Public Function getnewsequence(sequence() As Integer, number As Integer) As Boolean
On Error GoTo error
ReDim sequence(number)
Dim Text1, newnum As Integer
numberofnumbers = number
ReDim shufseq(numberofnumbers + 1)
ReDim uniqueseq(numberofnumbers + 1)
newnum = Randomgen
uniqueseq(1) = newnum
sequence(1) = newnum
For Text1 = 2 To numberofnumbers
Do
newnum = Randomgen
Loop Until ((checkifexists(newnum)) = True)
uniqueseq(Text1) = newnum
sequence(Text1) = newnum
Next
getnewsequence = True
Exit Function
error:
getnewsequence = False
End Function

Private Function Randomgen() As Integer
On Error Resume Next
Randomize
Do
Randomgen = Int((numberofnumbers + 1) * Rnd)
Loop Until Randomgen <> 0
End Function
Private Function checkifexists(number As Integer) As Boolean
On Error Resume Next
Dim Text1 As Integer
For Text1 = 1 To numberofnumbers + 1
If number = uniqueseq(Text1) Then
checkifexists = False
Exit Function
End If
Next Text1
checkifexists = True
End Function


i dont no where is a problem may be a
numberofnumbers = 0
to starts from 0 generate
i try to change it and gives me errors

How To Generate Numbers
Hello VB Experts! Do any of you know how to generate random numbers in Visual Basic 6 Professional?


Thanks

Generate Numbers
I created a generated number application that stores in an array with indexes 1 to 100 numbers. Generate the number to be stored at each index by summing the index and its individual digits. Example, 25 should be stored at index 17 cause 17 + 1 + 7 = 25 and 4 should be stored at index 2 cause 2 + 0 + 2 = 4. Heres the code I got so far.


Code:

Option Explicit

Private Sub cmdDone_Click()
Unload Me
End Sub

Private Sub Form_Load()

Call FillArray
Call DisplayArray

End Sub

Sub FillArray()
Dim intNumbers As Integer
Dim intGenerate As Integer
intGenerate = intNumbers + 1
For intNumbers = 1 To 100
lstOutcome.AddItem intNumbers & vbTab & intGenerate
Next
End Sub

Sub DisplayArray()
Dim intNumbers As Integer
lstMessage.AddItem "Index" & vbTab & "Generated Number"
For intNumbers = 1 To 100
lstOutcome.AddItem intNumbers
Next
End Sub

Array Help (generating Unique Random Numbers)
ok the problem i have is i want 6 random numbers to be generated inside 6 text boxes i then want the 6 boxes to be checked so they dont have


Code:

spent = spent + "1"
lblSpent = ("£" & spent)

For x = 0 To 10

ball(x) = Int(Rnd() * 10) + 1

Next x

For x = 0 To 5

lblResult(x) = ball(x)
Next x


lstWinningNums.AddItem (lblResult(0) & " " & lblResult(1) & " " & lblResult(2) & " " & lblResult(3) & " " & lblResult(4) & " " & lblResult(5))



that happily givs me mynumbers, so how do i use an array to check each box for the same numbers then get it to genrate a new number

Generating Machine Dependent Unique Numbers
Hi all,

I m developing an application in VB in which I have to generate a random but unique number and store it.

This unique number should be dependent on the some unique information about the machine on which it is running.

What unique information about the machine can I retrieve and how?

Regards,
MRL

"Lost opportunity is never found again"

How To Compare Two Field In Sql And Change One Field
how to compare two field in sql and change one field ...?

Unique Field Names
I have a recordset that retreives two fields with the same name from two different tables:
SELECT T1.Name, T2.Name FROM T1, T2


Code:
Dim adoRs As ADODB.Recordset
Dim fields As ADODB.fields
Dim fld As ADODB.Field

Set fields = adoRs.fields

For Each fld In fields
debug.Print fld.Name
Next
The results are Name, Name
Is there a property so I can get: T1.Name, T2.Name
Without using the SELECT T1.Name As Name1, T2.Name As Name2 ...
to get unique field names ?

Thanks,
Ziko

Generate Random Numbers With VBA
hello to all,

I've a little problem. Actually, I want to performe action resulting from conditions like IF...ELSE ...

But there is a probability of realisation of each condition.

Example: In 10% of the case, you win 1 million $, in 20% 500.000$ and in 70% you loose.

How can I do that inn VBA ?

Thanks

thomas

Generate Serial Numbers--please Help
hi all,
can any body tell me how can i use generate a sequence of numbers(serial numbers) in an excel column using Vb 6.0.
i tried out the method autofill. but it only works once. what if i want to run the same programe to generate the serial numbers.
here is the code i have tried.
Code:
On Error GoTo Messageuser

Dim xlappl As Excel.Application
Dim xlWb As Excel.Workbook
Dim xlWs As Excel.Worksheet
Dim sourcerange As Excel.Worksheets
Dim fillrange As Excel.Worksheets

Dim iCol As Long
Dim j As Long


Set xlappl = CreateObject("Excel.Application")
xlappl.Visible = True
Set xlWb = xlappl.Workbooks.Open("C: est.xls")
Set xlWs = xlWb.ActiveSheet
xlappl.WindowState = xlMaximized

' xlws.Range("A1") = grdReport.RowData(0)

xlWs.Range("A2").Select
xlWs.Range("A2").Value = 1
With xlWb
.Selection.AutoFill Destination:=Range("A2:A100"), Type:=xlFillSeries
.Range("A2:A100").Select
' .Range("A2").Select
' End With

'With xlWs.Application
' .Selection.AutoFill Destination:=Range("A2:A" & 'AdoRep.Recordset.RecordCount), Type:=xlFillSeries
' End With

' Set sourcerange = Worksheets("Sheet1").Range("A1:A2")
' Set fillrange = Worksheets("Sheet1").Range("A1:A20")
' xlWs.Range("A2").Select
' xlappl.Range("A2:A34893").AutoFill Destination:=Range("A2:A34893"), 'Type:=xlFillSeries

'xlappl.Selection.AutoFill Destination:=Range("A2:A34893"), Type:=xlFillSeries
' xlWs.Range("A2:A34893").Select
' xlWs.Range("A2").Select


' xlWs.Range("A2", "A" & AdoRep.Recordset.RecordCount).Value = xlWs.Rows.Value

the above piece of code has all the ways i tried out.

please help

reddy

Copyright © 2005-08 www.BigResource.com, All rights reserved