例,我定义了一个变量Rst为RecordSet
则我可用以下属性
rst.Field("日期")=2008-1-1
我能在类中实现
cls.a之类的方法与属性,上述带参数的属性如何实现啊!

解决方案 »

  1.   

    'Class1
    Option Explicit
    Option Base 1
    Public Enum Attris
      日期 = 1
      其他
      数目
    End Enum
    Private attri(3, 1) As String
    Public Property Let setValue(ByVal flag As String, ByVal value As String)
      If flag = "日期" Then
        attri(Attris.日期, 1) = value
       ElseIf flag = "其他" Then
        attri(Attris.其他, 1) = value
       ElseIf flag = "数目" Then
         attri(Attris.数目, 1) = value
      End If
    End PropertyPublic Property Get getAttriValue(ByVal flag As String) As String
      If flag = "日期" Then
        getAttriValue = attri(Attris.日期, 1)
       ElseIf flag = "其他" Then
        getAttriValue = attri(Attris.其他, 1)
       ElseIf flag = "数目" Then
        getAttriValue = attri(Attris.数目, 1)
      End If
    End Property
    'form1
    Private Sub Command1_Click()
      Dim clsTest As New Class1
      clsTest.setValue("日期") = "222"
      clsTest.setValue("其他") = "111"
      clsTest.setValue("数目") = "000"
      Debug.Print clsTest.getAttriValue("日期")
    End Sub
      

  2.   

    参数写在括号里就是了.LET与SET,最后一个是等号右边的变量.在那之前,多少个参数都可以.'类模块
    Option ExplicitPrivate mvarMyField() As StringPublic Property Let MyField(ByVal Index As Long, ByVal vData As String)
        mvarMyField(Index) = vData      'ByVal vData As String之前,多少个参数都可以
    End PropertyPublic Property Get MyField(ByVal Index As Long) As String
        MyField = mvarMyField(Index)
    End PropertyPrivate Sub Class_Initialize()
        Dim I As String
        
        I = "A.B.C.D.E.F.G.H.I.J.K.L.M.N.O.P.Q.R.S.T.U.V.W.X.Y.Z"
        mvarMyField = Split(I, ".")
    End Sub
    '窗体,添加一个按钮.
    Option ExplicitPrivate Sub Command1_Click()
        Dim I As New Class4
        
        I.MyField(1) = "sdkjflasdjfa"
        Debug.Print I.MyField(1)
        Debug.Print I.MyField(2)
        Debug.Print I.MyField(8)
    End Sub