VB中的SET是用来为对象付值的,如果你的属性数据类型不是一个对类型的,就不用Set

解决方案 »

  1.   

    在VB中,set varX=[value]语句的使用要求是:
        varX必须是一个对象变量,而且同时value必须是varX对象的一个实例。
    我估计你的语句应该改成 ab.exmma=text1.text,也就是说去掉set。
      

  2.   

    老兄 Set是給對象賦值的應該這樣些
    Option ExplicitPrivate m_exmma As StringPublic Property Get exmma() As String
        exmma = m_exmma
    End PropertyPublic Property Let exmma(ByVal NewValue As String)
        m_exmma = NewValue
    End Property
    Public Sub update()
    ' 代碼
    End Sub實際應用如下ab.exmma=text1.text
      

  3.   

    Option Explicit
    Public conn As ADODB.Connection
    Private mvarexamword As String
    Private mvarstname As String
    Private mvarmorse As Boolean
    Public Sub delectdate()
     If morse = True Then
        conn.Execute ("delect from examword")
      Else
        conn.Execute ("delect from examword where examword='" & mvarexamword & "'")
    End If
    End Sub
    Public Sub insertdate()
    conn.Execute ("insert into examword(examword,stname) values(mvarexamword,mvarstname)")
    End Sub
    Public Sub update()
    conn.Execute ("update examword set stname='" & mvarstname & "'where examword='" & mvarexamword & "'")
    End SubPublic Sub getdate()
    Dim rst As New ADODB.Recordset
     If morse = True Then
          Set rst = conn.Execute("select*from examwrod")
       Else
             Set rst = conn.Execute("select * from examword where examword='" & mvarexamword & "'")
    End If
    End SubPublic Property Let morse(ByVal vData As Boolean)
        mvarmorse = vData
    End Property
    Public Property Get morse() As Boolean
        morse = mvarmorse
    End PropertyPublic Property Let stname(ByVal vData As String)
        mvarstname = vData
    End Property
    Public Property Get stname() As String
        stname = mvarstname
    End PropertyPublic Property Let examword(ByVal vData As String)
        mvarexamword = vData
    End Property
    Public Property Get examword() As String
        examword = mvarexamword
    End PropertyPrivate Sub Class_Initialize()
    conn.ConnectionString = "porvider=microsoft.jet.oledb.4.0; datasoure=C:\WINDOWS\Desktop\类\examsystem.mdb"
    conn.Open
    If conn.State <> adStateOpen Then
        MsgBox "数据库打开失败", vbOKOnly + vbCritical, "警告"
            Exit Sub
    End If
    End SubPrivate Sub Class_Terminate()
    conn.Close
    End Sub
    这是一个类名为examword1的类
    我在另一个工程中引用它
    Private Sub Form_Load()
    Dim aa As examword1
    Set aa = New examword1‘到此处就出错了,我看了很多书都不明白是怎么一回事
    aa.examword = Text1.Text
    aa.stname = Text2.Text
    aa.insertdate
    End Sub
    在到第二行时就出错了
    错误是:未设置对象变量或with block变量
    如果是这样的话
    Private Sub Form_Load()
    Dim aa As examword1
    Set aa = New examword1
    Set aa.examword = Text1.Text ‘属性的使用无效
    Set aa.stname = Text2.Text
    aa.insertdate
    End Sub
      

  4.   

    这样定义不对 dim ab as new examword1.emaxword先不加NEW关键字,定义完后用SET 赋值再加NEW就可以了
      

  5.   

    类里conn没有赋值!
    用Public conn As new ADODB.Connection