How to call a function dynamically

I have a vb selector

Dim ver =101
Select Case ver
        Case 101
            upd101()
        Case 102
            upd102()
        Case 103
            upd103()
    End Select

How can I make this choice better by calling the function more dynamically in this form: with the prefix "upd" followed by the integer ver.?

Thank you! Adrian

+3
source share
3 answers

Its possible, but not cleaner or faster.

Dim t As Type = base.GetType()

t.GetMethod("upd" + theInt)
+3
source

Can't you just call upd (param)?

I mean, instead of creating many functions, create one and use variables .;]

+5
source
Dim ver as Integer 
dim procToCall as String

ver = 101
procToCall = "upd" & ver

CallByName myclassInstace, procToCall, vbMethod

EDIT: myClassInstance - , .
.. , Person, ToString.

dim somePerson as new Person
CallByName somePerson, "ToString", vbMethod

However, do not use this programming style.
How many such methods exist to call a method in this form?

+4
source

Source: https://habr.com/ru/post/1764041/


All Articles