calling procedures dynamically

how can i call procedures faster when i have lets say 2 procedures with same name but with a number on the end
the code i have in the command button is wrong syntax, is there anyway i can change that around or do something different?


Private Sub Level1()
'code
end sub

Private Sub Level2()
'code
end sub()

Private sub command1_click()
call "level" & intLevel 'int level being a number between 1 and 2
end sub

Comments

  • Private Sub Level(Byval Index as Integer)
    'Code
    End Sub

    Private sub command1_click()
    call level(intLevel) 'int level being a number between 1 and 2
    end sub

    Zvoni

    : how can i call procedures faster when i have lets say 2 procedures with same name but with a number on the end
    : the code i have in the command button is wrong syntax, is there anyway i can change that around or do something different?
    :
    :
    : Private Sub Level1()
    : 'code
    : end sub
    :
    : Private Sub Level2()
    : 'code
    : end sub()
    :
    : Private sub command1_click()
    : call "level" & intLevel 'int level being a number between 1 and 2
    : end sub
    :

    ------------------------------------------
    Only stupidity of mankind and the universe
    are infinite, but i'm not sure concerning
    the universe. A. Einstein

  • Try this way:>>
    The CALL keyword is optional.

    [code]
    Dim level As Integer

    Select Case level

    Case 1
    Level1()

    Case 2
    Level2()

    Case 3
    Level3()

    Case 4
    Level4()

    Case 5
    Level5()

    Case 6
    Level6()

    Case 7
    Level7()

    Case 8
    Level8

    Case 9
    Level9()

    Case 10
    Level10()

    End Select
    [/code]

    Regards,

    Dr M.




    Here is another example which uses the [b]Select Case[/b] statement to evaluate the value of a variable. The second Case clause contains the value of the variable being evaluated, and therefore only the statement associated with it is executed.
    [code]
    Number = 8 ' Initialize variable.
    Select Case Number ' Evaluate Number.
    Case 1 To 5 ' Number between 1 and 5.
    Debug.Print "Between 1 and 5"
    ' The following is the only Case clause that evaluates to True.
    Case 6, 7, 8 ' Number between 6 and 8.
    Debug.Print "Between 6 and 8"
    Case Is > 8 And Number < 11 ' Number is 9 or 10.
    Debug.Print "Greater than 8"
    Case Else ' Other values.
    Debug.Print "Not between 1 and 10"
    End Select
    [/code]

  • There is a function in the VBA libraries called "CallByName". You can pass in a String that will call the function you need to call.


    : Try this way:>>
    : The CALL keyword is optional.
    :
    : [code]
    : Dim level As Integer
    :
    : Select Case level
    :
    : Case 1
    : Level1()
    :
    : Case 2
    : Level2()
    :
    : Case 3
    : Level3()
    :
    : Case 4
    : Level4()
    :
    : Case 5
    : Level5()
    :
    : Case 6
    : Level6()
    :
    : Case 7
    : Level7()
    :
    : Case 8
    : Level8
    :
    : Case 9
    : Level9()
    :
    : Case 10
    : Level10()
    :
    : End Select
    : [/code]
    :
    : Regards,
    :
    : Dr M.
    :
    :
    :
    :
    : Here is another example which uses the [b]Select Case[/b] statement to evaluate the value of a variable. The second Case clause contains the value of the variable being evaluated, and therefore only the statement associated with it is executed.
    : [code]
    : Number = 8 ' Initialize variable.
    : Select Case Number ' Evaluate Number.
    : Case 1 To 5 ' Number between 1 and 5.
    : Debug.Print "Between 1 and 5"
    : ' The following is the only Case clause that evaluates to True.
    : Case 6, 7, 8 ' Number between 6 and 8.
    : Debug.Print "Between 6 and 8"
    : Case Is > 8 And Number < 11 ' Number is 9 or 10.
    : Debug.Print "Greater than 8"
    : Case Else ' Other values.
    : Debug.Print "Not between 1 and 10"
    : End Select
    : [/code]
    :
    :

  • : There is a function in the VBA libraries called "CallByName". You can pass in a String that will call the function you need to call.

    CallByName calls object methods, not regular functions.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • True, but if your function is in a module, class, or even form, technically, they are objects and you would just have to reference the name of the form, module, class for which the function is in and you have then supplied the object variable.

    : : There is a function in the VBA libraries called "CallByName". You can pass in a String that will call the function you need to call.
    :
    : CallByName calls object methods, not regular functions.
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :

  • here is an example of a basic form using the call by name function within itself


    Private Sub Command1_Click()

    MsgBox CallByName(Form1, "ToldYouSo", VbMethod)
    End Sub



    Public Function ToldYouSo() As String
    ToldYouSo = "Hi"
    End Function




    : True, but if your function is in a module, class, or even form, technically, they are objects and you would just have to reference the name of the form, module, class for which the function is in and you have then supplied the object variable.
    :
    : : : There is a function in the VBA libraries called "CallByName". You can pass in a String that will call the function you need to call.
    : :
    : : CallByName calls object methods, not regular functions.
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : : [code]
    : : $ select * from users where clue > 0
    : : no rows returned
    : : [/code]
    : :
    : :
    :
    :

  • : : True, but if your function is in a module, class, or even form, technically, they are objects and you would just have to reference the name of the form, module, class for which the function is in and you have then supplied the object variable.

    It doesn't work for modules, and it doesn't technically work on classes either, but rather *instances* of classes. It works on the forms because if you reference a form name in VB, then VB automatically loads it.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories