In Visual Basic, is there a way to convert a string, entered on the command line, to a statement label? The intent is to execute only select portions of code. I’m working with a large program that includes many individual steps. For testing purposes I want to execute just one step without having to run through all of the previous steps.
I know how to extract the desired substring from the command line argument list.
So, given that string TestStep = "Step_3:"
somehow convert TestStep to point to label "Step_3:
GoTo TestStep
...
Step_1: 'do something
GoTo Elsewhere
Step_2: 'do something else
GoTo Elsewhere
Step_3: ' do the thing we want
GoTo Elsewhere
Step_4: ' do other stuff
GoTo Elsewhere
...
I’ve looked in "Visual Basic.NET" by Jesse Liberty and "VB.NET Language Pocket Reference" by Roman, Petrusha & Lomax without success.
Of course, just trying
GoTo TestStep where TestStep is a string results in Visual Studio responding: Label "TestStep" not defined
2
Answers
I had a similar problem with a large and complicated
Select..Case
block that I didn’t like due to potential complexity. I solved it by usingAction
variable type and aDictionary
of function pointers as below.When the test is run, it will produce this output:
The lightest touch that I can think of would be something based on
Select Case
which would probably also require labels andGoTo
s to jump between cases. My idea is that if you started with something like this (not actually executable VB code, more like a VB-Fortran hybrid pseudocode):Then maybe it could convert to something like this: