如题所述
'下面是窗体代码,在 VB6.0 调试通过:
'在窗体放置 8 个控件:
'
Command1、Text1、Label1、Label2、Label3、Option1、Option2、Option3
'所有控件全部采用默认设置,可随意放置。复制下面的代码,粘贴到窗体的代码窗口,运行即可。
'本人原创,转载请注明来源:http://hi.baidu.com/100bd/blog/item/d935e1cbfee4b64af31fe760.html
Dim ctS1 As Long, ctS2 As Long, ctS As Long
Dim ctZong As Long, ctDui As Long
Private Sub Form_Load()
'设置基本参数和控件位置
Dim H1 As Single
Me.KeyPreview =
True: Me.Caption = "加减乘除的口算练习"
Label1.Font.Size = 12:
Label2.Font.Size = 24: Label3.Font.Size = 12
Label1.AutoSize = True:
Label2.AutoSize = True: Label3.AutoSize = True
Option1.Caption = "加减":
Option2.Caption = "乘除": Option3.Caption = "加减乘除"
H1 =
Label1.Height
Label1.Move H1 * 0.8, H1 '提示
Label2.Move H1 * 0.8, H1 * 3 '试题
Label3.Move H1 * 0.8, H1 * 6 '成绩
Label3.Caption = "": Label3.ForeColor =
&HFF
Option1.Move H1 * 18, H1 * 3, H1 * 8, H1
Option2.Move H1 * 18, H1 * 4.5, H1 * 8, H1
Option3.Move H1 * 18, H1 * 6,
H1 * 8, H1
Option1.Value = True
Command1.Caption =
"下一题(Enter)"
Command1.Move H1, H1 * 8.5, H1 * 8, H1 * 2
Text1.Font.Size = Label2.Font.Size: Text1.MaxLength = 9
End
Sub
Private Sub Form_Activate()
Call Command1_Click
End
Sub
Private Sub Command1_Click()
Dim S As Long, nStr As String, nMax
As Long, mMax As Long, H1 As Single
Randomize
If
Option1.Value Then
S = Int(Int(Rnd * 2))
Else
If
Option2.Value Then S = 2 + Int(Int(Rnd * 2)) Else S = Int(Int(Rnd * 4))
End If
nMax = 100 '******
100以内加减乘除,可修改
mMax = nMax ^ 0.5 '乘除法不能大于 nMax
的开方
Get1:
Randomize: ctS1 = Int(Rnd * nMax)
Randomize:
ctS2 = Int(Rnd * nMax)
Select Case S
Case 0: ctS = ctS1 +
ctS2: nStr = "+"
Case 1: ctS = ctS1 + ctS2: nStr = "-"
Case
2: ctS = ctS1 * ctS2: nStr = "×"
Case Else: ctS = ctS1 * ctS2: nStr =
"÷"
End Select
If S > 1 And (ctS1 >= mMax Or ctS2 >=
mMax) Then GoTo Get1 '乘除法
If ctS > nMax
Then GoTo Get1
If ctS2 = 0 And S = 3 Then GoTo Get1 '0 不能做除数
If S = 1 Or S = 3 Then '减法和除法,交换数字
S = ctS: ctS = ctS1: ctS1 = S
End If
Label1.Caption = "请输入答案,按回车表示输入结束:"
Label2.Caption =
ctS1 & nStr & ctS2 & "=" '&
ctS
'文本框与 Label2 对齐
H1 =
Label2.Height
Text1.Move Label2.Left + Label2.Width + H1 * 0.2,
Label2.Top - 2 * Me.ScaleY(1, 3, Me.ScaleMode), H1 * 3, H1
Text1.Text =
"": Text1.Enabled = True: Text1.SetFocus
Command1.Enabled = False
Label3.Caption = "当前第 " & ctZong + 1 & " 题" & vbCrLf & "已做"
& ctZong & "题,对" & ctDui & "题"
End Sub
Private Sub
Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub '删除键除外
If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii
= 0 '只能输入数字
End Sub
Private Sub
Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> 13
Then Exit Sub
If Text1.Enabled Then '判断对否
If Text1.Text = "" Then
MsgBox
"必须输入得数!", vbInformation, Me.Caption
Exit Sub
End
If
Command1.Enabled = True
ctZong = ctZong + 1
If
Val(Text1.Text) = ctS Then
ctDui = ctDui + 1
Label3.Caption = "√ 正确" & vbCrLf & "已做" & ctZong & "题,对" &
ctDui & "题"
Else
Label3.Caption = "× 错误。答案是:" &
ctS & vbCrLf & "已做" & ctZong & "题,对" & ctDui &
"题"
End If
Text1.Enabled = False
Label1.Caption =
"继续下一题,单击按钮,或按回车键:"
Else
Call Command1_Click '出下一题
End If
End Sub追问
'在窗体放置 8 个控件:
'
Command1、Text1、Label1、Label2、Label3、Option1、Option2、Option3
'所有控件全部采用默认设置,可随意放置。复制下面的代码,粘贴到窗体的代码窗口,运行即可。
'本人原创,转载请注明来源:http://hi.baidu.com/100bd/blog/item/d935e1cbfee4b64af31fe760.html
Dim ctS1 As Long, ctS2 As Long, ctS As Long
Dim ctZong As Long, ctDui As Long
Private Sub Form_Load()
'设置基本参数和控件位置
Dim H1 As Single
Me.KeyPreview =
True: Me.Caption = "加减乘除的口算练习"
Label1.Font.Size = 12:
Label2.Font.Size = 24: Label3.Font.Size = 12
Label1.AutoSize = True:
Label2.AutoSize = True: Label3.AutoSize = True
Option1.Caption = "加减":
Option2.Caption = "乘除": Option3.Caption = "加减乘除"
H1 =
Label1.Height
Label1.Move H1 * 0.8, H1 '提示
Label2.Move H1 * 0.8, H1 * 3 '试题
Label3.Move H1 * 0.8, H1 * 6 '成绩
Label3.Caption = "": Label3.ForeColor =
&HFF
Option1.Move H1 * 18, H1 * 3, H1 * 8, H1
Option2.Move H1 * 18, H1 * 4.5, H1 * 8, H1
Option3.Move H1 * 18, H1 * 6,
H1 * 8, H1
Option1.Value = True
Command1.Caption =
"下一题(Enter)"
Command1.Move H1, H1 * 8.5, H1 * 8, H1 * 2
Text1.Font.Size = Label2.Font.Size: Text1.MaxLength = 9
End
Sub
Private Sub Form_Activate()
Call Command1_Click
End
Sub
Private Sub Command1_Click()
Dim S As Long, nStr As String, nMax
As Long, mMax As Long, H1 As Single
Randomize
If
Option1.Value Then
S = Int(Int(Rnd * 2))
Else
If
Option2.Value Then S = 2 + Int(Int(Rnd * 2)) Else S = Int(Int(Rnd * 4))
End If
nMax = 100 '******
100以内加减乘除,可修改
mMax = nMax ^ 0.5 '乘除法不能大于 nMax
的开方
Get1:
Randomize: ctS1 = Int(Rnd * nMax)
Randomize:
ctS2 = Int(Rnd * nMax)
Select Case S
Case 0: ctS = ctS1 +
ctS2: nStr = "+"
Case 1: ctS = ctS1 + ctS2: nStr = "-"
Case
2: ctS = ctS1 * ctS2: nStr = "×"
Case Else: ctS = ctS1 * ctS2: nStr =
"÷"
End Select
If S > 1 And (ctS1 >= mMax Or ctS2 >=
mMax) Then GoTo Get1 '乘除法
If ctS > nMax
Then GoTo Get1
If ctS2 = 0 And S = 3 Then GoTo Get1 '0 不能做除数
If S = 1 Or S = 3 Then '减法和除法,交换数字
S = ctS: ctS = ctS1: ctS1 = S
End If
Label1.Caption = "请输入答案,按回车表示输入结束:"
Label2.Caption =
ctS1 & nStr & ctS2 & "=" '&
ctS
'文本框与 Label2 对齐
H1 =
Label2.Height
Text1.Move Label2.Left + Label2.Width + H1 * 0.2,
Label2.Top - 2 * Me.ScaleY(1, 3, Me.ScaleMode), H1 * 3, H1
Text1.Text =
"": Text1.Enabled = True: Text1.SetFocus
Command1.Enabled = False
Label3.Caption = "当前第 " & ctZong + 1 & " 题" & vbCrLf & "已做"
& ctZong & "题,对" & ctDui & "题"
End Sub
Private Sub
Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub '删除键除外
If Not IsNumeric(Chr(KeyAscii)) Then KeyAscii
= 0 '只能输入数字
End Sub
Private Sub
Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode <> 13
Then Exit Sub
If Text1.Enabled Then '判断对否
If Text1.Text = "" Then
MsgBox
"必须输入得数!", vbInformation, Me.Caption
Exit Sub
End
If
Command1.Enabled = True
ctZong = ctZong + 1
If
Val(Text1.Text) = ctS Then
ctDui = ctDui + 1
Label3.Caption = "√ 正确" & vbCrLf & "已做" & ctZong & "题,对" &
ctDui & "题"
Else
Label3.Caption = "× 错误。答案是:" &
ctS & vbCrLf & "已做" & ctZong & "题,对" & ctDui &
"题"
End If
Text1.Enabled = False
Label1.Caption =
"继续下一题,单击按钮,或按回车键:"
Else
Call Command1_Click '出下一题
End If
End Sub追问
总是提示GOTO get1 未定义,我在倒数第二条加入get1: 也没有用,怎么办?谢谢
追答没有啊,我试了下。点开链接,复制代码到工程。
在窗体放置 8 个控件:
Command1、Text1、Label1、Label2、Label3、Option1、Option2、Option3
所有控件全部采用默认设置,可随意放置。
运行,不出错的。你再试试
可以随时查看做题情况,哪些题做了,哪些没有做。
对结果进行简单分析,如剪发题错的多,提示用户应对减法多加练习;
参考资料:http://hi.baidu.com/100bd/blog/item/d935e1cbfee4b64af31fe760.html
温馨提示:答案为网友推荐,仅供参考
第1个回答 2012-11-29
Dim N As Single
Private Sub Command1_Click()
Dim c As String
Dim a, b As Integer
Randomize Timer '改变随机数种子
c = Int(3 * Rnd) '符号 C为 0加法 1减法 2乘法 3除法
a = Int(99 * Rnd + 1) '
b = Int(99 * Rnd + 1) '
Select Case c
Case 0 '加
N = a + b
c = "+"
Case 1 '减
N = a - b
c = "-"
Case 2 '乘
N = a * b
c = "×"
Case 3 '除
N = a / b
c = "÷"
End Select
Label1.Caption = a & c & b & "="
End Sub本回答被网友采纳
Private Sub Command1_Click()
Dim c As String
Dim a, b As Integer
Randomize Timer '改变随机数种子
c = Int(3 * Rnd) '符号 C为 0加法 1减法 2乘法 3除法
a = Int(99 * Rnd + 1) '
b = Int(99 * Rnd + 1) '
Select Case c
Case 0 '加
N = a + b
c = "+"
Case 1 '减
N = a - b
c = "-"
Case 2 '乘
N = a * b
c = "×"
Case 3 '除
N = a / b
c = "÷"
End Select
Label1.Caption = a & c & b & "="
End Sub本回答被网友采纳