Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 571
  • Last Modified:

Return command for a GoTo Command question for VB

For a Goto Command, is there VB code that says Goto a different line run that code and then a RETURN COMMAND that returns the execution to the original code position and pick up where it was left off.  All this being in the same subroutine.

Thanks.
0
tqwu
Asked:
tqwu
1 Solution
 
fulscherCommented:
I'm afraid there's no such command. You would have to work with two Goto statements:


...
   Dosomething
   Domore
   Goto LabelB
LabelA:
   Domore
   Domore
   Exit Sub

LabelB:
   Doanotherthing
   Goto LabelA

Anyway, using GOTO statements is considered poor programming practice. In your case, wouldn't a SUB be better?

...
   Dosomething
   Domore
   Call SubB
   Domore
   Domore
   Exit Sub

Sub SubB
   ...
End Sub

Of course, you can't easily share variables between the calling code and SubB. Two possible solutions:
- Put the common variables in the header of the module (again, poor programming practice)
- pass the variables by reference to SubB.

Hope this helps
Jan
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now