Results 1 to 16 of 16

Thread: Call a function dynamicly

  1. #1

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478

    Call a function dynamicly

    I want to call a function according the value of a combobox

    Let's say my combo is filled with
    "code39"
    "code41"
    "code52"
    "code53"

    Now i want to execute the function related to the chosen comboitem

    Function names are

    make_file_code39
    make_file_code41
    make_file_code52
    make_file_code53

    tried it with "make_file_" & cmbCode.Value

    no luck till now.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Look into the CallFunctionByName (or CallMEthodByName, or CallByName -- something like that) statement, it should be of help.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    The callbymname needs a object where this function resides.

    My functions aren't in a class or member of any other object.

    Therefore this will not work (tried it already)
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  4. #4
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    You're saying your functions aren't anywhere?

  5. #5

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    I don't say what you think i am saying


    The callbyname function can be used to call functions from objects , objects are classes , a form is also a class.

    a simple module isn't a class and therefore can't be used here.

    I will have several modules with the code in it to generate files according the type selected in the combo.

    I think i will need to use a select case statement to work around this issue;

    The whole meaning of calling it dynamicly was , when i add a module to the .mdb (access) i didn't need to add an extra case statement to the code, guess it will be the only way to do it.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  6. #6
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    http://www.vbforums.com/showthread.p...ght=callbyname

    Take a look at the last post.....

  7. #7
    Junior Member
    Join Date
    Aug 2002
    Posts
    21
    tried it with "make_file_" & cmbCode.Value
    shouldn't it be:
    tried it with "make_file_" & cmbCode.Text

    My brain hurts from too many loops and arrays so I could be wrong.

  8. #8

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Originally posted by Michael_Kamen
    http://www.vbforums.com/showthread.p...ght=callbyname

    Take a look at the last post.....
    Been trying this whole day,
    one error i cant get around
    Error number 2465
    description "Application-defined or object-defined error"

    Which object must be specified in it, the functions will be in different code modules ????
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  9. #9

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Got to take some evening course , will check again tommorrow.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  10. #10

  11. #11

  12. #12
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    The methods are in a module, which can't be passed, as the object, to the CallByName function
    Personally I would add them to a class module, as this would solve loads of problems.

    Woka

  13. #13

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Marty , the error occures on the line where the call is made.
    The code has been modified, but in the other reply you stated it could be called from a code module also.

    It doesn't work for me and i think this can't be done that way.

    Woka the class isn't an option. I only need to have functions in different modules to be called refering the item chosen in a combo.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  14. #14

  15. #15
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Originally posted by swatty
    Marty , the error occures on the line where the call is made.
    The code has been modified, but in the other reply you stated it could be called from a code module also.

    It doesn't work for me and i think this can't be done that way.
    Sorry but it looks like you are correct. The called procedures either need to be in the form or a class.

  16. #16

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    So I may assume your previous answer was not totally correct.

    No worries , i'll use a select case then and and a case for each new module created.

    Thanks anyway for the reply.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

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