Results 1 to 28 of 28

Thread: Why doesn't this loop work?{|/([Resolved])\|}

  1. #1

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    Resolved Why doesn't this loop work?{|/([Resolved])\|}

    This is my loop can anyone tell me why it doesn't work??

    VB Code:
    1. Do Until intDie12 = intDie34
    2.            
    3.                 intDie3 = Rand(1, 6)
    4.                 intDie4 = Rand(1, 6)
    5.            
    6.                 Dice3(intDie3 - 1).Visible = True
    7.                 Dice4(intDie4 - 1).Visible = True
    8.                
    9.                 intDie12 = intDie1 + intDie2
    10.                 intDie34 = intDie3 + intDie4
    11.            
    12.                 If intDie12 = intDie34 Then
    13.                
    14.                     lblWinner.Visible = True
    15.                
    16.                     lblAmount.Caption = "Player's Total Money: $" & intAmount
    17.                
    18.                 End If
    19.        
    20.             Loop
    Last edited by shizzy; May 11th, 2005 at 05:39 PM.
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. Do
    2.     '... the code
    3. Loop Until intDie12 = intDie34

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Why doesn't this loop work?

    VB Code:
    1. intDie12 = [b]intDie1 + intDie2[/b]
    Where are these variables set?

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    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:
    1. intDie1 = Rand(1, 6)
    2.     intDie2 = Rand(1, 6)
    3.     intDie3 = Rand(1, 6)
    4.     intDie4 = Rand(1, 6)
    5.  
    6.     lblWinner.Visible = False
    7.     lblLose.Visible = False
    8.  
    9.     Dice1(0).Visible = False
    10.     Dice1(1).Visible = False
    11.     Dice1(2).Visible = False
    12.     Dice1(3).Visible = False
    13.     Dice1(4).Visible = False
    14.     Dice1(5).Visible = False
    15.  
    16.     Dice2(0).Visible = False
    17.     Dice2(1).Visible = False
    18.     Dice2(2).Visible = False
    19.     Dice2(3).Visible = False
    20.     Dice2(4).Visible = False
    21.     Dice2(5).Visible = False
    22.  
    23.         Dice1(intDie1 - 1).Visible = True
    24.         Dice2(intDie2 - 1).Visible = True
    25.  
    26.         If intDie1 + intDie2 = 7 Or intDie1 + intDie2 = 11 Then
    27.  
    28.             lblWinner.Visible = True
    29.             intAmount = intAmount + intBet
    30.    
    31.             lblAmount.Caption = "Player's Total Money: $" & intAmount
    32.            
    33.             Exit Sub
    34.  
    35.         ElseIf intDie1 + intDie2 = 2 Or intDie1 + intDie2 = 12 Then
    36.  
    37.             lblLose.Visible = True
    38.             intAmount = intAmount - intBet
    39.    
    40.             lblAmount.Caption = "Player's Total Money: $" & intAmount
    41.            
    42.             Exit Sub
    43.  
    44.         Else
    45.        
    46.             MsgBox "Roll to match: " & intDie1 + intDie2
    47.             lblRoll.Visible = True
    48.            
    49.                 intDie3 = Rand(1, 6)
    50.                 intDie4 = Rand(1, 6)
    51.        
    52.        
    53.         Do
    54.            
    55.                 Dice3(intDie3 - 1).Visible = True
    56.                 Dice4(intDie4 - 1).Visible = True
    57.                
    58.                 intDie12 = intDie1 + intDie2
    59.                 intDie34 = intDie3 + intDie4
    60.            
    61.                 If intDie12 = intDie34 Then
    62.                
    63.                     lblWinner.Visible = True
    64.                
    65.                     lblAmount.Caption = "Player's Total Money: $" & intAmount
    66.                
    67.                 End If
    68.        
    69.         Loop Until intDie12 = intDie34
    70.        
    71.         End If
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Why doesn't this loop work?

    Is Rand() a function you have written yourself?

  6. #6

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    Re: Why doesn't this loop work?

    VB Code:
    1. Public Function Rand(ByVal Low As Long, _
    2.                      ByVal High As Long) As Long
    3.  
    4.   Rand = Int((High - Low + 1) * Rnd) + Low
    5.  
    6. End Function
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. intDie3 = Rand(1, 6)
    2.  intDie4 = Rand(1, 6)

  9. #9

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    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...
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Why doesn't this loop work?

    What are does Dice1() and Dice2()? Image controls? Do you even have a Dice3() and Dice4()?

  11. #11

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    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.
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  12. #12
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. intDie1 = Rand(1, 6)
    2.     intDie2 = Rand(1, 6)
    3.     intDie3 = Rand(1, 6)
    4.     intDie4 = Rand(1, 6)
    5.  
    6.     lblWinner.Visible = False
    7.     lblLose.Visible = False
    8.  
    9.     Dice1(0).Visible = False
    10.     Dice1(1).Visible = False
    11.     Dice1(2).Visible = False
    12.     Dice1(3).Visible = False
    13.     Dice1(4).Visible = False
    14.     Dice1(5).Visible = False
    15.  
    16.     Dice2(0).Visible = False
    17.     Dice2(1).Visible = False
    18.     Dice2(2).Visible = False
    19.     Dice2(3).Visible = False
    20.     Dice2(4).Visible = False
    21.     Dice2(5).Visible = False
    22.  
    23.         Dice1(intDie1 - 1).Visible = True
    24.         Dice2(intDie2 - 1).Visible = True
    25.  
    26.         If intDie1 + intDie2 = 7 Or intDie1 + intDie2 = 11 Then
    27.  
    28.             lblWinner.Visible = True
    29.             intAmount = intAmount + intBet
    30.    
    31.             lblAmount.Caption = "Player's Total Money: $" & intAmount
    32.            
    33.             Exit Sub
    34.  
    35.         ElseIf intDie1 + intDie2 = 2 Or intDie1 + intDie2 = 12 Then
    36.  
    37.             lblLose.Visible = True
    38.             intAmount = intAmount - intBet
    39.    
    40.             lblAmount.Caption = "Player's Total Money: $" & intAmount
    41.            
    42.             Exit Sub
    43.  
    44.         Else
    45.        
    46.             MsgBox "Roll to match: " & intDie1 + intDie2
    47.             lblRoll.Visible = True
    48.             Do
    49.                 intDie3 = Rand(1, 6)
    50.                 intDie4 = Rand(1, 6)
    51.            
    52.                 Dice3(intDie3 - 1).Visible = True
    53.                 Dice4(intDie4 - 1).Visible = True
    54.                 DoEvents
    55.                 intDie12 = intDie1 + intDie2
    56.                 intDie34 = intDie3 + intDie4
    57.            
    58.                 If intDie12 = intDie34 Then
    59.                     lblWinner.Visible = True
    60.                     lblAmount.Caption = "Player's Total Money: $" & intAmount
    61.                 End If
    62.        
    63.             Loop Until intDie12 = intDie34
    64.         End If
    Last edited by Joacim Andersson; May 11th, 2005 at 09:02 AM.

  13. #13

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    Re: Why doesn't this loop work?

    It doesn't work. The "doevents" does not show up blue.
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  14. #14
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Why doesn't this loop work?

    Could you zip up your project and post it here?

  15. #15

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    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.
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  16. #16
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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

  17. #17

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    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.
    Attached Files Attached Files
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  18. #18

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    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!
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  19. #19
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. Do
    2.            
    3.             intDie3 = Rand(1, 6)
    4.             intDie4 = Rand(1, 6)
    5.             DoEvents
    6.                
    7.                 Dice3(intDie3 - 1).Visible = True
    8.                 Dice4(intDie4 - 1).Visible = True
    9.                 Dice3(intDie3 - 1).ZOrder 'Put this dice upon any earlier shown dice
    10.                 Dice4(intDie4 - 1).ZOrder 'Put this dice upon any earlier shown dice
    11.                 intDie12 = intDie1 + intDie2
    12.                 intDie34 = intDie3 + intDie4
    13.            
    14.                 If intDie12 = intDie34 Then
    15.                     'lblWinner.Visible = True
    16.                     lblAmount.Caption = "Player's Total Money: $" & intAmount
    17.                 End If
    18.         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:
    1. Private Sub Form_Load()
    2.     Randomize
    3. End Sub
    So you don't get the same random numbers every time you play.

  20. #20
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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 ^^

  21. #21

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    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.
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  22. #22

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    Re: Why doesn't this loop work?

    Wow, that works perfectly. I don't get why you had to have the Zorder tho?
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  23. #23
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    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?

  24. #24

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    Re: Why doesn't this loop work?

    No, on the first roll if you don't roll a 2 (snake eyes ) 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.
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  25. #25
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  26. #26

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    Re: Why doesn't this loop work?

    Should I use ZOrder for the first Dice1 and Dice2?
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

  27. #27
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  28. #28

    Thread Starter
    Hyperactive Member shizzy's Avatar
    Join Date
    May 2005
    Location
    Michigan
    Posts
    278

    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
    In rare occasion, if I help you, give me some rate points. They help me sleep at night
    WMRR Rockin' the Lakeshore! For all your guitar music needs! For all your guitar purchasing needs!
    AC/DC Rocks! Van Halen! Led Zeppelin!

    my webpage

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width