Results 1 to 3 of 3

Thread: Help ! Code runs 10 times automatically !

  1. #1

    Thread Starter
    Lively Member fundean's Avatar
    Join Date
    Apr 2001
    Posts
    98

    Talking Help ! Code runs 10 times automatically !

    I get "You Have Reached 10 tries" immediately after clicking the command button. How can I change the code so that I can click on the button at least 10 times?


    Private Sub Command1_Click()
    Counter = 0
    Do While Counter < 10
    Label1.Caption = Rnd
    Label2.Caption = Rnd

    If Label1.Caption = Label2.Caption Then
    MsgBox "Numbers Identical !"
    End If

    Counter = Counter + 1

    Loop

    MsgBox "You Have Reached 10 tries"



    End Sub

  2. #2
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    Try this:
    Code:
    Private Sub Command1_Click() 
    Static Counter As Integer
    
        If Counter = 10 Then
            MsgBox "You Have Reached 10 tries."
            Exit Sub
        End If
    
        Label1.Caption = Rnd 
        Label2.Caption = Rnd 
    
        If Label1.Caption = Label2.Caption Then MsgBox "Numbers Identical !" 
        Counter = Counter + 1 
    End Sub
    -Excalibur

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    take out the do loop
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

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