Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

silly question for goto statements

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
this might seem as a silly question, but i dont want to write too many lines of code, is there any way of say declaring a variable and then using a goto statement with that variable, however the label it refers to doesnt have the same name, such as this:

myvariable = "International"
GoTo myvariable
.
.
International:
.
.
Obviously if I leave it like that, i'll get a big error, but i just dont want to write a bunch of If-statments. Thanks

 
Use GOTO only as a last resort. Take a look at the CASE statement. It is probably what you need in this situation.
 
GoTo is usually just used for error trapping.

As Zathras says,
Code:
Select Case
should be used as a switching statement, which avoids the need for nested
Code:
If ... Then
blocks.

 
yea i'll have to do that to clear up this code, thanks!
 
Ok i know i should use case statments, but with the goto statement, could i be able to have a label that is not in the same sub and "goto" that label, currently i get an error because the label, or destination must be in the same sub as the goto statement, i probably wont end up using these goto statements, but i'm still curious and would like to learn as much VBA as possible (if you haven't been able to tell already lol)
 
It's not VBA that is the problem, it's understanding how subs and functions work in any programming language.

Even if you could find a programming language that permitted a GOTO to some label outside of the current subroutine, I would not use it.

I can't even imagine a situation where it would be necessary. There is a theoretical construct which Larry Constantine wrote about back in the 70's that he called co-routines which comes close, but I've never found a practical application.

I strongly suggest you re-examine the structure of the application you are attempting to build.

I am curious, though. Why do you think you want to GOTO a label outside of the current routine? If you plan to come back, just CALL the other sub. If not, just EXIT the current sub.

 
Yea well I've always heard about not using goto, its just that in my programming, being such a novice programmer, i don't expand or broaden my practical knowledge of programming, and I rely on basic elementary methods to accomplish whatever tasks I need, but thanks for all your help, the code you've provided in my threads has been extrememly invaluable to me (and saved my job :D). Thanks Zathras
 
using calls might look more wordy and tedious but think of the tedium (no it is exciting tearing your hair out) debugging spaghetti.

Trust me, those who self taught on GW &/or QB2.5 (etc) know where you're at and it is in the middle of a very busy highway. Jump out now!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top