Results 1 to 4 of 4

Thread: how to use "goto"?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2006
    Posts
    120

    how to use "goto"?

    how to write code using "goto"?
    i get a compile error:expected:line number or label

  2. #2
    Hyperactive Member Capp's Avatar
    Join Date
    May 2005
    Location
    Texas
    Posts
    409

    Re: how to use "goto"?

    vb Code:
    1. On Error GoTo ErrHandler
    2.  
    3. 'your code here
    4.  
    5. Exit Sub 'This keeps it from running the error handler every time
    6.  
    7. ErrHandler:  'The name you gave it after the "GoTo" part
    8.  
    9. msgbox Err.Number & vbcrlf & Err.Description
    AmazingAntivirus.com
    Remote Data Backups


    Please Mark your Thread "Resolved", if the query is solved...

    If a post has helped you then Please Rate it!

  3. #3
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: how to use "goto"?

    the answer is don't - unless you're using it for an error handler, in which case:
    Code:
    Private Sub Command1_Click()
        On Error Goto ErrHandler
    
        ' Code
    
        Exit Sub
    ErrHandler:
        MsgBox "Err!"
    End Sub

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: how to use "goto"?

    Quote Originally Posted by bushmobile
    the answer is don't - unless you're using it for an error handler
    Amen in spades.

    However, because you asked the question I'm assuming you have some code that isn't working and you feel that a GoTo could be a solution.

    Show us what you have and what you want/need to do with it.

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