|
-
Oct 29th, 2002, 12:42 PM
#1
Thread Starter
Addicted Member
Skipping Code
Hey guys and gals.
Is there a way to jump from one place in some code to another?
Example:
VB Code:
If Variable = True then
Jump to last line
Else
Do this that and the other thing
End If
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! 
-
Oct 29th, 2002, 03:01 PM
#2
Sleep mode
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
-
Oct 29th, 2002, 06:04 PM
#3
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.
-
Oct 29th, 2002, 08:12 PM
#4
Thread Starter
Addicted Member
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! 
-
Oct 30th, 2002, 11:07 AM
#5
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.
-
Oct 30th, 2002, 12:15 PM
#6
PowerPoster
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.
-
Oct 30th, 2002, 01:34 PM
#7
Thread Starter
Addicted Member
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! 
-
Oct 30th, 2002, 01:45 PM
#8
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|