I was just wondering if there was a way to return back to where i left off after going to a label. ex-
if Blah=True then Goto LABEL_BLAH
LABEL_BLAH:
do some stuff
Return to line right after the if/then statement
Printable View
I was just wondering if there was a way to return back to where i left off after going to a label. ex-
if Blah=True then Goto LABEL_BLAH
LABEL_BLAH:
do some stuff
Return to line right after the if/then statement
Use a function, or Subroutine. There is now ay to go back to where you started from using GoTo.
Z.
And you should NEVER use gotos anyway.
Z.
thnx for the help.
I was just wondering since the goto is already in a function and i thought it seemed kinda odd to make a seperate function or sub just for my 3 or 4 lines of code, but OK.
Can you not just use an On Blah Goto Whatever Resume Next like you do with errors?Quote:
Originally posted by Killerguppy101
I was just wondering if there was a way to return back to where i left off after going to a label. ex-
if Blah=True then Goto LABEL_BLAH
LABEL_BLAH:
do some stuff
Return to line right after the if/then statement
Code:on error goto exiterror resume next
do whatever
exiterror:
do whatever
Dont have errors in your program =).
Z.
Zaei, theres difference between exception handling and errors in the program as in bugs.
Killerguppy101, this is probably what you are looking for, Gosubs are lighter than function calls, but they are messy, so be cautious.
Code:Dim a
GoSub 20
MsgBox a
Exit Sub
20:
a = 10
Return
I know, but its no excuse =).
Z.
You could tryAlthough, with the exception of On Error GoTo, I would agree with Zaei, and never use GoTos.VB Code:
If Blah=True Then Goto LABEL_BLAH LABEL_BLAH: 'do some stuff Resume Next End If
Actually I wasn't talking about errors. I just wondered whether exception handling could be used for anything else besides errors.
In C++ or Java you can use exception handling for almost anything that has to do with selectional execution (many people do, and many people also argue against it) but many times exception handling has nothing to do with errors at all.
Goto is not nessesary evil, its just lowlevel, and vb programmers shouldn't be accustomed to such, they should be planting pictureboxes and handling events :rolleyes:
Yeah that's one of the things that I don't agree about VB.NET, they basically removed all the low-level stuff that we used to optimize our programs :(
You can do some odd things with SEH:
Guess what x is. Its 3, because the _finally block is executed before x is returned.Code:int func(int x) {
_try { // I think its one underscore, though it may be two...
return x;
}
_finally { // again, I think its one, but it may be two...
x+=1;
}
}
...
x = func(2)
Z.
two underscores ;)
well, you have to see this one, because at first sight it looks like spaghetti code :D
helloCode:#include "stdio.h"
void main()
{
int* p = 0x00000000; // pointer to NULL
puts("hello");
__try{
puts("in try");
__try{
puts("in try");
*p = 13; // causes an access violation exception;
}__finally{
puts("in finally");
}
}__except(puts("in filter"), 1){
puts("in except");
}
puts("world");
}
in try
in try
in filter
in finally
in except
world