Results 1 to 10 of 10

Thread: Functions

  1. #1
    Swatty
    Guest

    Functions

    Hi all, is it possible to call a function or sub when the name of the function is stored in a var.

    When i try this i'll get the error
    Compile error
    Expected Sub, Function, or Property.

    Is there a way to call it with the name stored in a string variable ??

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Of course you'll get an error!! Try using a redirecting function instead.

    Call redirector(variablename)


    ...
    ...


    private function (redir as string)
    select case redir
    case "swatty"
    call soandso()

    case "mrpolite"
    call linux()

    end select
    end function

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Oops, I forgot to complete the sentence.

    "Of course you'll get an error,you're calling a variable!!"

  4. #4
    Swatty
    Guest
    If I need to do it like that, i'll place an extra if else in my loop for calling the wright function.

    It was for following.

    got two functions with same parameters but different calculations in it.

    So i would before i enter the loop put the function name in a var, and then call it through that var.

    Instead i'll test it every time again.

    Thanks for the quick reply though.

  5. #5
    Banned Michael_Kamen's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,180
    You can use the CallByName function, to call a sub or function stored in a variable. Like this:

    VB Code:
    1. Dim MyFunction As String
    2. Dim MyParameters As Integer
    3. MyFunction = "SquareRoot"
    4. MyParameters = 200
    5. 'usage:
    6. CallByName Me, MyFunction, VbMethod, MyParameters

    This example shows how to call a sub called SquareRoot which needs an integer as parameter.
    Last edited by Michael_Kamen; Jun 24th, 2002 at 05:14 AM.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Thanks from me... I had no idea about this one.

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Talking Blarney stone...my arse...

    I was just about to post that answer
    I use it in collecton class module so allow the client side to display columns in a grid. You just add the Property names to an array, easy to change....

    Wokawooooooo

  8. #8
    Swatty
    Guest
    Thanks but i think this won't work.

    It is a function call in a module .
    the option you gave me requires an object i don't have.
    And my parameters must be given in an array.

    this is my call to the first function.
    bereken_totaal_incl_btw "vleveringslijn", vL.Fields("jaar"), vL.Fields("journaal"), vL.Fields("nummer"), vL.Fields("boekdatum"), vL.Fields("betalingsvw"), vL.Fields("munt"), n, b, t, f, True, "vlevering"


    If i need to fill in the parametrlist first , i think it is faster with an if else statement.



    Anyway I'll keep it in mind for later use.
    Thanks Michael

  9. #9

  10. #10
    Swatty
    Guest
    If I have to fill in an array of 12 elements against a selection , i think it will go faster with the selection.

    Rhanks anyway

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