源程序:
 Private Sub Command1_Click()
   If Text1.Text <> "" Then Dim re As ADODB.Recordset
 Dim con As New Connection
 Dim st1 As String
 Dim st2 As String
 Dim st3 As String
 Dim st4 As String
 Dim st5 As String
 Dim st6 As String
 Dim st7 As String
 Dim st8 As String
 
 Dim sz1(1 To 10) As Single
 Dim sz2(1 To 10) As Single
 Dim sz3(1 To 4) As Single
 Dim sz4(1 To 4) As Single
 
 con.Open "dsn=shitiku"
For a = 1 To 40
  sum1 = 0
  sum2 = 0
  sum3 = 0
  sum4 = 0
    For i = 1 To 10
      Randomize
   sz1(i) = Int(Rnd * 50) + 1
      st1 = "select 分值*难度系数 as s1 from 选择题表 where 题型='选择'and 试题号=" & sz1(i)
      Set re = con.Execute(st1)
      sum1 = sum1 + re("s1")
    Next i
     For j = 1 To 10
      Randomize
    sz2(j) = Int(Rnd * 50) + 1
      st2 = "select 分值*难度系数 as s2 from 填空题表 where题型='填空'and 试题号=" & sz2(j)
      Set re = con.Execute(st2)
      sum2 = sum2 + re("s2")
    Next j
    For k = 1 To 4
      Randomize
      sz3(k) = Int(Rnd * 25) + 1
      st3 = "select 分值*难度系数 as s3 from 简答题表 where 题型='简答'and 试题号=" & sz3(k)
      Set re = con.Execute(st3)
      sum3 = sum3 + re("s3")
    Next k
    For l = 1 To 4
      Randomize
      sz4(l) = Int(Rnd * 25) + 1
      st4 = "select 分值*难度系数 as s4 from 计算题表 where 题型='计算'and 试题号=" & sz4(l)
      Set re = con.Execute(st4)
      sum4 = sum4 + re("s4")
    Next l
     If (sum1 + sum2 + sum3 + sum4) / 100 = Val(Text1.Text) Then
  End If
  Next a
  
    For i = 1 To 10
      st5 = "select 内容 from 选择题表 where 试题号=" & sz1(i)
        Set re = con.Execute(st5)
        Form2.List1.AddItem re("内容")
       Next i
        For j = 1 To 10
      st6 = "select 内容 from 填空题表 where 试题号=" & sz2(j)
        Set re = con.Execute(st6)
        Form2.List2.AddItem re("内容")
       Next j
       For k = 1 To 4
       st7 = "select 内容 from 简答题表 where 试题号=" & sz3(k)
        Set re = con.Execute(st7)
        Form2.List3.AddItem re("内容")
        Next k
        For l = 1 To 4
      st8 = "select 内容 from 计算题表 where 试题号=" & sz4(l)
        Set re = con.Execute(st8)
        Form2.List4.AddItem re("内容")
       Next l
   con.Close
   Else: MsgBox "请输入难度系数"
   End If
end sub
  运行出错提示: 用户定义类型未定义
  请帮帮忙

解决方案 »

  1.   

    Dim re As new ADODB.Recordsetst1 = "select 分值*难度系数 as s1 from 选择题表 where 题型='选择'and 试题号='" & sz1(i) & "'
    如果你的试题号如为数字型,不用这样如是字符型,要按以上的, 其他的st2,st3,st4都是这样格式Set re = con.Execute(st4)
          sum4 = sum4 + re("s4")
        Next l
         If (sum1 + sum2 + sum3 + sum4) / 100 = Val(Text1.Text) Then
      End If
      Next are.close ‘是必需的///
      

  2.   

    第一步要加New 要不在set rs=new adodb.recordsetSet re = con.Execute(st1)
    ......
      

  3.   

    1.要添加Microsoft ActiveX data objects 2.x Library引用2.Dim sz1(1 To 10) As Single你定义的试题号为数值型,那么应该这样写st1 = "select 分值*难度系数 as s1 from 选择题表 where 题型='选择'and 试题号=" & sz1(i) & ""
    下面的也要改过来
      

  4.   

    : rainstormmaster(rainstormmaster
    我那个没有引用ado
      

  5.   

    在VB菜单[工程]下的引用中选中Microsoft ActiveX Data Object 2.1 Library
      

  6.   

    同志呀
      你的ADO控件都没有引用,当然不行了呀
      再说你的SQL语句中的字段类型没有指定正确哟,呵呵
      具体的代码,自己去写哟!!!!呵呵