这标题话有点ao口,还是举例吧'在一个模块中定义了两个自定义类型:
Public Type At
    a As Integer
    b As Integer
End TypePublic Type Bt
    a As Integer
    b As Integer
End Type
'另一个地方用到了:
Private Sub Form_Load()
    Dim x '----------------此处, x 要 As 什么才下面的代码才不会出错呢?
    Dim a As At
    Dim b As Bt
    x = a
    x = b
End Sub

解决方案 »

  1.   

    还真不好解决.只不过,这种情况,我都是用类的.建议一个类
    类里面的代码
    类名 Cls
    public a As Integer
    public b As Integer引用Private Sub Form_Load()
        Dim x as Object
        Dim a As New Cls
        Dim b As New Cls
        set x = a
        set x = b
    End Sub
      

  2.   

    唉,真不好解决.用类的话VB不支持public的数组,真是奇怪.就只能写一大堆函数来进行数组访存
    但我是懒人~~而且一定要数组~
      

  3.   

    不好意思 弄错了 
    dim x as Variant
      

  4.   

    类里面也可以用数组啊.
    '类里面的代码,类名Class1Option ExplicitPrivate m_Arr(100) As String
    Public Property Get Arr(ByVal Index As Integer) As String
       Arr = m_Arr(Index)
    End PropertyPublic Property Let Arr(ByVal Index As Integer, ByVal vNewValue As String)
      m_Arr(Index) = vNewValue
    End Property
    '窗体中的代码
    Option ExplicitPrivate Sub Command1_Click()
      Dim A1 As New Class1
      A1.Arr(1) = "12"
      MsgBox A1.Arr(1)
    End Sub
      

  5.   

    当然是用 Variant 类型。
    不过对 UDT(User Define Type) 要求是具有 UUID 的,意思就是:
    ·要么 Public Type 声明在 ActiveX Dll/Exe/Control 工程的 Public Class/Control 中;
    ·要么将结构声明在 tlb 中。《高级 Visual Basic 编程》(Advance Visual Basic) 中说得很明白。可以在 CSDN 得资源下载中找到该书。
      

  6.   

    哎呀!刚刚结帖,用Property这种方式也可以,不过如果能用自定义结构就更好了,应该效率更高吧.刚刚找到了《高级 Visual Basic 编程》,看看先~
      

  7.   

    《高级 Visual Basic 编程》真是本好书哇,早些见到就好了
    等把这本书修炼完了,我也应该是高手了,哼哼哼哼~~