dim myObj as Object
if 需要"CA" then
  set myObj= new CA
else if 需要"CB" then
  set myObj= new CB
end if不知道是不是你要的情况

解决方案 »

  1.   

    也许是我讲得不够详细。比如楼上的例子中,
    如果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
    那么程序一定编译不过!
    如何解决?(除了预编译)
      

  2.   

    在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
      

  3.   

    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
      

  4.   

    我那个例子通不过?是不可能,在我的程序,我就是这样用的,没有问题啊,关键是要把myObj定义成Object类型
      

  5.   

    http://www.csdn.net/develop/Read_Article.asp?Id=16544
      

  6.   

    enhydraboy的回答十分贴切!高手风范!
    qingfenge的帖子很有用,学习!不过对我的问题稍微偏了一点。
    gcj123的热心谢谢了!是否通得过请再仔细看一下我写的那段,然后再试一下。
    结贴!