永发信息网

谁帮我看看这段VB代码

答案:1  悬赏:0  手机版
解决时间 2021-05-16 08:53
  • 提问者网友:杀手的诗
  • 2021-05-15 19:19

Option Explicit
Dim op, n1, n2, nop, n3
Dim result
Private Sub Command1_Click()
Timer1.Enabled = True
Call cs
Text1.SetFocus
End Sub

Private Sub Command2_Click()
Picture1.Visible = True
Picture2.Visible = True
Label3.Visible = True
End Sub

Private Sub Form_Load()
Picture1.Visible = False
Picture2.Visible = False
Label3.Visible = False
Timer1.Interval = 30
Timer1.Enabled = False
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Val(Text1) = result Then Call cs
Text1.SetFocus
End If
End Sub

Private Sub Timer1_Timer()
Picture1.Move Picture1.Left + 30
If Picture1.Left > Form1.Width Then Timer1.Enabled = False
If Label3.Left > Form1.Width Then Timer1.Enabled = False
Picture2.Move Picture2.Left + 10
If Picture2.Left > Form1.Width Then Timer1.Enabled = False
End Sub

Sub cs()
Randomize
nop = Int(Rnd * 4 + 1)
Select Case nop
Case 1
op = "+"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
Label3.Caption = n1 & "+" & n2 & "="
result = n1 + n2
Case 2
op = "-"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
If n1 < n2 Then n3 = n1: n1 = n2: n2 = n3
Label3.Caption = n1 & "+" & n2 & "="
result = n1 - n2
Case 3
op = "×"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
Label3.Caption = n1 & "+" & n2 & "="
result = n1 * n2
Case 4
op = "÷"
n2 = Int(Rnd * 9 + 1)
n1 = Int(Rnd * 10 + 0) * n2
Label3.Caption = n1 & "+" & n2 & "="
result = n1 / n2
End Select
End Sub

界面如下

主要的目的就是label3中产生一个式子,然后在TEXT1中输入运算结果,然后回车判断,如果是正确的就重新调用一次产生另一条式子,继续判断。可是我的代码不可以判断,要怎么改?我是初学者

最佳答案
  • 五星知识达人网友:老鼠爱大米
  • 2021-05-15 19:39

你的result是用来存放什么的???



在If Val(Text1) = result Then Call cs语句,当程序一开始时,result为空,而你没有赋值,所以永远为空,这够永远不运行,你后面CS子过程永远不会运行。


我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯