单个Return语句的Vbscript多个语句

时间:2017-08-16 13:38:46

标签: vbscript

我正在开发如下的VBScript

Dim a
Set a = New Class1
a("text").doSomething 'Has to execute doSomething in Class1
a("text").anotherSomething 'Has to execute doSoemthing in Class2

class Class1
    Dim b
    Dim c
    public default Function init(str)
          Set b = New Class2
          Set c = New Class3
          'Some more operations to perform
          If **What is the condition can be?** Then
              Set init = c
          Else
              Set init = b
          End If
    End Function
End class

class Class2
    public Function doSomething()
        'Stuff to do something
    End Function
End class
class Class3
    public Function anotherSomething()
        'Stuff to do something
    End Function
End class

这里,对象“a”具有参数,该参数可以相同。 所以,我不能保持参数“=”或“<>”

而且,我无法将这些功能放在Class1中。

那么,可以决定的条件是什么。

1 个答案:

答案 0 :(得分:0)

看起来您需要利用委托人。基本上,您需要的内部对象是您想要访问OOP中父类中的方法的类型。

以下是一个例子:

Class ScreenPoint
  '' Properties

  'Ancestor Point2D
  Private P2D
  'Point color
  Private Color
  '----------------------

  '' Methods
  'Constructor - called automatically
  Private Sub Class_Initialize()
    Set P2D = new Point2D
  End Sub
  '----------------------
  'Destructor - called automatically
  Private Sub Class_Terminate()
    Set P2D = Nothing
  End Sub
  '----------------------
  'A pair of methods to access private property X
  Property Get X
    X = P2D.X
  End Property

  Property Let X(ByVal in_X)
    P2D.X = in_X
  End Property
  '----------------------
  'A pair of methods to access private property Y
  Property Get Y
    Y = P2D.Y
  End Property

  Property Let Y(ByVal in_Y)
    P2D.Y = in_Y
  End Property
  '----------------------
End Class

如果您迷路了,请尝试阅读此处的源文章:http://automation-beyond.com/2008/11/16/oop-vbscript-2/