在类模块中,如何判断标准模块中自定义类型的数组是否为空?
问题解决,马上结贴.

解决方案 »

  1.   

    dim lhp() as string
    if ubound(lhp)<>0 then 
       
    elseend if
      

  2.   

    可能我没有说清楚,变量是在标准模块中定义的,而我要在类模块中访问.而且这个变量是Type型的,不能用IsNull或者IsEmpty进行判断,用UBound是肯定不行的.
      

  3.   

    类模块中
    Public Sub ShowCpuInfo()
    On Error GoTo errHandle
        Dim i As Integer
        If UBound(MySys) = -1 Then Exit Sub
        For i = 0 To UBound(MySys)
            MsgBox MySys(i).CPU
        Next
    errHandle:
        If Err.Number = 9 Then
            MsgBox "数组为空"
        End If
    End Sub模块中
    Private Type SystemInfo
       CPU As Variant
       Memory As Long
       VideoColors As Integer
       Cost As Currency
       PurchaseDate As Variant
    End TypePublic MySys() As SystemInfo窗体中
    Dim MyClass As Class1
    Private Sub Command1_Click()
        MyClass.ShowCpuInfo
    End SubPrivate Sub Form_Load()
       Set MyClass = New Class1
       initMySys    ’使用此句则正常通过,不使用则捕捉到数组为空
    End Sub
    sub InitMySys()
       ReDim Preserve MySys(0)
       MySys(0).CPU = "p3"
       ReDim Preserve MySys(1)
       MySys(1).CPU = "p4"
    end sub
      

  4.   

    问题解决了,多谢SoHo_Andy(冰),结贴.