也许是我讲得不够详细。比如楼上的例子中, 如果CA的成员有subA1,subA2,subC CB中有subB1,subC。 如果如楼上之定义方法,在程序中有如下表述: if 需要"CA" then myobj.subA1 myobj.subA2 myobj.subC else if 需要"CB" then myobj.subB1 myobj.subC end if 那么程序一定编译不过! 如何解决?(除了预编译)
在VB6中,Microsoft提供了新的技术。 Executes a method of an object, or sets or returns a property of anobject.CallByName(object, procedurename, calltype,[arguments()])The CallByName function is used to get or set a property, or invoke a method at run time using a string name.In the following example, the first line uses CallByName to set the MousePointer property of a text box, the second line gets the value of the MousePointer property, and the third line invokes the Move method to move the text box:CallByName Text1, "MousePointer", vbLet, vbCrosshair Result = CallByName (Text1, "MousePointer", vbGet) CallByName Text1, "Move", vbMethod, 100, 100
dim myObj as Object if 需要"CA" then set myObj= createobject("Project.CA") Result = CallByName (myobj, "MethodA", VbMethod,param1,param2,...)
else if 需要"CB" then set myObj= createobject("Project.CB") Result = CallByName (myobj, "MethodB", VbMethod,param1,param2,...) end if
如果CA的成员有subA1,subA2,subC
CB中有subB1,subC。
如果如楼上之定义方法,在程序中有如下表述:
if 需要"CA" then
myobj.subA1
myobj.subA2
myobj.subC
else if 需要"CB" then
myobj.subB1
myobj.subC
end if
那么程序一定编译不过!
如何解决?(除了预编译)
Executes a method of an object, or sets or returns a property of anobject.CallByName(object, procedurename, calltype,[arguments()])The CallByName function is used to get or set a property, or invoke a method at run time using a string name.In the following example, the first line uses CallByName to set the MousePointer property of a text box, the second line gets the value of the MousePointer property, and the third line invokes the Move method to move the text box:CallByName Text1, "MousePointer", vbLet, vbCrosshair
Result = CallByName (Text1, "MousePointer", vbGet)
CallByName Text1, "Move", vbMethod, 100, 100
if 需要"CA" then
set myObj= createobject("Project.CA")
Result = CallByName (myobj, "MethodA", VbMethod,param1,param2,...)
else if 需要"CB" then
set myObj= createobject("Project.CB")
Result = CallByName (myobj, "MethodB", VbMethod,param1,param2,...)
end if
qingfenge的帖子很有用,学习!不过对我的问题稍微偏了一点。
gcj123的热心谢谢了!是否通得过请再仔细看一下我写的那段,然后再试一下。
结贴!