Strings as Object Methods
Hi everybody,
I'm completely new to VB (I'm on 6.0 for this project), but I'm not new to programming. My problem is as such: I have a string that I want to use to call a method of a specified object. I'm using the Microsoft Agent class, and here's what I'm doing (in a nutshell):
Code:
Private Sub Form_Load()
Agent1.Characters.Load "Merlin", "merlin.acs"
Set Merlin = Agent1.Characters("Merlin")
Dim sAction As String
sAction = "Show"
Merlin.sAction
Merlin.Play ("Greet")
'etc
Merlin.Hide
End Sub
It fails on Merlin.sAction. I know I can do this in C/C++ derrived web languages (such as PHP and Perl), but I'm not sure how o do this in VB. Help is appreciated.
Cheers!
Re: Strings as Object Methods
Use the CallByName function
sAction = "Show"
CallByName merlin, sAction, VbMethod
Re: Strings as Object Methods
i dont know about PHP and other similar languages, but in VB, you cannot expect this to work:
VB Code:
Dim iStr as String
iStr = [i]<name of action>[/i] 'Show in your case
Object.iStr
because sAction is not a valid event of MS Agent control.
just use:it should work.
Harsh Gupta
EDIT: :eek: right bruce, i forgot the CallByName funcntion!! sorry