|
-
Jun 24th, 2002, 04:42 AM
#1
Functions
Hi all, is it possible to call a function or sub when the name of the function is stored in a var.
When i try this i'll get the error
Compile error
Expected Sub, Function, or Property.
Is there a way to call it with the name stored in a string variable ??
-
Jun 24th, 2002, 04:46 AM
#2
Of course you'll get an error!! Try using a redirecting function instead.
Call redirector(variablename)
...
...
private function (redir as string)
select case redir
case "swatty"
call soandso()
case "mrpolite"
call linux()
end select
end function
-
Jun 24th, 2002, 04:47 AM
#3
Oops, I forgot to complete the sentence.
"Of course you'll get an error,you're calling a variable!!"
-
Jun 24th, 2002, 04:58 AM
#4
If I need to do it like that, i'll place an extra if else in my loop for calling the wright function.
It was for following.
got two functions with same parameters but different calculations in it.
So i would before i enter the loop put the function name in a var, and then call it through that var.
Instead i'll test it every time again.
Thanks for the quick reply though.
-
Jun 24th, 2002, 05:10 AM
#5
Banned
You can use the CallByName function, to call a sub or function stored in a variable. Like this:
VB Code:
Dim MyFunction As String
Dim MyParameters As Integer
MyFunction = "SquareRoot"
MyParameters = 200
'usage:
CallByName Me, MyFunction, VbMethod, MyParameters
This example shows how to call a sub called SquareRoot which needs an integer as parameter.
Last edited by Michael_Kamen; Jun 24th, 2002 at 05:14 AM.
-
Jun 24th, 2002, 05:13 AM
#6
Thanks from me... I had no idea about this one.
-
Jun 24th, 2002, 05:33 AM
#7
Blarney stone...my arse...
I was just about to post that answer 
I use it in collecton class module so allow the client side to display columns in a grid. You just add the Property names to an array, easy to change....
Wokawooooooo
-
Jun 24th, 2002, 05:40 AM
#8
Thanks but i think this won't work.
It is a function call in a module .
the option you gave me requires an object i don't have.
And my parameters must be given in an array.
this is my call to the first function.
bereken_totaal_incl_btw "vleveringslijn", vL.Fields("jaar"), vL.Fields("journaal"), vL.Fields("nummer"), vL.Fields("boekdatum"), vL.Fields("betalingsvw"), vL.Fields("munt"), n, b, t, f, True, "vlevering"
If i need to fill in the parametrlist first , i think it is faster with an if else statement.
Anyway I'll keep it in mind for later use.
Thanks Michael
-
Jun 24th, 2002, 05:50 AM
#9
Sausage and Chips is now illegal...
Errr...what do you mean by an object you don't have???
It will work...Just pass your para's in as an array....????
Woka
-
Jun 24th, 2002, 05:58 AM
#10
If I have to fill in an array of 12 elements against a selection , i think it will go faster with the selection.
Rhanks anyway
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|