473,386 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Using a string to call a function

I have a load of function names stored in a table which I want to use
to decide which function to run. I can select the function name but I
cannot work out how to call the function if I have the name of the
function as a string.
Normally in my code I would just call the function name but if I do
this with the string variable which is the function name I get an
error.
Can anyone help.
Alex
Nov 13 '05 #1
5 4681
On 25 Dec 2004 08:32:04 -0800, al********@hotmail.com (Alex) wrote:

Check out the Exec function in the help file.
-Tom.

I have a load of function names stored in a table which I want to use
to decide which function to run. I can select the function name but I
cannot work out how to call the function if I have the name of the
function as a string.
Normally in my code I would just call the function name but if I do
this with the string variable which is the function name I get an
error.
Can anyone help.
Alex


Nov 13 '05 #2
Tom van Stiphout wrote:
On 25 Dec 2004 08:32:04 -0800, al********@hotmail.com (Alex) wrote:

Check out the Exec function in the help file.
-Tom.


Do you mean Eval()?

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
Nov 13 '05 #3
On Sat, 25 Dec 2004 17:52:41 +0100, Bas Cost Budde
<b.*********@heuvelqop.nl> wrote:

Oops - yes, I meant Eval.
Debug.Print Eval("SomeFunction()")
-> SomeValue

-Tom.
Tom van Stiphout wrote:
On 25 Dec 2004 08:32:04 -0800, al********@hotmail.com (Alex) wrote:

Check out the Exec function in the help file.
-Tom.


Do you mean Eval()?


Nov 13 '05 #4
I tried Eval and it does seem to run the function but the function displays
a form used as a progress counter and the form is not displayed.
In essence I have a continous form with about 50 records in it and the user
can select any number of these. For each selection there is a function to
run. My progress form shows which of the functions is currently running and
how far through the function it is. All of this is working except being able
to call the function using the function name stored as a string in a table.
Alex

"Tom van Stiphout" <no*************@cox.net> wrote in message
news:vf********************************@4ax.com...
On Sat, 25 Dec 2004 17:52:41 +0100, Bas Cost Budde
<b.*********@heuvelqop.nl> wrote:

Oops - yes, I meant Eval.
Debug.Print Eval("SomeFunction()")
-> SomeValue

-Tom.
Tom van Stiphout wrote:
On 25 Dec 2004 08:32:04 -0800, al********@hotmail.com (Alex) wrote:

Check out the Exec function in the help file.
-Tom.


Do you mean Eval()?

Nov 13 '05 #5
Paradigm wrote:
I tried Eval and it does seem to run the function but the function displays a form used as a progress counter and the form is not displayed.
In essence I have a continous form with about 50 records in it and the user can select any number of these. For each selection there is a function to run. My progress form shows which of the functions is currently running and how far through the function it is. All of this is working except being able to call the function using the function name stored as a string in a table. Alex


Perhaps the following brute force method is adequate:

Form code:

Dim varArray() As Variant

ReDim varArray(1)
varArray(0) = "My string"
varArray(1) = 3
MsgBox (EvaluateFunction("Function2", varArray()))
ReDim varArray(0)
varArray(0) = "New string"
MsgBox (EvaluateFunction("Function1", varArray()))

Module code:

Public Function EvaluateFunction(strFunctionName As String, varArray()
As Variant) As Variant
Select Case strFunctionName
Case "Function1": EvaluateFunction = Function1(varArray())
Case "Function2": EvaluateFunction = Function2(varArray())
Case Else
EvaluateFunction = strFunctionName & " is not in the function list."
End Select
End Function

Private Function Function1(varArray() As Variant) As String
Function1 = varArray(0)
End Function

Private Function Function2(varArray() As Variant) As Integer
Function2 = varArray(1)
End Function

Disclaimer: It's late and I'm tired. I didn't know if you needed
function arguments so I added varArray() for that purpose. Perhaps
ParamArray can be used to preserve argument names. Where's that
Functions collection Evaluate method hiding :-)?

James A. Fortune

I wonder if "works like a charm" only refers to charms that always
work.

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: none | last post by:
Hello all, I wrote a shell program a few years ago in VB6 that needs to be modified. The problem I have is this: The SysAdmin uses this shell in place of Explorer, so there is no taskbar. When...
1
by: Mike | last post by:
When trying to compile (using Visual Web Developer 2005 Express Beta; frameworkv2.0.50215 ) the source code below I get errors (listed below due to the use of ICallBackEventHandler. Ultimately I...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
3
by: Parveen | last post by:
I'm trying to use the GetUserName API function in the advapi32.dll library. I declare my function as follows Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer...
2
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified...
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
14
by: B Williams | last post by:
I am stuck on an assignment that uses classes and functions. I am receiving numerous errors when I try to run a test program to see if I wrote it correctly. Can someone please point me in the right...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.