-
Why doesn't this loop work?{|/([Resolved])\|}
This is my loop can anyone tell me why it doesn't work??
VB Code:
Do Until intDie12 = intDie34
intDie3 = Rand(1, 6)
intDie4 = Rand(1, 6)
Dice3(intDie3 - 1).Visible = True
Dice4(intDie4 - 1).Visible = True
intDie12 = intDie1 + intDie2
intDie34 = intDie3 + intDie4
If intDie12 = intDie34 Then
lblWinner.Visible = True
lblAmount.Caption = "Player's Total Money: $" & intAmount
End If
Loop
-
Re: Why doesn't this loop work?
Well maybe it's because the first time you come to the first statement in the loop intDie12 and intDie34 hasn't got any values so they are both 0. Meaning you will never enter the loop since intDie12 = intDie34. You could change the loop to:
VB Code:
Do
'... the code
Loop Until intDie12 = intDie34
-
Re: Why doesn't this loop work?
VB Code:
intDie12 = [b]intDie1 + intDie2[/b]
Where are these variables set?
chem
-
Re: Why doesn't this loop work?
Ok my code for this dumb craps game won't work. Please take a look at it and see what i'm doing wrong.
VB Code:
intDie1 = Rand(1, 6)
intDie2 = Rand(1, 6)
intDie3 = Rand(1, 6)
intDie4 = Rand(1, 6)
lblWinner.Visible = False
lblLose.Visible = False
Dice1(0).Visible = False
Dice1(1).Visible = False
Dice1(2).Visible = False
Dice1(3).Visible = False
Dice1(4).Visible = False
Dice1(5).Visible = False
Dice2(0).Visible = False
Dice2(1).Visible = False
Dice2(2).Visible = False
Dice2(3).Visible = False
Dice2(4).Visible = False
Dice2(5).Visible = False
Dice1(intDie1 - 1).Visible = True
Dice2(intDie2 - 1).Visible = True
If intDie1 + intDie2 = 7 Or intDie1 + intDie2 = 11 Then
lblWinner.Visible = True
intAmount = intAmount + intBet
lblAmount.Caption = "Player's Total Money: $" & intAmount
Exit Sub
ElseIf intDie1 + intDie2 = 2 Or intDie1 + intDie2 = 12 Then
lblLose.Visible = True
intAmount = intAmount - intBet
lblAmount.Caption = "Player's Total Money: $" & intAmount
Exit Sub
Else
MsgBox "Roll to match: " & intDie1 + intDie2
lblRoll.Visible = True
intDie3 = Rand(1, 6)
intDie4 = Rand(1, 6)
Do
Dice3(intDie3 - 1).Visible = True
Dice4(intDie4 - 1).Visible = True
intDie12 = intDie1 + intDie2
intDie34 = intDie3 + intDie4
If intDie12 = intDie34 Then
lblWinner.Visible = True
lblAmount.Caption = "Player's Total Money: $" & intAmount
End If
Loop Until intDie12 = intDie34
End If
-
Re: Why doesn't this loop work?
Is Rand() a function you have written yourself?
-
Re: Why doesn't this loop work?
VB Code:
Public Function Rand(ByVal Low As Long, _
ByVal High As Long) As Long
Rand = Int((High - Low + 1) * Rnd) + Low
End Function
-
Re: Why doesn't this loop work?
Well consider the code you have inside the loop. You never change the values of intDie1 - 4. So maybe intDie12 never will equal intDie34 meaning you end up with an endless loop.
-
Re: Why doesn't this loop work?
What I mean is that in your first post these two lines where inside the loop but they aren't anymore.
VB Code:
intDie3 = Rand(1, 6)
intDie4 = Rand(1, 6)
-
Re: Why doesn't this loop work?
The loop never runs at all. I ran a break and it skipped over the loop when I got there. the Die3(intDie3 - 1).Visible = True part makes the picture of a die show up, and no dice even show up. There is obviously something wrong and I'm not sure what it is...
-
Re: Why doesn't this loop work?
What are does Dice1() and Dice2()? Image controls? Do you even have a Dice3() and Dice4()?
-
Re: Why doesn't this loop work?
I have six images of the six sides of a die. Each are name Dice1(0) for the 1 side, Dice2(1) for the two side etc. etc. This Dice3(intDie3 - 1).Visible = True makes whatever number this intDie3 = Rand(1, 6) generates to make that die show up.
-
Re: Why doesn't this loop work?
Yes I understood that much, but do you have 4 groups of these image control arrays? If so try this code:
VB Code:
intDie1 = Rand(1, 6)
intDie2 = Rand(1, 6)
intDie3 = Rand(1, 6)
intDie4 = Rand(1, 6)
lblWinner.Visible = False
lblLose.Visible = False
Dice1(0).Visible = False
Dice1(1).Visible = False
Dice1(2).Visible = False
Dice1(3).Visible = False
Dice1(4).Visible = False
Dice1(5).Visible = False
Dice2(0).Visible = False
Dice2(1).Visible = False
Dice2(2).Visible = False
Dice2(3).Visible = False
Dice2(4).Visible = False
Dice2(5).Visible = False
Dice1(intDie1 - 1).Visible = True
Dice2(intDie2 - 1).Visible = True
If intDie1 + intDie2 = 7 Or intDie1 + intDie2 = 11 Then
lblWinner.Visible = True
intAmount = intAmount + intBet
lblAmount.Caption = "Player's Total Money: $" & intAmount
Exit Sub
ElseIf intDie1 + intDie2 = 2 Or intDie1 + intDie2 = 12 Then
lblLose.Visible = True
intAmount = intAmount - intBet
lblAmount.Caption = "Player's Total Money: $" & intAmount
Exit Sub
Else
MsgBox "Roll to match: " & intDie1 + intDie2
lblRoll.Visible = True
Do
intDie3 = Rand(1, 6)
intDie4 = Rand(1, 6)
Dice3(intDie3 - 1).Visible = True
Dice4(intDie4 - 1).Visible = True
DoEvents
intDie12 = intDie1 + intDie2
intDie34 = intDie3 + intDie4
If intDie12 = intDie34 Then
lblWinner.Visible = True
lblAmount.Caption = "Player's Total Money: $" & intAmount
End If
Loop Until intDie12 = intDie34
End If
-
Re: Why doesn't this loop work?
It doesn't work. The "doevents" does not show up blue.
-
Re: Why doesn't this loop work?
Could you zip up your project and post it here?
-
Re: Why doesn't this loop work?
I can when I get home I'm at school right now and their computers are very limited. There's no winzip. I'll post it around 6 tonight. I'll prolly make a new thread. Thanks cya.
-
Re: Why doesn't this loop work?
Quote:
Originally Posted by shizzy
I'll post it around 6 tonight.
That's fine... have you ever considered that it's already 6 tonight in some parts of the world ;)
-
1 Attachment(s)
Re: Why doesn't this loop work?
Oh that is true. Sorry this post is for Joacim. It was 10 in the morning when I last posted. Now it's 6 for me :). Here's my project.
-
Re: Why doesn't this loop work?
If anyone wants to look at my project in my post above and see whats wrong I'd give points to you or whatever they are:) and i'm a generous guy!
-
Re: Why doesn't this loop work?
May I ask what it actually means when you have, let's say rolled a 9 and the MsgBox comes up just before the loop that says "Roll to match 9" means? Are you supposed to hit the roll button until the two new dices also show 9? That is not happening now, the only thing that happens is that the loop keeps going until you've reached 9 on the two other dices. Of course this is not shown since you never put the last two dices on top of the others.
VB Code:
Do
intDie3 = Rand(1, 6)
intDie4 = Rand(1, 6)
DoEvents
Dice3(intDie3 - 1).Visible = True
Dice4(intDie4 - 1).Visible = True
Dice3(intDie3 - 1).ZOrder 'Put this dice upon any earlier shown dice
Dice4(intDie4 - 1).ZOrder 'Put this dice upon any earlier shown dice
intDie12 = intDie1 + intDie2
intDie34 = intDie3 + intDie4
If intDie12 = intDie34 Then
'lblWinner.Visible = True
lblAmount.Caption = "Player's Total Money: $" & intAmount
End If
Loop Until intDie12 = intDie34
As you can see I added a call using ZOrder that will bring the new dice to the top of the others. But this loop will go so fast that you will hardly see anything but the fact that the two new dices also show 9 together.
May I also suggest that you make a call to Randomize in Form_Load.
VB Code:
Private Sub Form_Load()
Randomize
End Sub
So you don't get the same random numbers every time you play.
-
Re: Why doesn't this loop work?
can you explain the game one more time, i can help you then
[edit] beat me to it ^^
-
Re: Why doesn't this loop work?
Mr. Joacim, my teacher's version of the dice move very quickly on the second pair of dice, so that is good :). The point of the roll to match, is that when you don't get a 2, 7, 11, or 12, whatever you roll (say a 3 and 6) that will be 9. So on the second pair of dice you have to match 9 (in any combination) or get a 7 or 11 which in the second roll, will make you lose.
-
Re: Why doesn't this loop work?
Wow, that works perfectly. I don't get why you had to have the Zorder tho?
-
Re: Why doesn't this loop work?
so wait, your 2nd roll, has to match the first roll on the first try, if it doesnt you lose?
-
Re: Why doesn't this loop work?
No, on the first roll if you don't roll a 2 (snake eyes :afrog: ) 7, 11, or 12, then you get a 'subsequent roll' which is the second pair of dice. You roll as many times with the second pair of dice until you match your first roll's total or get a 7 or 11.
-
Re: Why doesn't this loop work?
Quote:
Originally Posted by shizzy
Wow, that works perfectly. I don't get why you had to have the Zorder tho?
Say your first two dice show a 6 and a 3. That means you must match 9 on the other two, right? So let's say in the first round of the loop they come up as 3 and 2. Those two images are now visible. Let's say next time they come up as 1 and 4 which of them are then the two topmost images? 3 and 2 or 1 and 4? Or maybe 3 and 4 or 1 and 2? The images is on top of each other when you start the game some are on top of others. If you are showing two images that are of the exact same size and at the exact same position you will of course only see one of them. The one on the top. Setting the ZOrder (without any argument) will bring the object to top.
-
Re: Why doesn't this loop work?
Should I use ZOrder for the first Dice1 and Dice2?
-
Re: Why doesn't this loop work?{|/([Resolved])\|}
That's is not necassary since you set their Visible property to False at the start of the Sub. So only two images will be visible at any time, the two that shows the randomly selected numbers. But inside the Loop you set the Visible property for Dice3 and Dice4 but never set it back to False.
-
Re: Why doesn't this loop work?{|/([Resolved])\|}
Oh, I'm going to use ZOrder because its alot better looking than all those .false statements :) PLEASE LOOK AT MY NEW THREAD