Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Call a function stored as string

Posted on 2003-10-27
9
Medium Priority
?
147 Views
Last Modified: 2010-05-03
I want to call functions stored as string.
For example I want to automate reporting and send a data table during the night.
Before sending my report I need to refresh data table with the function UpdateMyTab.
This function is not related with an object. I just want to launch this function.
0
Comment
Question by:meciab
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 24

Expert Comment

by:R_Rajesh
ID: 9626016
dont what you mean exactly...  but if you paste a public fuction to a module, you should be able to launch it from anywhere by using the call statement of just typing its name
0
 

Author Comment

by:meciab
ID: 9626048
I've got a database with a list of reports.
For each of Those report I have to launch a function who update some data.
So for each I have a string with the name of the function I want to launch. But I d'on't know the way to do it.
Thanks
0
 
LVL 5

Expert Comment

by:phyderous
ID: 9626054
VB has support for calling method in objects by using CallByName function

Cheers
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:meciab
ID: 9626069
yes but I don't want to call method in object.
I just want a function like LaunchIt(Function as string).
0
 
LVL 5

Expert Comment

by:phyderous
ID: 9626079
for example

create standart project with form1 and form2 put a button on form1

then paste this code into form1

'form1
Private Sub Command1_Click()
CallByName Form2, InputBox("which function x or y"), VbMethod
End Sub


paste this code into form2

Public Sub x()
MsgBox "test1"
End Sub

Public Sub y()
MsgBox "test2"
End Sub

as you can see command1_click call function on form2 by string return form the input box

sorry for the solution is so simple ...


0
 
LVL 5

Accepted Solution

by:
phyderous earned 1500 total points
ID: 9626085
There is no diffrence in the preformance it is doing the same ...

just create class with all the function you need
0
 
LVL 7

Expert Comment

by:_agj_
ID: 9626114
u cud use the callbyname or:

select case ReportName

case Report1: Call  Make_Report1
case Report2: Call   Make_Report2
case Report3: Call   Make_Report3

end select
0
 

Author Comment

by:meciab
ID: 9626132
TRhe thing is that I automate a lot of things and I d'ont want to do that programaticaly and the answer of phyderous is good.
I'll put the function in a class and call with CallByName
Thanks for your help
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 9626149
I don't think there is an easy way to do this. You can't just call a function whoose name is in a string, becouse every function needs to be compiled before it is executed, and if you alteady have those functions defined somewhere, then you would have to write a code which could read the string, and then call the apropriate function.
For an example:

If you have several functions:    Func1(),Func2(),Func3()  etc.    then your program should do the following:

Select Case str_Function
Case "Func1()"                                        '   same as                 If str_Function = "Func1()" then Call Func1
        Call Func1

Case "Func2()"
        Call Func2

Case "Func3()"
        Call Func3
        .
        .
        .
End Select

If thoose functions needs some parameters (arguments), then it gets more complicated. Your code should be able to read the function name from a string. When it determines the name, it should determine all of the arguments from that string, and store each of them in a variable.

When all of the data is read, then it should call the apropriate function with all of the parameters.



0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Suggested Courses

609 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