dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Weird Goto Error

  1. #1
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125

    Weird Goto Error

    Hello,

    I have this piece of code :
    Code:
    Private Sub Form_Load()
    
    goOn:
    
    Some code!
    
    Timer1.Enabled = True
    
    Exit Sub
    
    End Sub
    
    Private Sub Timer1_Timer()
    GoTo goOn:
    Timer1.Enabled = False
    
    End Sub
    When I run this it gives an eror that the Goto goOn: label is not defined ? Is there something wrong with this code ???

    Thanks
    Bert Willekens,

  2. #2
    Join Date
    Aug 2003
    Location
    London
    Posts
    515
    Goto labels are only valid within the scope of the procedure for which they are defined, you cannot Goto a label in another procedure.

    Valid code would be...

    Code:
    Private Sub Form_Load()
    
        Timer1.Enabled = True
        Exit Sub
    
    End Sub
    
    Private Sub Timer1_Timer()
    
    '// Some sort of test...
        IF (X <> Y) Then
            Goto GoOn:
        End If
    
        Exit Sub
    
    goOn:
        Timer1.Enabled = False
    
    End Sub

  3. #3
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210
    hi Bert Willekens.
    seems you want to run the code in Form_load
    just call Form_load as you call any sub

    Code:
    Private Sub Timer1_Timer()
    Form_load
    Timer1.Enabled = False
    End Sub

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)