|
-
Feb 18th, 2006, 12:33 PM
#1
Thread Starter
New Member
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!
-
Feb 18th, 2006, 12:56 PM
#2
Re: Strings as Object Methods
Use the CallByName function
sAction = "Show"
CallByName merlin, sAction, VbMethod
-
Feb 18th, 2006, 01:01 PM
#3
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: right bruce, i forgot the CallByName funcntion!! sorry
Last edited by Harsh Gupta; Feb 18th, 2006 at 01:11 PM.
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
|