i know its like really REALLY simple, but i dont know how to, and i cant find a tutorial, so if someone could plz gimme a crash course (very small, just so i can use it) because i kinda need it now, thanx
Printable View
i know its like really REALLY simple, but i dont know how to, and i cant find a tutorial, so if someone could plz gimme a crash course (very small, just so i can use it) because i kinda need it now, thanx
You only need to declare a label. do this by
Private Sub Command1_Click()
GoTo err
Exit Sub
err:
[labelname]:
[commands].....
End Sub
Its simple isn't it. :)
btw, i suggest you use this sparingly. I only user goto for
my error handlers. you may not want to have spaghetti codes.
just a thought. :D
what do you mean by a LABELNAME, why do i need a label, cant i just go
goto err:
end sub
err:
if blahdebvlahdeblah
GoTo will jump to the specified lablel and continue from there.
GoSub will do the same, but it requires some kind of termination, such as Return or Exit Sub.
GoTo is useful if you want to skip a block of code based on some criteria.
GoSub is useful if you have a block of code that is repeated within a routine. You can move that code to a GoSub followed by Return and then just call it each time you would have re-executed the code.
GoTo statements really shouldn't be necessary, in most cases If..Thens and Error Handlers can replace them.