Solved

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

Posted on 2000-03-06
7
156 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:mbarreto022800
7 Comments
 
LVL 3

Expert Comment

by:groone
ID: 2588827
can you elaborate a bit what you are wanting to do?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2588840
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!®©
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 45 total points
ID: 2588849
"HOWTO: Use the CallByName Function to Run a Procedure"

http://support.microsoft.com/support/kb/articles/Q186/1/43.ASP
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:Vbmaster
ID: 2589368
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.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2590139
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>.
0
 

Author Comment

by:mbarreto022800
ID: 2595246
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.
0
 

Author Comment

by:mbarreto022800
ID: 2595330
The CallByName Function worked just fine, thank you Erick37 .

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now