Need some help with an array function (1 Viewer)

MCAdude

Registered User.
Local time
Today, 19:09
Joined
Mar 4, 2002
Messages
13
Got a OnClick event that will give a random number ranging between 1 and 12. On each new record a new random number is created, but on a recordset of 12 records there should be an even divided numbercollection (1 to 12)

So I create the first record and I assign a random number to it. Let's say 1. Now the second day I create the second record and assign a new random number, this time ranging from 2 to 12 since 1 is already assigned. etc. etc.

After 12 records this process should start over again. With new random numbers ranging from 1 to 12.

I know this can be done using an array, a counter for the records and the rnd function.

Unfortunatly I'm not a real codemaster and can't get it to work. Is anybody out there who could help me with the probably "banging my head against the wall right now" answer....
 

pdx_man

Just trying to help
Local time
Today, 11:09
Joined
Jan 23, 2001
Messages
1,347
Here is a very general outline to give you some direction. I believe you still need to do some thinking through of what exactly you need to do. If you truely want to use an array, you will have to re-load it each time with what values were assigned in the previous days.

Some questions I would ask myself:
Do I NEED to have the numbers randomly generated?
By what means am I keeping my records unique?
Should I create a timestamp field when the record was created?

initialize array
For y = 1 To 12
varArray(y) = y
Next y
z = 0

find the number of records. Use the MOD function to determine how far away from having a group of 12 records. Generate a random number between 1 and the remaining recs
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("Table2")
HighLim = 12 - rst.RecordCount Mod 12
If HighLim = 0 Then HighLim = 12
HoldEm = Int(Rnd(34) * 12) + 1
rst.AddNew
rst!Field1 = HoldEm
rst.Update

remove the used number from the array
For y = 1 To 12 - HighLim
If y = HoldEm Then z = 1
varArray(y) = varArray(y + z)
Next y

These will be used in separate procedures depending on how you are accessing the data.

The first part would be for initializing the array. Per my above comments, I would think you would want to get this info from the existing dataset starting from when the last 12 records ended. It would have to have a global array variable, so the other functions could access it.

The second part can be a stand alone procedure as could the third part.

I would really figure out what I need to do first, though.

HTH



[This message has been edited by pdx_man (edited 04-17-2002).]
 

MCAdude

Registered User.
Local time
Today, 19:09
Joined
Mar 4, 2002
Messages
13
Well the unique part isn't a problem since there will be assigned a recordnumber to each record which has got nothing to do with the random number.

The random number is needed to assign a person to a location. But the person who uses the db can't see how this is done. So for example there are 2 locations (place A and B) amongst 12 numbers (this could be a different even number I just use it as an example) the locations are evenly divided. The user may not know how large the block of numbers is (in this example it is 12) so he can not guess which location comes next. (this is why I want to use a random number).

So now I've got a block where 1=A, 2=A, 3=B, 4=A, 5=B, 6=B, etc. to 12... The user doesn't know this and the persons are perfectly divided between the location.

I thought an array was the best solution, but if anybody knows a better way I would be very thankful indeed.

btw. thanks pdx_man you already helped me a lot
 

Users who are viewing this thread

Top Bottom