Results 1 to 8 of 8

Thread: Skipping Code

  1. #1

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171

    Skipping Code

    Hey guys and gals.
    Is there a way to jump from one place in some code to another?
    Example:

    VB Code:
    1. If Variable = True then
    2.     Jump to last line
    3. Else
    4.    Do this that and the other thing
    5. End If
    6.  
    7. This line is the jump-to point...


    Thankyou for your time.
    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    hi
    It's just like "Go to Line" in VB6.

    example
    Code:
    Sub GotoStatementDemo()
    Dim Number As Integer
    dim MyString As String
       Number = 1   ' Initialize variable.
       ' Evaluate Number and branch to appropriate label.
       If Number = 1 Then GoTo Line1 Else GoTo Line2
       
    Line1:
       MyString = "Number equals 1"
       GoTo LastLine   ' Go to LastLine.
    Line2:
       ' The following statement never gets executed because Number = 1.
       MyString = "Number equals 2"
    LastLine:
       ' Print "Number equals 1" in the Output window.
       Debug.WriteLine (MyString)  
    End Sub

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    Since GOTO has gone hence, there isn't a simple statement to do so.

    However, since GOTO was almost never needed (except in error handling), there is always a way to re-write your code such that the GOTO statement is not needed. The re-write may not appear to be as simple, but thinking about a problem in a new way has never made anybody less-informed.

  4. #4

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Originally posted by pirate
    hi
    It's just like "Go to Line" in VB6.

    example
    Code:
    Sub GotoStatementDemo()
    Dim Number As Integer
    dim MyString As String
       Number = 1   ' Initialize variable.
       ' Evaluate Number and branch to appropriate label.
       If Number = 1 Then GoTo Line1 Else GoTo Line2
       
    Line1:
       MyString = "Number equals 1"
       GoTo LastLine   ' Go to LastLine.
    Line2:
       ' The following statement never gets executed because Number = 1.
       MyString = "Number equals 2"
    LastLine:
       ' Print "Number equals 1" in the Output window.
       Debug.WriteLine (MyString)  
    End Sub
    Worked great. Thanks!

    Originally posted by Shaggy Hiker
    Since GOTO has gone hence, there isn't a simple statement to do so.

    However, since GOTO was almost never needed (except in error handling), there is always a way to re-write your code such that the GOTO statement is not needed. The re-write may not appear to be as simple, but thinking about a problem in a new way has never made anybody less-informed.
    Still works for me! I will, however, take into consideration your suggestion of rewriting the code.


    Thankyou both!
    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    I haven't tried it, but I was under the impression that the GOTO statement had been removed from .NET. Do you say that it hasn't? Has Microsoft mislead me? Who would think it of them!!

    I suppose it must remain since GOTO is still used in On Error statements which remain for legacy support in .NET. However, I would be reluctant to rely on GOTO, since legacy support tends to deteriorate over time.

  6. #6
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    With if statements, the many kind of loops, and the case statement, you can program without having to use the GOTO statement at all. It should even be easier to read.

  7. #7

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Originally posted by hellswraith
    With if statements, the many kind of loops, and the case statement, you can program without having to use the GOTO statement at all. It should even be easier to read.
    Very true. I'm definately rewriting to for legibility's sake.

    As for MICROSOFT, I'd give them a ring and tell them that they have misleading information in one of their articles. That should piss off ol' Billy-boy pretty good!
    Thanks for all your help, dudes.


    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  8. #8

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Oh wait! There isn't a Keys.Asterisk! What do I do?
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

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