Link to home
Start Free TrialLog in
Avatar of mbarreto022800
mbarreto022800

asked on

Calling a Sub or a Function with their names on a string.

How can I call a Sub or a Function, witch name is on a string ?

In C I could use a pointer to a function. How can I do this in VB ?

Thank you.
Avatar of groone
groone

can you elaborate a bit what you are wanting to do?
Well in VB5, you need to do a Case statement... for example:


Select Case GotoVariable
   Case "Function1": Function1
   Case "Function2": Function2
   Case "Function3": Function3
End Select



Cheers!®©
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The CallByName function is a VB6-only function, but there is a way to implement this in VB5 too, let me know and I can put up the solution on my webpage or something.
Wait... VbMaster.. you have a Webpage?.. As I am a fan.. Wow, would I ever like to check that place out!!! Anyhow.. on to the question.. <smile>.

Yes.. VB6 has a Callbyname option.. but please be advised that in using it, you can pay a very high price in performance.. as there is considerable processing overhead in late binding a procedure. Once and done, type Calls are certainly ok, but a Callbyname employed in a tight loop.. only makes me shudder with long awaited <yawn> anticipation.

In lieu of what Vbmaster may have in mind.. the best and safest bet is still brute force and ignorance.. and SELECT CASE your logical troubles away.. as mcrider has so cogently proposed.. <smile>.
Avatar of mbarreto022800

ASKER

Well, I've already thought on using a "SELECT CASE" but... let me elaborate a bit what I'm wanting to do, like groone asked. I'm writting an software application that will need to write on other applications databases at some point. I was thinking on making a table on my database, describing the applications I'll need to connect. On that table, I thought in creating a field with the name of the function or sub that would write on the tables of that application (since I don't know at start, the configuration of those tables). Then, every time I would need to connect with a new application I would only need to configure the aplication on that table and make a new module with the function or sub, without worrying about all the places on the code where i have those "SELECT CASE"s.
The CallByName Function worked just fine, thank you Erick37 .

Ps. I only work with VB6, Vbmaster, thank you anyway.