|
-
October 17th, 2001, 04:02 PM
#1
variable for methods
hello all,
Is it possible to use a variable for methods?
In the following example, add_two() and substract_two() are two methods, but I do not know which one will be called during coding.
======================
Set m_obj = AdvCreateObject("MyObject.myObject")
var_method = "add_two"
result = m_obj.var_method(11, 22) '??????
var_method = "substract_two"
result = m_obj.var_method(11, 22) '??????
======================
thanks!
_Zhining Zhang
-
October 17th, 2001, 10:23 PM
#2
Re: variable for methods
As far as I know this is IMPOSSIBLE
But u can achieve the same by having an argument in the var_method to get the method name and inside the code deal with that accordingly
' In the class:
public Function var_method(s as string , n1 as Integer , n2 as Integer ) as Integer
If s = "add_two" then
var_method = n1 + n2
ElseIf s = "substract_two" then
var_method = n1 - n2
else
' .....
Endif
' The Method has to be called as
'======================
set m_obj = AdvCreateObject("MyObject.myObject")
result = m_obj.var_method("add_two", 11, 22)
result = m_obj.var_method("substract_two"
, 17, 34) '??????
'======================
If u don't know how to Rate an answer, then Rate my answer to learn, If u know, then practice it 
-
October 18th, 2001, 08:30 AM
#3
Re: variable for methods
This is a feature of languages like Lisps with which you can actually delay the evaluation of an expression till you tell him to do it...
VB isn't like that and you should do as the other guy says.. Pass a string parameter and check for that parameter to do the right call you wanna make.
Nic
Nicolas Bohemier
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
|