|
-
Jun 10th, 2003, 02:28 PM
#1
Thread Starter
Junior Member
Calling a function based on the contents of a string
Hi all, is it possible to call a function based on the name of a string?
What I want to do is treat the contents of "TextVariable" as a function name and then call it...
i.e. something similar to this:
VB Code:
Sub Command1_Click()
Msgbox "Button pressed"
End Sub
Sub Command2_Click()
Dim TextVariable as String
TextVariable = GetFunctionNameFromDatabase()
'i.e. TextVariable = "Command1_Click()"
Call ContentsOf(TextVariable)
End Sub
cheers
- Mike.
-
Jun 10th, 2003, 02:30 PM
#2
PowerPoster
probably the closest you will get to doing this will be to put your function code in a Class Property or Method and use the CallByName function to invoke it (I think that would work anyway) ...
-
Jun 11th, 2003, 12:32 PM
#3
Thread Starter
Junior Member
-
Jun 11th, 2003, 12:39 PM
#4
Another thing you could do would be to make a function that took the string as an argument, and used a Select statement to choose which function to call:
Select funcName
Case "Blue"
Blue()
Case "Red"
Red()
.
.
.
etc.
-
Jun 11th, 2003, 12:48 PM
#5
Thread Starter
Junior Member
yeah that'd work,
I'm missing the obvious answers and going straight into the more complex ones as usual, ta :-)
-
Jun 11th, 2003, 12:55 PM
#6
That's when it's time to take a walk.
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
|