474,042 Members | 39,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4708
On 25 Dec 2004 08:32:04 -0800, al********@hotm ail.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********@hotm ail.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.*********@he uvelqop.nl> wrote:

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

-Tom.
Tom van Stiphout wrote:
On 25 Dec 2004 08:32:04 -0800, al********@hotm ail.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.c om...
On Sat, 25 Dec 2004 17:52:41 +0100, Bas Cost Budde
<b.*********@he uvelqop.nl> wrote:

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

-Tom.
Tom van Stiphout wrote:
On 25 Dec 2004 08:32:04 -0800, al********@hotm ail.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 (EvaluateFuncti on("Function2" , varArray()))
ReDim varArray(0)
varArray(0) = "New string"
MsgBox (EvaluateFuncti on("Function1" , varArray()))

Module code:

Public Function EvaluateFunctio n(strFunctionNa me As String, varArray()
As Variant) As Variant
Select Case strFunctionName
Case "Function1" : EvaluateFunctio n = Function1(varAr ray())
Case "Function2" : EvaluateFunctio n = Function2(varAr ray())
Case Else
EvaluateFunctio n = strFunctionName & " is not in the function list."
End Select
End Function

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

Private Function Function2(varAr ray() 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
6976
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 his users run PC Anywhere from the shell, and minimize it, it minimizes to the system tray. With no task bar, there is no system tray, so there is no way to restore the PC Anywhere window. The shell starts PC Anywhere using ShellExecute. I...
1
567
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 want to use a callback from the client side to update webcontrols based on user input without using postback. I am seeking a way to stop the compile errors. using System; using System.Data;
3
24053
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 tables in the database where the code resides. If we move the database with the data tables to a new directory, the links are no longer valid. I tried to update the links by changing the Connect property and refreshing: Set td = db.TableDefs(0)...
5
2989
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 problems with the http://www.mvps.org/access/api/api0002.htm but it only browse to folders.
11
6645
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 where the job is running, the job runs sucessfully, PDF files got generated, everything is good. If I scheduled the job to run at the time that I am not logged into the server, Access is not able to print to the printer. The error is pretty...
1
4030
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 live databases on the network. Is there a way, via code, when I get back in-house from being on the road to click a button, and select the backends I want to link to? I would want to delete all the current links and link to the "live"
3
9853
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 As String, ByVal nsize As Long) As Lon But when I call the function like this lngRetVal = GetUserName(strName, lngSize I get the following error
2
5065
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 folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when you select the file/folder and then: Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
3
5355
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 at it and let me know what I need to change. I have tried changing the "hwnd" type into intptr's but there seem to be other problems too, like it won't allow "lParam As Any" to be declared.
14
2131
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 direction. These are two of the error messages I am receiving. error C2660: 'Invoice::setPartNumber' : function does not take 1 arguments error C3861: 'setItemQuantity': identifier not found This is the code. Thsnks in advance
0
10337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
12135
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11601
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12014
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11138
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7865
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6833
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5409
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.