Results 1 to 2 of 2

Thread: Replacing names with variables??? Help, please!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    1

    Post

    I'm looking for a way to call a procedure(sub or function) using a variable. I want to be able to:

    Dim strFunctionName as String

    strFunctionName = "Exit" (where Exit is the name of the sub)
    Call strFunctionName


    or something to this effect

    Does anyone know if this is possible?
    FoxPro has macro substitution that allows this sort of thing using the ampersand(&), but I don't know about VB.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    If you have VB6 yo can do
    Code:
    Dim strFunctionName As String
    
    strFunctionName = "SomeOtherSub"
    CallByName Me, strFunctionName, VbMethod
    
    strFunctionName = "ExitPgm"
    CallByName Me, strFunctionName, VbMethod
    If you don't have VB6 the best you can do is to create a Case statement with a case for each procedure you want to call.
    Code:
    Select Case strFunctionName
        Case "SomeOtherSub"
            SomeOtherSub
        Case "ExitPgm"
            ExitPgm
        Case Else
            MsgBox "Unrecognized procedure name"
    End Select
    ------------------
    Marty
    What did the fish say when it hit the concrete wall?
    > > > > > "Dam!"

    [This message has been edited by MartinLiss (edited 02-15-2000).]

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