# Re: 测验程式的问题

Posted by 小v on October 14, 1999 at 09:33:02:

In Reply to: 测验程式的问题 posted by 志文 on October 13, 1999 at 21:25:41:

: 小弟因工作需要,自己想写一个可以测验股票代码的程式
: 就是我建好股票名称以及股票代码,当我开始测验时,pc出现名称,我输入代码,pc判断对错
: 目前我label4.caption 放入股票名称
: text2.text抓的为股票代码
: 可是底下的判断,却是失败的,请问各位先进能否指导一下,谢谢

: Private Sub Command1_Click() '开始测验
: Dim i As Variant
: Dim ansq As Variant
: correct = 0: wrong = 0
: For i = 0 To Data1.Recordset.RecordCount - 1
: Label4.Caption = Data1.Recordset.Fields(i + 1).Value
: Text2.SetFocus
: If Text2(ansq).Text = Data1.Recordset(i).Value Then
: correct = correct + 1
: CurrentX = 2000: CurrentY = 3000
: Print "答对了"
: Data1.Recordset.MoveNext
: Else
: wrong = wrong + 1
: CurrentX = 2000: CurrentY = 3000
: Print "答错了"
: End If
: Next
: End Sub

改成下面这样试试:
Sub Form_Load()
Data1.Recordset.MoveFirst
Label4.Caption = Data1.RecordSet.Field("股票名称")
Text2.Text = ""
End Sub

Sub Command1_Click()
if Data1.RecordSet.Field("股票代号")=Text2.Text Then
Correct = Correct + 1
MsgBox "答对了!"
Else
Wrong = Wrong + 1
MsgBox "答错了!"
End If
Data1.Recordset.MoveNext
If Not Data1.Recordset.Eof Then
Label4.Caption = Data1.RecordSet.Field("股票名称")
Text2.Text = ""
else
MsgBox "测试完毕!"
end if
End Sub

Follow Ups: