永发信息网

我的这段VB代码怎么会这样

答案:4  悬赏:0  手机版
解决时间 2021-05-17 04:03
  • 提问者网友:龅牙恐龙妹
  • 2021-05-16 10:58

Private Sub Command2_Click() '检查答案的正误
If Val(Text1) = result1 Then
Label14 = "√"
Else
Label14 = "×"
End If
If Val(Text2) = result2 Then
Label15 = "√"
Else
Label15 = "×"
End If
If Val(Text3) = result3 Then
Label16 = "√"
Else
Label16 = "×"
End If
If Val(Text4) = result4 Then
Label17 = "√"
Else
Label17 = "×"
End If
If Val(Text5) = result5 Then
Label18 = "√"
Else
Label18 = "×"
End If
If Val(Text6) = result6 Then
Label19 = "√"
Else
Label19 = "×"
End If
If Val(Text7) = result7 Then
Label20 = "√"
Else
Label20 = "×"
End If
If Val(Text8) = result8 Then
Label21 = "√"
Else
Label21 = "×"
End If
If Val(Text9) = result9 Then
Label22 = "√"
Else
Label22 = "×"
End If
If Val(Text10) = result10 Then
Label23 = "√"
Else
Label23 = "×"
End If
If Val(Text11) = result11 Then
Label24 = "√"
Else
Label24 = "×"
End If
If Val(Text12) = result12 Then
Label25 = "√"
Else
Label25 = "×"
End If
End Sub

Private Sub Command3_Click() '开始新一轮的练习
Call Command3_Click
End Sub

Private Sub Command4_Click()
Call CCCS1
Label2 = n1 & B & n2 & "="
Call JJCS1
Label3 = n1 & B & n2 & "="
Call JJCS2
Label4 = n1 & B & n2 & "="
Call CCCS2
Label5 = n1 & B & n2 & "="
Call JJCS3
Label6 = n1 & B & n2 & "="
Call CCCS3
Label7 = n1 & B & n2 & "="
Call JJCS4
Label8 = n1 & B & n2 & "="
Call JJCS5
Label9 = n1 & B & n2 & "="
Call CCCS4
Label10 = n1 & B & n2 & "="
Call JJCS6
Label11 = n1 & B & n2 & "="
Call CCCS5
Label12 = n1 & B & n2 & "="
Call CCCS6
Label13 = n1 & B & n2 & "="
End Sub
Sub CCCS1()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "+"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result1 = n1 + n2
Case 2
B = "-"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
If n1 < n2 Then n3 = n1: n1 = n2: n2 = n3
result1 = n1 - n2
End Select
End Sub
Sub JJCS1()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "×"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result2 = n1 * n2
Case 2
B = "÷"
n2 = Int(Rnd * 9 + 1)
n1 = Int(Rnd * 10 + 0) * n2
result2 = n1 / n2
End Select
End Sub

Sub JJCS2()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "+"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result3 = n1 + n2
Case 2
B = "-"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
If n1 < n2 Then n3 = n1: n1 = n2: n2 = n3
result3 = n1 - n2
End Select
End Sub
Sub CCCS2()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "×"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result4 = n1 * n2
Case 2
B = "÷"
n2 = Int(Rnd * 9 + 1)
n1 = Int(Rnd * 10 + 0) * n2
result4 = n1 / n2
End Select
End Sub
Sub JJCS3()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "+"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result5 = n1 + n2
Case 2
B = "-"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
If n1 < n2 Then n3 = n1: n1 = n2: n2 = n3
result5 = n1 - n2
End Select
End Sub
Sub CCCS3()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "×"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result6 = n1 * n2
Case 2
B = "÷"
n2 = Int(Rnd * 9 + 1)
n1 = Int(Rnd * 10 + 0) * n2
result6 = n1 / n2
End Select
End Sub
Sub JJCS4()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "+"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result7 = n1 + n2
Case 2
B = "-"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
If n1 < n2 Then n3 = n1: n1 = n2: n2 = n3
result7 = n1 - n2
End Select
End Sub
Sub JJCS5()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "×"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result8 = n1 * n2
Case 2
B = "÷"
n2 = Int(Rnd * 9 + 1)
n1 = Int(Rnd * 10 + 0) * n2
result8 = n1 / n2
End Select
End Sub
Sub CCCS4()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "+"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result9 = n1 + n2
Case 2
B = "-"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
If n1 < n2 Then n3 = n1: n1 = n2: n2 = n3
result9 = n1 - n2
End Select
End Sub
Sub JJCS6()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "×"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result10 = n1 * n2
Case 2
B = "÷"
n2 = Int(Rnd * 9 + 1)
n1 = Int(Rnd * 10 + 0) * n2
result10 = n1 / n2
End Select
End Sub
Sub CCCS5()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "+"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result11 = n1 + n2
Case 2
B = "-"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
If n1 < n2 Then n3 = n1: n1 = n2: n2 = n3
result11 = n1 - n2
End Select
End Sub
Sub CCCS6()
Randomize
A = Int(Rnd * 2 + 1)
Select Case A
Case 1
B = "×"
n1 = Int(Rnd * 10 + 1)
n2 = Int(Rnd * 10 + 1)
result12 = n1 * n2
Case 2
B = "÷"
n2 = Int(Rnd * 9 + 1)
n1 = Int(Rnd * 10 + 0) * n2
result12 = n1 / n2
End Select
End Sub

运行后的界面就成了这样了

最佳答案
  • 五星知识达人网友:怙棘
  • 2021-05-16 12:04

你的Form_load过程贴出来看看啊。

全部回答
  • 1楼网友:山河有幸埋战骨
  • 2021-05-16 14:36

在通用声明里先定义n1,n2 B 等一些变量

Dim N1,N2,B

另个你还有个错误:

Private Sub Command3_Click() '开始新一轮的练习 Call Command3_Click ‘怎么会自己调用自己呀???????? End Sub

  • 2楼网友:爱难随人意
  • 2021-05-16 13:26

Call CCCS1 Label2 = n1 & B & n2 & "=" 检查下n1,n2,B赋值的函数。 例如CCCS1...................等

label2显示就一个等号。说明赋值函数有问题。打断点调试吧。

  • 3楼网友:掌灯师
  • 2021-05-16 12:35

你的labelxx直接就赋值啊?

应该用labelxx.caption,文本输入框是Textxx.Text来访问其中的字符串的。

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