PDA

Click to See Complete Forum and Search --> : Need help with GoTo labels!


Killerguppy101
Mar 25th, 2002, 12:17 PM
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

Zaei
Mar 25th, 2002, 12:35 PM
Use a function, or Subroutine. There is now ay to go back to where you started from using GoTo.

Z.

Zaei
Mar 25th, 2002, 12:35 PM
And you should NEVER use gotos anyway.

Z.

Killerguppy101
Mar 25th, 2002, 12:39 PM
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.

Ephesians
Mar 25th, 2002, 01:14 PM
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

Can you not just use an On Blah Goto Whatever Resume Next like you do with errors?


on error goto exiterror resume next
do whatever

exiterror:
do whatever

Zaei
Mar 25th, 2002, 01:25 PM
Dont have errors in your program =).

Z.

kedaman
Mar 25th, 2002, 02:24 PM
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.

Dim a

GoSub 20
MsgBox a

Exit Sub
20:
a = 10
Return

Zaei
Mar 25th, 2002, 02:27 PM
I know, but its no excuse =).

Z.

Hack
Mar 25th, 2002, 02:28 PM
You could tryIf Blah=True Then Goto LABEL_BLAH
LABEL_BLAH:
'do some stuff
Resume Next
End IfAlthough, with the exception of On Error GoTo, I would agree with Zaei, and never use GoTos.

Ephesians
Mar 25th, 2002, 02:29 PM
Actually I wasn't talking about errors. I just wondered whether exception handling could be used for anything else besides errors.

kedaman
Mar 25th, 2002, 03:07 PM
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:

Jotaf98
Mar 25th, 2002, 05:52 PM
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 :(

Zaei
Mar 25th, 2002, 11:51 PM
You can do some odd things with SEH:

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)

Guess what x is. Its 3, because the _finally block is executed before x is returned.

Z.

kedaman
Mar 26th, 2002, 02:37 AM
two underscores ;)
well, you have to see this one, because at first sight it looks like spaghetti code :D

#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");
}

hello
in try
in try
in filter
in finally
in except
world