
Simple Question - Variable's as Sub names
Dear Stephen,
It is possible to declare a number of classes that could
contain the same method (with different implementation).
Then add them to some collection with meaning keys.
Then you could call these (different by content and the
same by interface) methods by the keys (in your case
it would be subroutine names).
For example;
===========================
<Class1>
Public Sub run_me(some_argument)
MsgBox "It is Class1 - " & some_argument
End Sub
<Class2>
Public Sub run_me(some_argument)
MsgBox "It is Class2 - " & some_argument
End Sub
<Form1>
Dim my_subs As Collection
Private Sub Form_Load()
Dim tmp_object As Object
Set my_subs=New Collection
Set tmp_object = New Class1
my_subs.Add tmp_object, "first_sub"
Set tmp_object = New Class2
my_subs.Add tmp_object,"second_sub"
End Sub
Private Sub Command1_Click()
my_subs("first_sub").run_me "my argument"
my_subs("second_sub").run_me 123.5
End Sub
=================================
It is only a rough idea. If you wanted to have quick access
to the collected methods it is possible to optimize this
sample. (Give the same interface to the classes and build
specialized collection to avoid late bounding.)
Ernest.
Quote:
> This is probably an easy one. Is there a way to call a Subroutine using a
> variable? For example, if I have a variable RunSub = "MySubroutine", how
can
> I call "MySubroutine" using the variable name RunSub? Obviously, Call
RunSub
> doesn't work because it looks for the Subroutine called RunSub, not
> MySubroutine. Thanks in advance for any assistance.