473,372 Members | 805 Online

# Need help I'm working on a slot machine game and need some help

I am working on a slot machine project in vb6. I am trying to figure out how to change this:

If (a = 1 And b = 1 And c <> 1) Or (a = 1 And c = 1 And b <> 1) Or (b = 1 And c = 1 And a <> 1) Or _
(a = 2 And b = 2 And c <> 2) Or (a = 2 And c = 2 And b <> 2) Or (b = 2 And c = 2 And a <> 2) Or _
(a = 4 And b = 4 And c <> 4) Or (a = 4 And c = 4 And b <> 4) Or (b = 4 And c = 4 And a <> 4) Or _
(a <> 1 And b = 1 And c = 1) Or (b <> 1 And c = 1 And a = 1) Or (c <> 1 And b = 1 And a = 1) Or _
(a <> 2 And b = 2 And c = 2) Or (b <> 2 And c = 2 And a = 2) Or (c <> 2 And b = 2 And a = 2) Or _
(a <> 4 And b = 4 And c = 4) Or (b <> 4 And c = 4 And a = 4) Or (c <> 4 And b = 4 And a = 4) Then

into a select case statement if possible. I am very new to programming but have come a good way. I am using the Rnd function to come up with 3 random numbers which associates itself to 3 different pictures out of 30 pictures. The problem is that when I program all the losing numbers to deduct money or whatever that there's to many combinations of the above code to put in an If Then statement. Would anybody have a suggestion or show me the way I would put it in a select case statement? I got the slot machine game to work good but it misses a majority because I don't know how to catch them all properly.
Apr 2 '22 #1
1 16616
MerlinTheGreat
6 Nibble
Actually you wrote the same thing twice.
The first three lines are essentially the same as the other three lines, only in the opposite order of comparison.
Removing the 4th to the 6th line makes things easier since half of the code is dropped.

You could try to add the values of a, b and c together in a variable d and build a select case with the resulting value.
I'm not using the dim statement in this example. Doing so will however make your code clearer and less prone to errors.

Expand|Select|Wrap|Line Numbers
1. d = a + b + c
2.
3. Select Case d
4.   Case = 2 : two of the variables a, b and c have a value of 1
5.      : Do whatever is needed to be done in this case.
6.
7.   Case = 4 : two of the variables a, b and c have a value of 2
8.      : Do whatever is needed to be done in this case.
9.
10.   Case = 8 : two of the variables a, b and c have a value of 4
11.      : Do whatever is needed to be done in this case.
12.
13.   : If other combined values are to be checked,
14.   : you can put them here in the same way as the code above
15.
16.   Case Else : Catch all for other combinations
17.      : Do whatever is needed to be done in this case.
18.
19. End Select
You might have to watch out for possible combinations that might give an unwanted match like a=1 b=1 c=2 which gives 4 as a result.
I don't know if this is possible in your programm.

I hope this helps you out.
Jun 13 '22 #2