Hi Bails,
Sorry for the delay, I havent been receiving messages about this
thread for some reason, and one came through today - so....
The way to use that function is as follows:
1/ You need to make a new module (well it can be an existing one but
lets keep things simple for now...)
2/ in that module, lets call it 'Tatts', we copy the function code
that I posted a few posts back.
3/ remove the Option Explicit and Option Compare Database stuff from
the top of the module, I cant remember if I explicitly declared all
the variables or not so its easier for our experiment to just wipe
them out...
4/ Save this module - the function is now available to be used in the
application
5/ Go to tools -> references and select Microsoft ActiveX Data Objects
2.xx (where xx is some number) - This gives the application usage of
the ADO library needed for handling the generated data... (once you
have done this go back and check that it is actually "ticked" and
selected. The function wont work without it.)
The way the function works is to accept parameters for n and m, where
n represents the number of balls you want to take out for any single
draw, and m represents the number of balls that are possible to choose
from.
The function also accepts an ADODB.Recordset object, which is a fancy
way of saying it accepts a table in your database as something it can
work with. In order to give this table to the function we need to
first make the table if it doesnt exist, and then create the adodb
stuff necessary to make that ADODB.Recordset object that the function
needs.
What I suggest is as follows:
- Go to tables
- Create a new table
- Create six columns named "Ball1", "Ball2"......"Ball6"
- Each columns data type should be set to Number, and the field size
set to Byte
- Save the table and give it a meaningful name, maybe 6from45
Okay, we now have all the basic building blocks in place to run this
experiment. As you get better with code you will start to build code
that generates the tables for you and so on, but for now we just did
it by hand because it it more expedient.
We can now write a Sub (routine) that takes values for n and m,
creates all the necessary stuff to connect up the ADODB.Recordset, and
then passes all this to the function to do its job.
There are two ways to do this, one is via a form where you enter the
variables into fields and click a button, but we are going to do the
quick and dirty method because it is really a one time thing for this
experiment.
use the following code to 'Get the balls rolling' (ahem..poor attempt
at humour):
Create a new module, and wipe out the junk at the top
copy in the following code
Sub CrunchTime()
dim Combinations as Long
dim NumberRecords as ADODB.Recordset
dim cn as ADODB.Connection
set cn = CurrentProject.Connection
With NumberRecords
.ActiveConnection = cn
.Source = "6from45" ' - this is the name of the table
.Open
.ActiveConnection = Nothing
End With
Combinations = Spin(6,45,NumberRecords)
NumberRecords.ActiveConnection = cn
NumberRecords.UpdateBatch
NumberRecords.Close
cn.Close
Set NumberRecords = Nothing
Set cn = Nothing
Beep
End Sub
I wrote this code straight into the newsgroup editor here so check it
for typos. Make sure to save the module before running anything.
To make this run all you need to do is to place the cursor on the
first line where the Sub statement is, and click the 'play' button on
the toolbar, or go to the menubar and select run -> run / continue, or
press F5.
I am not sure how long this would take to run, maybe up to an hour or
two - depends on your processor. You would also need to make sure that
the machine you run this on has enough memory to run it. I would guess
that around 128mb to 256mb for the data while it is in memory, so
512Mb of RAM should be enough (I am guessing - you will get an error
if it is not). This routine will also use the processor 100%, so the
less junk running on the machine the faster it will go. I expect that
the whole machine will basically look frozen while this is running, so
go away and have a beer, check back on it a while later.
I hope this gets you where you want to be. You could adapt the code to
do different ball / draw combinations, just make sure you have made
the table for it before running it or it will crash. Likewise dont
forget if you run different combinations you may need much more memory
on the machine, eg/ 6 from 49 would probably blow a gig or two. There
is also a limit on how big an MDB file can be, I think its two gig.
Enjoy, have fun, and let me know how it goes
Cheers
The Frog