|
-
Jun 13th, 2000, 06:04 PM
#1
Thread Starter
Lively Member
How do i call...? api experts?
Anyone know how to do the following? I want to tell a function that when I call it it should call another function of my choice. In the code below I've tried to illustrate what I mean.
I run Test.
It tells CallThat to run Test2.
Test2 shows the first messagebox.
Then it tells CallThat to run Test3.
Test3 shows the second messagebox.
Code:
Sub Test()
CallThat Test2
CallThat Test3
End Sub
Sub CallThat(CallWhat As Variant)
Call CallWhat
End Sub
Sub Test2()
MsgBox "I was called"
End Sub
Sub Test3()
MsgBox "And I was called after that"
End Sub
Using this in an event-class where i want to be able to specify what function should be called.
-
Jun 13th, 2000, 06:19 PM
#2
PowerPoster
It should be look like this...
Code:
Sub Test()
CallThat "Test2"
CallThat "Test3"
End Sub
Sub CallThat(CallWhat As String)
Select Case CallWhat
Case "Test2"
Test2
Case "Test3"
Test3
End Select
End Sub
Sub Test2()
MsgBox "I was called"
End Sub
Sub Test3()
MsgBox "And I was called after that"
End Sub
-
Jun 13th, 2000, 06:22 PM
#3
Thread Starter
Lively Member
The Test2 and Test3 were just examples. It can be any function. The class has no prerecognition of what functions it may call.
-
Jun 13th, 2000, 06:25 PM
#4
PowerPoster
I don't think you can call a Function through variable. Since you write the class, then you should be able to write a extra function to compare the variable and then just call the respective function like what I've posted.
-
Jun 13th, 2000, 06:28 PM
#5
Hi Thomas!
I'm sorry but I think it's not possible.
You can determine the adress of a function with AdressOf() but as far as I know in vb there is no possibility to call a function by adress.
What do you need this for?
Maybe we could find another solution ...
Regards
da_bob
________________
-
Jun 13th, 2000, 07:41 PM
#6
Thread Starter
Lively Member
Well. I'm making a class that are creating controls at runtime on a target empty form or frame1. That part works well.
If I now create ie. 4 textboxes and if I want to monitor the event_change on these 4 textboxes with the same procedure, the best way would be to.
1. Create 1st textbox WithEvents.
2. Tell the class that the Change_Event should run "myfunction" which can be any function.
3. Do 1 and 2 with the 3 other textboxes.
I now have 4 instances of the control-class which all point to "myfunction" somewhere in my code.
I do not wish for the code to be static, because static programming is a waste. The reason I made code to create controls at runtime was to make it all dynamic. To fully complete the project i need to to stay that way, or else I would just write the whole project statically from the start.
There has to be some smart way to be able to call a function by address. Using API perhaps?
I say nothing is impossible when coding. There is always a way around. There is always some clever guy who found out how to do it.
(VBA(97) does not have control arrays like in VB)
-
Jun 13th, 2000, 08:40 PM
#7
Take a look at the CallByName function (introduced in VB6). I ran this test and it worked:
Code:
Private Sub Form_Load()
CallThat "Test2"
CallThat "Test3"
End Sub
Sub CallThat(CallWhat As Variant)
CallByName Me, CallWhat, VbMethod
End Sub
Sub Test2()
MsgBox "I was called"
End Sub
Sub Test3()
MsgBox "And I was called after that"
End Sub
"It's cold gin time again ..."
Check out my website here.
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
|