-
March 18th, 2003, 01:33 PM
#1
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:
Sub Command1_Click()
SubToCall = "Call" & "Me"
SubToCall
End Sub
Sub CallMe()
' Process data here
End Sub
Any suggestions on how to make this work would be greatly apprecieated.
Thanks
-
March 18th, 2003, 03:27 PM
#2
vbwannabe
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
Case FunctionNameOne
FunctionNameone()
Case FunctionNameTwo
FunctionNameTwo()
Case Else
Messagebox "No such Function Name"
End Select
End sub
sorry best i can do
Jerry Woodstock
-
March 18th, 2003, 04:03 PM
#3
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, 04:50 PM
#4
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, 05:57 AM
#5
Busy
-
March 19th, 2003, 02:36 PM
#6
Thanks for the input. I will give this a try.
-
March 20th, 2003, 01:16 AM
#7
Use CallByName
eg.
Code:
Public Function calval(ByVal x As Integer) As Integer
calval = x * x
End Function
Private Sub Form_Load()
MsgBox CallByName(Form1, "calval", VbMethod, 10)
End Sub
Last edited by Cimperiali; May 20th, 2004 at 02:19 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|