Sub Routine Names As Variables

T

terryspencer2003

I have a procedure which passes the names of other sub routines (Sub1,
Sub2 Sub3)to a variable ("PriceOPtion"). I set up the variable within
a Select Case statment before my main code. Thus the Case will decide
which name gets passed to the PriceOPtion variable. When the main code
runs, the sub which was passed to the variable gets called. Example:

Select Case
Case Is = 1
PriceOPtion = Sub1
Case Is = 2
PriceOPtion = Sub1
Case Is = 3
PriceOPtion = Sub1
End Select

Loop Logic of Main Code
Call PriceOPtion
Loop Logic of Main Code

However, I have a 4th case where I do not want any of the Subs called.
I can put an if in the main code that bypasses the Call statment. Is
there a way that I can pass a dummy variable to PriceOPtion such that
I can avoid the if stmt in the main code? That is I want to call
PriceOPtion in Case 4, but I want the code to not call a thing and
simply progress through the call as if nothing happened.

Select Case
Case Is = 1
PriceOPtion = Sub1
Case Is = 2
PriceOPtion = Sub1
Case Is = 3
PriceOPtion = Sub1
Case Is = 4
PriceOption = DummaryVariable
End Select

Loop Logic of Main Code
Call PriceOPtion
Loop Logic of Main Code


Thanks TS
 
T

Tom Ogilvy

if priceoption is not the name of a subroutine, then call priceoption will
fail.

assume the variable you do your case statement on is inum

Select Case inum

rather than do that you could do

if inum >0 and inum < 3 then
application.Run "Sub" & inum
End if
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top