2010-01-30 66 views
0

我一直在試圖創建一個vb6代碼,將隨機10個問題,但它不工作。我使用SQL作爲我的數據庫在vb6中隨機生成40個問題?請幫助我

這裏是我的代碼:

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 

請幫助我,我無法弄清楚什麼是錯。

+0

錯誤描述總是很好的這些類型的問題:) – cwap 2010-01-30 15:32:02

+0

什麼是錯誤 – 2010-01-30 16:06:17

+0

沒有錯誤我不知道如何隨機問題 – 2010-01-30 16:13:17

回答

1

是的什麼是錯誤信息?

  1. 你不保存任何這方面的空間「與」: 隨着Adodc2.Recordset 點域(「智商」)值=等級 尾隨着

  2. 您可以刪除塊的代碼(End Select之後),因爲它在每個Case語句中都是如此。 所以壓縮它歸結爲: Adodc2.Recordset.Fields(「智商」)值=等級

  3. 爲什麼沒有你的選項值,並存儲在相同的方式回答,所以你可以做一個比較單一,像: 如果real_ans = OptionValue然後...

的隨機數,試試這個:

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