views:

58

answers:

3

I have in vb a selector

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

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

thank you! Adrian

+3  A: 

Can't you just call upd(param)?

I mean, rather than creating many functions, create one and use variables. ;]

Tomasz Kowalczyk
Come now that would be foolish.
ChaosPandion
I don;t understand what you mean, could you tell a little bit more?
Tomasz Kowalczyk
Sorry, if English is not your first language you might not read the sarcasm.
ChaosPandion
Yes, I am from Poland, but now I understand. ;] In polish, we would say something like "no co ty?" - in English: "dude! really?". ;]
Tomasz Kowalczyk
+2  A: 
Dim ver as Integer 
dim procToCall as String

ver = 101
procToCall = "upd" & ver

CallByName myclassInstace, procToCall, vbMethod

EDIT: Here myClassInstance is the instance of the class you have created.
i.e. lets assume you have a class named Person which has a method named ToString.
The code will look like

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

However, avoid using this style of programming.
How many such methods exist for you to call the method in this form?

shahkalpesh
tnx, so I have the functions upd101() to ... upd150()
Adrian
and I what to replace the selector to some lighter ... like upd{101}() ..? is this posible ???
Adrian
sorry : I mean upd{ver}() ... where ver is the number from 101 to 150 ..
Adrian
it give me an error: Public member 'upd100' on type 'frm' not found.
Adrian
CallByName(Me, procToCall, vbMethod)
Adrian
finally I got it it works!! thanks!!! :)
Adrian
A: 

Its possible but its not cleaner, or faster.

Dim t As Type = base.GetType()

t.GetMethod("upd" + theInt)
Nix
This requires VB.NET so it may not work for them.
ChaosPandion
what is obj ? Dim obj As New Object
Adrian
That help? Is the type of the class that all of your methods are defined in.
Nix