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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

application.run

Status
Not open for further replies.

vlad123

Programmer
Jun 22, 2005
37
DE
Hi! My problem looks something like this:
I have some sequences, every sequence has some steps.Every step is a function.Of course, every step, function can have one or more arguments.
for every sequence I have to call every function with its own arguments.
these things I have in a DB.
I have the name of the function in a variable, so I can use:
Application.run function_name, arg1, arg2,...
the problem is that I dont know how to solve with these arguments.because sometimes its just one, but can be also 2 or 3 ....
if you need more details...just ask for!
thanks!
 
It looks like you want a standard statement that you can use and reuse that will let you pass any number of arguments to any/all functions, regardless of the number of arguments the function expects. Is that the gist of what you have going on?

Two options off the top of my head:

Rewrite the functions to expect an array, and then pass in an array that you construct with the arguments that you need. The Function you are calling will have to know how to handle the array - what every array element means, etc.

Your Function declaration would look like:

Public MyFunction(vArray() as Variant) As WHATEVER_TYPE

Your call would look something like:

Code:
dim vArgs() as Variant
dim a as integer
dim Function_Name as string

Function_Name = "MyFunction"

For a = 0 to 4
  redim preserve vArgs(a)
  vargs(a) = a
Next a

Application.Run Function_Name, vArgs

The other option is to declare a user type with properties of types that you will need:

Code:
Public Type FunctionArgs
  Str1 as string
  Str2 as string
  Str3 as string
  Str4 as string
  Str5 as string

  Lng1 as Long
  Lng2 as Long
  Lng3 as Long
  Lng4 as Long
  Lng5 as Long

  Boo1 as Boolean
  Boo2 as Boolean
  Boo3 as Boolean
End Type

Your Function would have to expect a single argument of FunctionArgs Type:

Public MyFunction(faFunArgs as FunctionArgs) As WHATEVER_TYPE

Then your call would look something like this:

Code:
dim FunArgs as FunctionArgs
dim Function_Name as string

Function_Name = "MyFunction"

FunArgs.Str1 = "Some string."
FunArgs.Str2 = "Some other string."
FunArgs.Boo1 = True
RunArgs.Lng1 = 1000

Application.Run function_name, FunArgs

I like the latter option better, because it gives a cleaner interface to the values with less chance of error.

HTH
Rubbernilly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top