Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing function name into a public function as an argument

Status
Not open for further replies.

nrjhano

Technical User
May 9, 2000
19
0
0
SE
I have spent some time to search for techtips for this problem and on microsoft´s site but in vain.

I would like to pass a function() or procedure() call as an argument to another function() or procedure(). The most obvious thing is to send it as a string, however, when I assign this string to a variable it is interpreted as a string instead of a function which of course is rather reasonable.

My question is: How can this be done?

I have seen a contribution called "Passing label name to a public function" but, regretfully, it doesn´t give me any useful ideas.

Hakan
Canarian Islands 2001-11-10

 
Hakan
Pass a boolean (switch) with the function. Then in the called module, interrogate the switch with an IF/THEN/ELSE construct. If the switch = Y(es) then call the function you need. Any parameters need by the final function call can be passed by the first function call.
-Geno
 
Your answer is a straightforward solution and gave me a reason to formulate myself more precisely. Your suggestion means that I have to edit the called function each time I call it with a new function. I would like to avoid that complication. In one exellent document from the microsoft site I found the following passage:

***Beginning of extract
Working with Stored Procedures

You can use ODBCDirect QueryDef objects to run stored procedures. ODBCDirect QueryDef objects support stored procedures that have both input parameters and return values. Input parameters are the parameter values supplied to the procedure at run time. The procedure's return value is the value that it returns when it has finished running. For example, a stored procedure may return the number of records that have been affected.

The following example creates a stored procedure named GetEmps on the server.

strSQL = "CREATE PROCEDURE GetEmps AS "
strSQL = strSQL & "SELECT * FROM EMPLOYEE;"
cnn.Execute strSQL


If there is already a stored procedure named GetEmps on the server, you can use the DROP statement to delete it before creating a new one, as shown in the following example.

strSQL = "DROP PROCEDURE GetEmps;"
cnn.Execute strSQL


You can run the stored procedure by using the Execute method of a Connection object. To retrieve the return value, create a QueryDef object and open a recordset on it.

Set qdf = cnn.CreateQueryDef("qry", "{ call GetEmps() }")
Set rst = qdf.OpenRecordset

*** End of extract

The article is from Microsoft office developer forum about "Data Access Object".

I am attempting to adapt this method on my problem.

Does anybody know if this will solve my problem?

Hakan
 
The Eval funtion will likely work for you. Check it out in help.
 
Check out the run method in the help

application.Run procedure[, arg1, arg2, ..., arg30]

example Application.Run "basTestFunction"

This may be what you are asking for.


 
Tanks lameid. Eval is a terrific function. Only one thing, it doesn´t seem to like Recordset and TableDef. Also, one string variable that contained "C:\nnnn" was misinterpreted. Well, I suppose eval is an overloaded function that works on string contents in some mysterious fashion so maybe I shouldn´t be surprised. Anyway I tried many ways to generalise the use of passed function with separately passed parameters but failed utterly. I will take a look on xmad4´s promising solution today.

Anyway, thank you all for your enligthning suggestions.

Hakan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top