From: NeatBoxx via VBMonster.com on
Hi, Fellow Coders of Visual Basic 6

I have been working on a program now for a year and almost complete except
for the last module. It is the most all around lottery program I have ever
seen as far as tabulating your wins and making Lotto Wheels.

This something I took up in my retirement to while my time away. I don't
have any formal training in programming except for a course I had to take in
school way back in 1993...Programming in Quickbasic 4.5 The syntax is very
similar in Visual Basic and that's the only reason why I even took up Visual
Basic because it is easy.

If anyone can or will help; I have included my code that I have so far...It
works but very inefficiently.

The main problem is that my algorithm is not very efficient and cause'es
program crashes. I don't have the expertise to do things in programming that
others find easy...Just too old...I guess. I would appreicate any help.
Just copy and paste the code into Visual Basic 6 and read the instuctions and
you will see what I am trying to do.

Private Sub Command1_Click()
Randomize Timer
Dim v, x, y, z, t, u, w, q, j, Field, Elements, Frequency, Combinations,
Kcount, Sets As Long
Frequency = Val(Text1.Text)
Sets = Val(Text2.Text)



'.........Instructions........

' You Will Need 2 Textboxes Very Small Ones!! But Large enough To Enter
Numbers
' 2 Labels "Frequency" And "Combinations
' 1 Command Button...Copy And Paste All Code Into The Command Button

'_____________________________________________
' Parameters = (Frequency,Combinations)= P = (f,c)
'Where f = The Exact Number Of Times Each Number Appears In a (f,c) Matrix
'Where c = The Number Of Combinations In a (f,c) Matrix
'___________________________________________________

'** In The Frequency TextBox1 Enter 3
'** In The Combinations TextBox2 Enter 4
'** For The Smallest Test Run.....
'** You Can Run It As Many Times As You Wish
'** Each Result Will Be Different
'** And Each Number 1 - 8 Will Appear Exactly 3 Times
'** You Can Use (3,4),(6,8),(9,12) Or (12,16)
'** Just Make Sure You Enter The Smallest Number In The TextBox1
'** Use Any Other Than Those Suggested
'** The Program Will Probably Hang!!!
'** But If You Are Brave...You Can Try All Possible Parameter Sets!!..(There
Are 7)
'** (3,4)..(6,8)..(9,12)..(12,16)..(15,20)..(18,24)..(21,28)
'** Much Past..(9,12) Will Hang the Program and I don't Know Why!!
'_____________________________________________

'*** Loops Until BooLean Condition = True ***



Do While _
v <> Frequency Or _
x <> Frequency Or _
y <> Frequency Or _
z <> Frequency Or _
t <> Frequency Or _
u <> Frequency Or _
w <> Frequency Or _
q <> Frequency

'_____________________________________________

'***************
'Set all variables back to zero after each loop
j = 0
Elements = 0
Field = 0
Combinations = 0
v = 0
x = 0
y = 0
z = 0
t = 0
u = 0
w = 0
q = 0

'***************
'******************************************** Generate Random Combinations of
6 Elements
Cls
For Combinations = 1 To Sets 'Number Of Combinations To Generate
Elements = 6 'Number Of Elements In Each
Combination
Field = 8 'Largest Value(...No Number Can Be
larger Than 8...)
For j = 1 To Field '.............(Or Smaller Than 1.......
............)
'___________________________________________________________________________________________

'This Is The Most Efficient Non-Reapeating
'Random Number Generator I Have Ever Seen
'Wish It Were Mine...Got It Out of An Old
'GW-Basic Book From The 90's...Not Even
'Sure Of How It Works But It Does And Great!!
'_____________________________________________

'Doesn't Work Well With ListBoxes...Can't Get The OutPut In Rows
And Columns!
'Have To Use Print And Semicolon To Print To The Form!



If Rnd < Elements / Field Then

Kcount = Kcount + 1


If j = 1 Then v = v + 1 'Counts The Number Of Times J = 1
If j = 2 Then x = x + 1 '
If j = 3 Then y = y + 1 '
If j = 4 Then z = z + 1 '
If j = 5 Then t = t + 1 '
If j = 6 Then u = u + 1 '
If j = 7 Then w = w + 1 '
If j = 8 Then q = q + 1 'Counts The Number Of Times J = 8

'____________________________________________________________________

'When All Variables = Frequency Then Print
'The 4 Combinations
'Tried To Put This In a Procedure But Couldn't Get It To Work!
!
'Have to Use The Cls Statement to Clear The Screen After Each
Loop!

'____________________________________________________________________

Print Format$(j, "00") & " ";
Elements = Elements - 1
End If
Field = Field - 1
Next
Print
Next

Loop
Print
Print
Print "Number Of Passes = "; Kcount / (Sets * 6) 'Loop Count
Print
Print
Print "Each Number Appears Exactly "; Frequency; " Times" 'Frequency


End Sub

--
Message posted via VBMonster.com
http://www.vbmonster.com/Uwe/Forums.aspx/vb/201007/1

From: Kevin Provance on
Top posted:

I'll have to take a closer look at this after I C&P it into VB, since the
formatting messed it all up. The first thing I noticied is your DIM
statement

: Dim v, x, y, z, t, u, w, q, j, Field, Elements, Frequency, Combinations,
: Kcount, Sets As Long

Everything, except Sets, VB considers a Variant, which for your purposes, is
bad. Variants eat up resources. You'll need to Dim each variable
separately.

Dim v As Long, x As Long, y As Long ,etc.


"NeatBoxx via VBMonster.com" <u61568(a)uwe> wrote in message
news:ab19918f673d7(a)uwe...
: Hi, Fellow Coders of Visual Basic 6
:
: I have been working on a program now for a year and almost complete
except
: for the last module. It is the most all around lottery program I have
ever
: seen as far as tabulating your wins and making Lotto Wheels.
:
: This something I took up in my retirement to while my time away. I
don't
: have any formal training in programming except for a course I had to take
in
: school way back in 1993...Programming in Quickbasic 4.5 The syntax is very
: similar in Visual Basic and that's the only reason why I even took up
Visual
: Basic because it is easy.
:
: If anyone can or will help; I have included my code that I have so
far...It
: works but very inefficiently.
:
: The main problem is that my algorithm is not very efficient and cause'es
: program crashes. I don't have the expertise to do things in programming
that
: others find easy...Just too old...I guess. I would appreicate any help.
: Just copy and paste the code into Visual Basic 6 and read the instuctions
and
: you will see what I am trying to do.
:
: Private Sub Command1_Click()
: Randomize Timer
: Dim v, x, y, z, t, u, w, q, j, Field, Elements, Frequency, Combinations,
: Kcount, Sets As Long
: Frequency = Val(Text1.Text)
: Sets = Val(Text2.Text)
:
:
:
: '.........Instructions........
:
: ' You Will Need 2 Textboxes Very Small Ones!! But Large enough To Enter
: Numbers
: ' 2 Labels "Frequency" And "Combinations
: ' 1 Command Button...Copy And Paste All Code Into The Command Button
:
: '_____________________________________________
: ' Parameters = (Frequency,Combinations)= P = (f,c)
: 'Where f = The Exact Number Of Times Each Number Appears In a (f,c) Matrix
: 'Where c = The Number Of Combinations In a (f,c) Matrix
: '___________________________________________________
:
: '** In The Frequency TextBox1 Enter 3
: '** In The Combinations TextBox2 Enter 4
: '** For The Smallest Test Run.....
: '** You Can Run It As Many Times As You Wish
: '** Each Result Will Be Different
: '** And Each Number 1 - 8 Will Appear Exactly 3 Times
: '** You Can Use (3,4),(6,8),(9,12) Or (12,16)
: '** Just Make Sure You Enter The Smallest Number In The TextBox1
: '** Use Any Other Than Those Suggested
: '** The Program Will Probably Hang!!!
: '** But If You Are Brave...You Can Try All Possible Parameter
Sets!!..(There
: Are 7)
: '** (3,4)..(6,8)..(9,12)..(12,16)..(15,20)..(18,24)..(21,28)
: '** Much Past..(9,12) Will Hang the Program and I don't Know Why!!
: '_____________________________________________
:
: '*** Loops Until BooLean Condition = True ***
:
:
:
: Do While _
: v <> Frequency Or _
: x <> Frequency Or _
: y <> Frequency Or _
: z <> Frequency Or _
: t <> Frequency Or _
: u <> Frequency Or _
: w <> Frequency Or _
: q <> Frequency
:
: '_____________________________________________
:
: '***************
: 'Set all variables back to zero after each loop
: j = 0
: Elements = 0
: Field = 0
: Combinations = 0
: v = 0
: x = 0
: y = 0
: z = 0
: t = 0
: u = 0
: w = 0
: q = 0
:
: '***************
: '******************************************** Generate Random Combinations
of
: 6 Elements
: Cls
: For Combinations = 1 To Sets 'Number Of Combinations To Generate
: Elements = 6 'Number Of Elements In Each
: Combination
: Field = 8 'Largest Value(...No Number Can Be
: larger Than 8...)
: For j = 1 To Field '.............(Or Smaller Than
1.......
: ...........)
:
'___________________________________________________________________________________________
:
: 'This Is The Most Efficient Non-Reapeating
: 'Random Number Generator I Have Ever Seen
: 'Wish It Were Mine...Got It Out of An Old
: 'GW-Basic Book From The 90's...Not Even
: 'Sure Of How It Works But It Does And Great!!
: '_____________________________________________
:
: 'Doesn't Work Well With ListBoxes...Can't Get The OutPut In Rows
: And Columns!
: 'Have To Use Print And Semicolon To Print To The Form!
:
:
:
: If Rnd < Elements / Field Then
:
: Kcount = Kcount + 1
:
:
: If j = 1 Then v = v + 1 'Counts The Number Of Times J = 1
: If j = 2 Then x = x + 1 '
: If j = 3 Then y = y + 1 '
: If j = 4 Then z = z + 1 '
: If j = 5 Then t = t + 1 '
: If j = 6 Then u = u + 1 '
: If j = 7 Then w = w + 1 '
: If j = 8 Then q = q + 1 'Counts The Number Of Times J = 8
:
: '____________________________________________________________________
:
: 'When All Variables = Frequency Then Print
: 'The 4 Combinations
: 'Tried To Put This In a Procedure But Couldn't Get It To
Work!
: !
: 'Have to Use The Cls Statement to Clear The Screen After
Each
: Loop!
:
: '____________________________________________________________________
:
: Print Format$(j, "00") & " ";
: Elements = Elements - 1
: End If
: Field = Field - 1
: Next
: Print
: Next
:
: Loop
: Print
: Print
: Print "Number Of Passes = "; Kcount / (Sets * 6) 'Loop Count
: Print
: Print
: Print "Each Number Appears Exactly "; Frequency; " Times" 'Frequency
:
:
: End Sub
:
: --
: Message posted via VBMonster.com
: http://www.vbmonster.com/Uwe/Forums.aspx/vb/201007/1
:

From: Kevin Provance on
"NeatBoxx via VBMonster.com" <u61568(a)uwe> wrote in message
news:ab19918f673d7(a)uwe...
:
: The main problem is that my algorithm is not very efficient and cause'es
: program crashes. I don't have the expertise to do things in programming
that
: others find easy...Just too old...I guess. I would appreicate any help.
: Just copy and paste the code into Visual Basic 6 and read the instuctions
and
: you will see what I am trying to do.

What do you mean by crashes? Does VB actually crash and close? Does an
error message appear? If so, what does it say?

The only crash I have experience thus far is attempting to exit the program
in mid loop, which is easily fixed with a cancel button and a global boolean
value to stop the loop.

Any additional info about the crashes would be helpful

- Kev

From: Michael Cole on
NeatBoxx via VBMonster.com has brought this to us :
> Hi, Fellow Coders of Visual Basic 6

Comments inline

> If anyone can or will help; I have included my code that I have so far...It
> works but very inefficiently.

I'll have a go.

> The main problem is that my algorithm is not very efficient and cause'es
> program crashes.

What the hell is the algorytm supposed to accomplish? I have fixed
what I can, but I still don't know what the outcome should be.

Some minor coding points are below, but I really need an answer to the
above question to go any further.

> Private Sub Command1_Click()
> Randomize Timer

Stick this in the form load event, not in the command click event. it
should only ever be called once.

> Dim v, x, y, z, t, u, w, q, j, Field, Elements, Frequency, Combinations,
> Kcount, Sets As Long

See Kevin's comments about variable declaration. Also, convert all
these (q-z) into an array of long - i.e.,

Dim lngOccurrances(0 To 7) As Long

_________________________________________
> ' Parameters = (Frequency,Combinations)= P = (f,c)
> 'Where f = The Exact Number Of Times Each Number Appears In a (f,c) Matrix
> 'Where c = The Number Of Combinations In a (f,c) Matrix
> '___________________________________________________
>
> '** In The Frequency TextBox1 Enter 3
> '** In The Combinations TextBox2 Enter 4
> '** For The Smallest Test Run.....
> '** You Can Run It As Many Times As You Wish
> '** Each Result Will Be Different
> '** And Each Number 1 - 8 Will Appear Exactly 3 Times

This (above explanation) is what I don't understand...


> Do While _
> v <> Frequency Or _
> x <> Frequency Or _
> y <> Frequency Or _
> z <> Frequency Or _
> t <> Frequency Or _
> u <> Frequency Or _
> w <> Frequency Or _
> q <> Frequency
>

Do While True

For j = 0 To UBound(lngOccurrances)
If lngOccurrances(j) = Frequency Then
Exit Do
End If
Next j


[SNIP]

>
> If j = 1 Then v = v + 1 'Counts The Number Of Times J = 1
> If j = 2 Then x = x + 1 '
> If j = 3 Then y = y + 1 '
> If j = 4 Then z = z + 1 '
> If j = 5 Then t = t + 1 '
> If j = 6 Then u = u + 1 '
> If j = 7 Then w = w + 1 '
> If j = 8 Then q = q + 1 'Counts The Number Of Times J = 8

lngOccurrances(j - 1) = lngOccurrances(j - 1) + 1


From: NeatBoxx via VBMonster.com on
NeatBoxx wrote:
>Hi, Fellow Coders of Visual Basic 6
>
> I have been working on a program now for a year and almost complete except
>for the last module. It is the most all around lottery program I have ever
>seen as far as tabulating your wins and making Lotto Wheels.
>
> This something I took up in my retirement to while my time away. I don't
>have any formal training in programming except for a course I had to take in
>school way back in 1993...Programming in Quickbasic 4.5 The syntax is very
>similar in Visual Basic and that's the only reason why I even took up Visual
>Basic because it is easy.
>
>If anyone can or will help; I have included my code that I have so far...It
>works but very inefficiently.
>
>The main problem is that my algorithm is not very efficient and cause'es
>program crashes. I don't have the expertise to do things in programming that
>others find easy...Just too old...I guess. I would appreicate any help.
>Just copy and paste the code into Visual Basic 6 and read the instuctions and
>you will see what I am trying to do.
>
>Private Sub Command1_Click()
>Randomize Timer
>Dim v, x, y, z, t, u, w, q, j, Field, Elements, Frequency, Combinations,
>Kcount, Sets As Long
>Frequency = Val(Text1.Text)
>Sets = Val(Text2.Text)
>
> '.........Instructions........
>
> ' You Will Need 2 Textboxes Very Small Ones!! But Large enough To Enter
>Numbers
> ' 2 Labels "Frequency" And "Combinations
> ' 1 Command Button...Copy And Paste All Code Into The Command Button
>
>'_____________________________________________
>' Parameters = (Frequency,Combinations)= P = (f,c)
>'Where f = The Exact Number Of Times Each Number Appears In a (f,c) Matrix
>'Where c = The Number Of Combinations In a (f,c) Matrix
>'___________________________________________________
>
>'** In The Frequency TextBox1 Enter 3
>'** In The Combinations TextBox2 Enter 4
>'** For The Smallest Test Run.....
>'** You Can Run It As Many Times As You Wish
>'** Each Result Will Be Different
>'** And Each Number 1 - 8 Will Appear Exactly 3 Times
>'** You Can Use (3,4),(6,8),(9,12) Or (12,16)
>'** Just Make Sure You Enter The Smallest Number In The TextBox1
>'** Use Any Other Than Those Suggested
>'** The Program Will Probably Hang!!!
>'** But If You Are Brave...You Can Try All Possible Parameter Sets!!..(There
>Are 7)
>'** (3,4)..(6,8)..(9,12)..(12,16)..(15,20)..(18,24)..(21,28)
>'** Much Past..(9,12) Will Hang the Program and I don't Know Why!!
>'_____________________________________________
>
>'*** Loops Until BooLean Condition = True ***
>
> Do While _
> v <> Frequency Or _
> x <> Frequency Or _
> y <> Frequency Or _
> z <> Frequency Or _
> t <> Frequency Or _
> u <> Frequency Or _
> w <> Frequency Or _
> q <> Frequency
>
> '_____________________________________________
>
>'***************
>'Set all variables back to zero after each loop
>j = 0
>Elements = 0
>Field = 0
>Combinations = 0
>v = 0
>x = 0
>y = 0
>z = 0
>t = 0
>u = 0
>w = 0
>q = 0
>
>'***************
>'******************************************** Generate Random Combinations of
>6 Elements
>Cls
> For Combinations = 1 To Sets 'Number Of Combinations To Generate
> Elements = 6 'Number Of Elements In Each
>Combination
> Field = 8 'Largest Value(...No Number Can Be
>larger Than 8...)
> For j = 1 To Field '.............(Or Smaller Than 1.......
>............)
>'___________________________________________________________________________________________
>
> 'This Is The Most Efficient Non-Reapeating
> 'Random Number Generator I Have Ever Seen
> 'Wish It Were Mine...Got It Out of An Old
> 'GW-Basic Book From The 90's...Not Even
> 'Sure Of How It Works But It Does And Great!!
> '_____________________________________________
>
> 'Doesn't Work Well With ListBoxes...Can't Get The OutPut In Rows
>And Columns!
> 'Have To Use Print And Semicolon To Print To The Form!
>
> If Rnd < Elements / Field Then
>
> Kcount = Kcount + 1
>
>
> If j = 1 Then v = v + 1 'Counts The Number Of Times J = 1
> If j = 2 Then x = x + 1 '
> If j = 3 Then y = y + 1 '
> If j = 4 Then z = z + 1 '
> If j = 5 Then t = t + 1 '
> If j = 6 Then u = u + 1 '
> If j = 7 Then w = w + 1 '
> If j = 8 Then q = q + 1 'Counts The Number Of Times J = 8
>
>'____________________________________________________________________
>
> 'When All Variables = Frequency Then Print
> 'The 4 Combinations
> 'Tried To Put This In a Procedure But Couldn't Get It To Work!
>!
> 'Have to Use The Cls Statement to Clear The Screen After Each
>Loop!
>
>'____________________________________________________________________
>
> Print Format$(j, "00") & " ";
> Elements = Elements - 1
> End If
> Field = Field - 1
> Next
> Print
> Next
>
> Loop
> Print
> Print
> Print "Number Of Passes = "; Kcount / (Sets * 6) 'Loop Count
> Print
> Print
> Print "Each Number Appears Exactly "; Frequency; " Times" 'Frequency
>
>
>End Sub

*************************************************************************************8
Thanks for the Dim Statement tip....As I said There is a lot about computer
programming I don't understand, but I have always been able to code what I
wanted to except for this module. It works, but I suspect that it needs an
expertise cleansing because of my lack of undersanding of things like arrays..
.I know that I should have used them, but I cannot grasp their meaning in
terms of what I want to do in this module...I have spent a lot of hours
trying to understand how to apply them, but my age has caught up with me and
I just can't comprehend them. I am 65.

--
Message posted via VBMonster.com
http://www.vbmonster.com/Uwe/Forums.aspx/vb/201007/1