Results 1 to 3 of 3

Thread: Strings as Object Methods

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2006
    Posts
    4

    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!

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Strings as Object Methods

    Use the CallByName function

    sAction = "Show"
    CallByName merlin, sAction, VbMethod

  3. #3
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    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:
    1. Dim iStr as String
    2. iStr = [i]<name of action>[/i] 'Show in your case
    3. Object.iStr
    because sAction is not a valid event of MS Agent control.
    just use:
    VB Code:
    1. Merlin.Show
    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.
    Show Appreciation. Rate Posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width