在vb6中随机生成40个问题?请帮我

时间:2010-01-30 15:26:45

标签: vb6 random

我一直在尝试创建一个vb6代码,该代码将随机化10个问题,但它无效。我使用sql作为我的数据库

这是我的代码:

Private Sub cmdNext_Click()
Dim real_ans As String
Dim nCnt As Integer
'nCnt = nCnt + 2
'Label3.Caption = nCnt
real_ans = Adodc1.Recordset.Fields("answer")
 With Adodc2.Recordset
 Dim grade As String

If (real_ans = "A" And Option1.Value = True) Or (real_ans = "B" And Option2.Value = True) Or (real_ans = "C" And Option3.Value = True) Or (real_ans = "D" And Option4.Value = True) Then
    .Fields("english_score").Value = .Fields("english_score").Value + 1
     nEnglish_score = Adodc2.Recordset.Fields("english_score").Value
     Select Case nEnglish_score
Case Is >= 7 'If score above 80...
    grade = "genius" 'Give an A
    With Adodc2.Recordset
    .Fields("IQ").Value = grade
    End With
Case Is >= 6 'If score above 70...
    grade = "Superior " 'Give a B
     With Adodc2.Recordset
    .Fields("IQ").Value = grade
    End With
Case Is >= 5 'If score above 60...
    grade = "High Average" 'Give a C
     With Adodc2.Recordset
    .Fields("IQ").Value = grade
    End With
Case Is >= 4 'If score above 50...
    grade = "Average" 'Give a D
     With Adodc2.Recordset
    .Fields("IQ").Value = grade
    End With
Case Is >= 3 'If score above 40...
    grade = "Low Average " 'Give a E
     With Adodc2.Recordset
    .Fields("IQ").Value = grade
    End With
Case Is >= 2 'If score above 30...
    grade = "Moron" 'Give a F
     With Adodc2.Recordset
    .Fields("IQ").Value = grade
    End With
Case Is >= 1 'If score above 20...
    grade = "Idiot " 'Give a G
     With Adodc2.Recordset
    .Fields("IQ").Value = grade
    End With
Case Else 'Else
    grade = "xxxx" 'Give a G
     With Adodc2.Recordset
    .Fields("IQ").Value = grade
     .Update
    End With
End Select

     End If
    Adodc1.Recordset.MoveNext
    End With



End Sub

Private Sub Command1_Click()
frmExam2.Show
frmExam2.SetFocus
End Sub

Private Sub Form_Initialize()
Command1.Enabled = False
With Adodc2.Recordset
.AddNew
.Fields("name").Value = cStudent_Name
.Fields("section").Value = cStudent_Section
.Fields("english_score").Value = "0"
.Fields("math_score").Value = "0"
.Fields("abstract").Value = "0"
.Fields("total_average").Value = "0"
.Fields("IQ").Value = "0"
.Update
End With
End Sub

Private Sub Text1_Change()
If Text1.Text <> "" Then
cmdNext.Enabled = True
Else
Command1.Enabled = True
 cmdNext.Enabled = False
End If
End Sub

请帮帮我,我不知道什么是错的。

1 个答案:

答案 0 :(得分:1)

是的,错误信息是什么?

  1. 使用此'with'不保存任何空格: 使用Adodc2.Recordset .Fields(“IQ”)。值=等级

    结束
  2. 你可以删除那个代码块到最后(在结束选择之后),因为无论如何它都在每个Case语句中。 所以压缩到: Adodc2.Recordset.Fields(“IQ”)。Value = grade

  3. 为什么不以相同的方式存储您的选项值和答案,这样您就可以进行单一比较,例如: 如果real_ans = OptionValue则...

  4. 对于随机数,试试这个:

    Function Rand(max As Long, Optional Min As Long) As Long
    
            Dim s As Single
            s = Rnd(1) * (max - Min + 1) + Min - 0.5
            Rand = CLng(Round(s, 0))
    
    
    End Function
    

    并将RANDOMIZE放入form_load