# More Slot machine issues

## Recommended Posts

Marz    150
Hi I'm using VB6 to create a slot machine. So far it's working well but I have 1 small problem. The slot machine has nine boxes. It pays out if any 3 of these boxes rolls 7. I can't figure out how to check for this. if i use the following it keeps finding the same 7 over 3 times. for i = 0 to 8 if box(i).picture = imaage(7) and box(i).picture = imaage(7)And box(i).picture = imaage(7) Then you win end if next i I am sure this is simple for you long time programers but for a newbie like me it's got me baffeled. I would greatly appreciate some insight. Please use layman's terms. thank you. the two posts I got from this question were very helpful. BUT Just count how many sevens you've got. Your code only tests for a single box being a 7 (if box i is a 7, then all 3 box(i).picture == imaage(7) are true!) count = 0 for i = 0 to 8 if box(i).picture == imaage(7) Then count = count + 1 next i if count >= 3 Then you win end if This allows me to award any 3 sevens but I can't light up the squares around the sevens as I know not where they are. any input would be greatly appreciated.

##### Share on other sites
raptorstrike    181
i would assume that all the pictures you are drawing have coordaninths (y wouldnt they) so all you have to do is

if box(i).picture == imaage(7) Then count = count + 1

then

box(i).picture = Light_Up_7Box.

i think this is what your asking (i dont know VB but hopefully you can inturpret what i mean

patient =)

____________________________
"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"
- Colin Mochrie

##### Share on other sites
Marz    150
yeah but that will light up the seven even if there is one. ..keep it coming please. you helping a lot.

##### Share on other sites
Marz    150
This is what i have now. It plays the music when there are 3 or more sevens but it only lights up the last seven.

For i = 0 To 8If box(i).Picture = Image1(2) Thensevencount = sevencount + 1End IfIf sevencount > 2 ThenLabel1(i).Visible = True  **label is the light up box**Retval = PlaySound("C:\Documents and Settings\Trent Hogan\Desktop\sounds\win", 0, 1)End IfNext i

##### Share on other sites
Zahlman    1682
This is what I was trying to tell you before, corrected because it hadn't occurred to me that you don't want to highlight sevens if the player loses ;)

' *Highlight* and count every box with a seven in it.For i = 0 To 8  If box(i).Picture = Image1(2) Then    sevencount = sevencount + 1    Label1(i).Visible = True  End IfNext i' Ok, now see if the player won.If sevencount < 3 Then  ' Oops, not enough sevens, so unhighlight everything.  For i = 0 To 8    Label1(i).Visible = False  Next iElse  ' There were enough sevens, so we play the sound.  ' Doing things this way makes sure we don't call PlaySound more than once  ' if there are more than three sevens.  Retval = PlaySound("C:\Documents and Settings\Trent Hogan\Desktop\sounds\win", 0, 1)End If

Of course, this is a bit silly; since we have to check again anyway, we may as well do highlighting in the second pass:

' Just count every box with a seven in it.For i = 0 To 8  If box(i).Picture = Image1(2) Then    sevencount = sevencount + 1  End IfNext i' Ok, now see if the player won.If sevencount >= 3 Then  ' There are enough sevens, so we play the sound,  Retval = PlaySound("C:\Documents and Settings\Trent Hogan\Desktop\sounds\win", 0, 1)  ' and we must also go back and highlight all the sevens.  For i = 0 To 8    If box(i).Picture = Image1(2) Then      Label1(i).Visible = True    End If  Next iEnd If

The reason your code won't work is that by the time you determine that there are enough sevens, you have already passed by the first two sevens, so it is too late to highlight them. There isn't really any way around this: you need to do the processing in two separate passes.