March 18th, 2003, 12:33 PM
Call sub from variable
I would like to call a sub (or function if necessary) from a variable. Currently I am having difficulties doing this. I get an error. The error is Compile error: Expected Sub, Function, or Property. The code I am using is below:
SubToCall = "Call" & "Me"
' Process data here
Any suggestions on how to make this work would be greatly apprecieated.
March 18th, 2003, 02:27 PM
I dont know if what you want to do is possible. What exactly are you trying to do? there is an addressof() function that allows you to get the address of a function. or maybe you can use a case structure for example
Private Sub Command_Click()
Select Case VaribleName
Messagebox "No such Function Name"
sorry best i can do
March 18th, 2003, 03:03 PM
I need to process and evaluate incoming comm port data 1 of 16 different ways. The process varies widely so I will not have any common code. The process will not change during the program execution and is determined at startup by a series of radio buttons. My intent was to run the proper procedure based on radio button input. I would assign a variable to the radio button which would execute the correct procedure on incoming comm port data. I did not want to evaluate a select case for each data input since the process would remain constant throughtout the program execution. I appreciate your input. Thanks for taking the time to respond.
March 18th, 2003, 03:50 PM
The CallByName Function will do what you want. You could even append the index of the option button to the name of the function too.
March 19th, 2003, 04:57 AM
March 19th, 2003, 01:36 PM
Thanks for the input. I will give this a try.
March 20th, 2003, 12:16 AM
Public Function calval(ByVal x As Integer) As Integer
calval = x * x
Private Sub Form_Load()
MsgBox CallByName(Form1, "calval", VbMethod, 10)
Last edited by Cimperiali; May 20th, 2004 at 02:19 AM.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!