我用VB做了一显示RTF格式文件的控件,生成OCX文件时,刚开始还很正常,可以正常显示,为什么我修改之后再重新生成OCX文件时就不能正常显示了,只有VB中那个“start”按钮运行时才能显示,以前的不需要
为什么???对VB不熟,请大家帮帮忙~~~

解决方案 »

  1.   

    控件通过传递来的参数与数据库联接,读取数据显示。有参数传值,在VB中不好直接调试。源文件如下,还请多多指教:)第一次用VB写东西,代码很乱Const EM_LINESCROLL = &HB6
    Private Const EM_LINEINDEX = &HBB
    Private Const EM_LINEFROMCHAR = &HC9
    Const EM_GETFIRSTVISIBLELINE = &HCE
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As LongDim con As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim con2 As New ADODB.Connection
    Dim rs2 As New ADODB.RecordsetDim answ(100) As String
    Dim proH(100) As Integer
    Dim proSty(100) As Integer
    Dim blankNum(50) As Integer
    Dim anSave(100) As String
    Dim proNum As Integer
    Dim uCls As Integer
    Dim uID As Integer
    Dim DBpaperid As Integer
    Dim arrDBanswPublic Property Get usercls() As Integer
     usercls = 0
    End PropertyPublic Property Let usercls(ByVal cls As Integer)
    uCls = cls
    PropertyChanged "usercls"
    If uCls = 1 Then
     submit.Visible = False
     viewansw.Visible = False
     complete.Visible = False
    End If
    End Property
    Public Property Get userid() As Integer
    userid = 0
    End Property
    Public Property Let userid(ByVal newID As Integer)
     uID = newID
     PropertyChanged "userid"
    End Property
    Public Property Get pro_id() As Integer
    pro_id = 1
    End PropertyPublic Property Let pro_id(ByVal newID As Integer)
        paperid = newID
     PropertyChanged "pro_id"
     
       Call show(paperid, uCls, uID)
       Call getProH
       rtf_pro.SelStart = 0
    End PropertyPublic Function show(ByVal paperid As Integer, ByVal usercls As Integer, ByVal userid As Integer)
    uCls = usercls
    DBpaperid = paperid
    uID = userid
    'MsgBox ("uCls::" & uCls & "==uID==" & uID & "==paperid==" & paperid)Dim profile
    Dim p_Profile
    Dim apro As StringOn Error Resume Next
    If DBpaperid <= 0 Then
    t = MsgBox("没有此试卷!", "", "显示试出错")
     Exit Function
    End If con.Open "webexam", "sa", "afrime"
        
    '对参数进行判断,检测权限
    sql = "select * from userinfo where userID =" & uID
    Set rs = con.Execute(sql)
    If Not rs.EOF Then
        DBuCls = rs("userCls")
    Else
    Dim no
        no = MsgBox("非法操作,请和管理员联系!", , "出错提示")
                a.Visible = False
                b.Visible = False
                c.Visible = False
                d.Visible = False
                rtf_anw.Visible = False
                rtf_pro.Visible = False
                prolist.Visible = False
                submit.Visible = False
                complete.Visible = False
                viewansw.Visible = False
                tansw.Visible = False
                p_score.Visible = False
                title.Visible = False
                p_time.Visible = False
                
                
        Exit Function
          
          
          
    End If
    rs.CloseIf DBuCls <> uCls Then
    Dim jjj
        jjj = MsgBox("非法操作,请和管理员联系!", , "出错提示")
        uCls = 0
                a.Visible = False
                b.Visible = False
                c.Visible = False
                d.Visible = False
                rtf_anw.Visible = False
                p_score.Visible = False
                title.Visible = False
                p_time.Visible = False
                rtf_pro.Visible = False
                prolist.Visible = False
                submit.Visible = False
                 tansw.Visible = False
                complete.Visible = False
                viewansw.Visible = False
        Exit Function
    End If
        
        
        sql = "select * from wholepaper where p_id = " & DBpaperid
        Set rs = con.Execute(sql)
        
        If Not rs.EOF Then
        p_Title = rs("p_title")
        p_Date = rs("p_date")
        p_Profile = Split(rs("p_profile"), "+")
        p_source = rs("p_source")
        p_time = rs("p_time")
        p_score = rs("p_score")
        title.text = Trim(p_Title)
        p_time.text = "考试时长:" & p_time & "分钟"
        p_score.text = "试卷分数:" & p_score
        proNum = UBound(p_Profile)
        Else
        Exit Function
        End If
     rs.Close
      
     
    '创建题目列表树
    Dim pNode
      Set pNode = prolist.Nodes.Add(, , "Root", "题目列表")
            
        con2.Open "pro", "sa", "afrime"
        
        Dim i As Integer
        
        For i = 0 To proNum
        
            '取得题目
            profile = Split(p_Profile(i), "_")(0)
         '   MsgBox ("ProbID:" & profile & " ==PB::" & p_Profile(i))
            Set rs2 = con2.Execute("select * from ProbCont where i_Probid ='" & profile & "'")
             pro = cto(rs2("i_pcont"), i)
            apro = apro & pro
            rs2.Close
     
            
            
            '取得题目类型
           
            typeKey = Split(p_Profile(i), "_")(1)
            typeValue = GetTypeValue(typeKey)
            tv = "p" & typeKey
            proSty(i + 1) = typeKey
         '   MsgBox ("typeKey" & typeKey & "=========Type:" & typeValue)
             
             ' 取得答案
          If uCls = 1 Then
             Set rs2 = con2.Execute("select I_ACONT from answcont where i_probid = '" & profile & "'")
                    DBansw = rs2("I_ACONT")
                    answ(i) = DBansw
                 rs2.Close
           End If
          '  MsgBox ("Answ:" & answ(i))
           
             
         '添加题目列表的子节点
            
         On Error Resume Next
         
         test = prolist.Nodes.Item(tv).text
         
         If Err = 35601 Then
            Set pNode = prolist.Nodes.Add("Root", tvwChild, tv, typeValue)
            pNode.EnsureVisible
         End If
         
         Set pNode = prolist.Nodes.Add(tv, tvwChild, , i + 1)
                Next
         rtf_pro.TextRTF = "{\rtf1\ansi \deff0\deflang1033" & apro & "}"
         
         
    Dim DBanswstr
        DBanswstr = ""
    sql = "select answ_text from paperansw where paper_id=" & DBpaperid & " and userid=" & uID
    Set rs = con.Execute(sql)
    If Not rs.EOF Then
        DBanswstr = rs("answ_text")
    End Ifrs.Close
    If DBanswstr = "" Then
        For i = 0 To proNum
             DBanswstr = DBanswstr & "^|" & i + 1 & "   "
        Next
        con.Execute ("update paperansw set answ_text = '" & DBanswstr & "' where paper_id = " & DBpaperid & " and userid = " & uID)
    End If
    arrDBansw = Split(DBanswstr, "^|")
    End Function(下面续)