Posts by filo65

    Re: calling "variable names" procedure


    Thank you Andy,


    in the meantime I found out how it worked. It' a really advanced programming topic approcing VBA to the VC++ features.



    For the one of you who are interested here is an example;


    Sub main()
    Dim strg As String, i As Integer
    i = 10

    Select Case i
    Case 1
    strg = "func" & i
    Case 2
    strg = "func" & i
    Case Else
    strg = "func99"


    End Select
    Evaluate (strg & "(" & i & ")")
    End Sub


    Function func1(a As Integer)
    MsgBox "I'm 1"
    End Function


    Function func2(a As Integer)
    MsgBox "I'm 2"
    End Function


    Function func99(a As Integer)
    MsgBox "I'm Else"
    End Function


    There is no need of hardcoding the function names in a "select case" or "if... Else" statements; you can pass them as arguments to a main function.


    function mainfunc(funcName as string)
    mainfunc=Evaluate(funcName & "()") <==== adapt code for custom code
    end function



    filo65

    Re: calling &quot;variable names&quot; procedure


    thank you A9192Shark,


    but I want to keep max flexibility; with if or select case statement I'm force to hardcode. I want to have the freedom to add more "func"Nbr function without changing continuosly the code. I thought there was something with "Evaluate"...



    filo65

    Hi,


    can someone help me to remember how to call a proceure with "variable name" within a main procedure? I know there is a way but I forgot it


    i.e.:


    sub main(var1 as integer)
    dim res as integer
    call ...."func" & var1 & "(2,3, res)"


    end sub


    sub func1(a as integer,b as integer,c as integer)
    c=a+b
    end sub


    sub func2(a as integer,b as integer,c as integer)
    c=a*b
    end sub


    Depending on var1 main calls the appropriate sub routine.


    Thank you in advance


    Filo65