Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Sub Routine Names As Variables

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Sub Routine Names As Variables

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

--
Regards,
Tom Ogilvy


wrote in message
om...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sub Routine Names As Variables

Good idea Tom! - Piku

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
find maximum and minum variables for multiple names [email protected] Excel Worksheet Functions 1 November 29th 07 10:21 PM
Inserting variables within file names kestrel Excel Worksheet Functions 3 June 16th 06 08:00 PM
Routine?? Zax Excel Programming 3 December 19th 03 05:50 PM
Need VBA Routine John M. Lembo Excel Programming 0 July 13th 03 01:51 AM
variables for file names mike Excel Programming 1 July 9th 03 11:39 PM


All times are GMT +1. The time now is 01:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"