Results 1 to 9 of 9

Thread: Executing a sub via parm pass

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    Executing a sub via parm pass

    Hi,

    Back in my AS400 days, you could call a program whose name
    was strored in a variable "Call &PGMNAMESTOREDHERE" I wish to
    do similar in my VB program. I want to execute a subroutine
    whose name would be stored in a table. Is this possible?
    Thanks
    Tom

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    Do you mean a subroutine that exists in your VB program or elsewhere (such as in a DLL) ?

    If in VB prog, you can do it via "if then ... "(I know that's pretty obvious but though I'd mention it just in case) but I don't think there's any other way.

    If in a DLL, there might be an API call you can use (but, again, I'm not aware of any)

  3. #3
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352
    Actually his second idea works I am pretty sure. If you place them in a DLL, you can dynamically call functions. I did it for a math program I designed a while back, but I don't have the code on me. It involved using LoadLibrary to load the DLL and then I believe CallWndProc. Hope that helps.

    Joe

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    Sub call

    Phinds,

    A call to a sub in the same VB program. Might sound odd, but
    here is the reason: Base on the type of "container" that is
    selected, the "containerization" of the product is different. That means a different form/subroutine for each container type. Container types are going to be added over time, so I will have to
    hardcode the container type, requiring form changes,and
    CASE,IF/ELSE selections modified. I would rather put the
    container types to a table and call the appropriate subroutine whose name is stored in the record for the container type. This will reduce modifications in the future to just writing the sub and populating the container table. Just a pipe dream I guess
    Tom

  5. #5
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    This is what the vbapi says about CallWindowProc. I think it's basically for subclassing, and not for calling a procedure/function by name.

    http://216.26.168.92/vbapi/ref/c/callwindowproc.html

    To the best of my knowledge VB doesn't provide for a macro-style function calling by name.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    Sharpsville, PA
    Posts
    135

    PArm pass

    Joe,

    I can't go DLL route because of my lack of knowledge on how those are built/excuted. I should learn it, But I do not have the luxury of time to figure it out, but it does seem interesting. Maybe down the road. Thanks guys/gals anyway for responding
    Tom

  7. #7
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352
    My apologizes, GetProcAddress is what I meant. Then there was a manner to use that proc address to call the function dynamically. I know for a fact there is a manner to do it as I actually did it. I just do not have code here with me at work. Edit: Or did I cheat? I may have cheated. I am not sure to be honest. I may have cheated and passed the variable name to a predefined function that handled passing it to the next. Though, for some reason I am inclined to think that I called the function directly.

    Joe
    Last edited by Joey_k29; Aug 8th, 2002 at 08:41 AM.

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    VB Code:
    1. CallByName
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  9. #9
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    plenderj --- OUTSTANDING !!!

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