主题:我要怎么修改我的这段程序?
ictest
[专家分:0] 发布于 2011-01-13 10:11:00
我给儿子编了一个20以内加减法口算程序,请问如何在按下command按钮后或者10秒倒计时结束后新建的文件中显示完整题目和答案?在那里修改?谢谢!
回复列表 (共7个回复)
沙发
ictest [专家分:0] 发布于 2011-01-13 10:18:00
Dim z, zj, tj, x, y
Private Sub Command1_Click()
Dim s As String
s = ""
Randomize
a = Int(20 * Rnd)
fh1 = IIf(Int(2 * Rnd) = 0, "+", "-")
fh2 = IIf(Int(2 * Rnd) = 0, "+", "-")
If Option1.Value = True Then
If fh1 = "-" Then
b = Int((a + 1) * Rnd) '在a以内取随机数,以免出现负数
Else
b = Int((20 - a + 1) * Rnd) '以免相加大于取值范围
End If
s = s & a & fh1 & b & "=" & Space(12 - Len(a) - Len(b))
Else
If fh1 = "-" Then
b = Int((a + 1) * Rnd) '在a以内取随机数,以免出现负数
If fh2 = "-" Then
c = Int((a - b + 1) * Rnd)
Else
c = Int((20 - (a - b) + 1) * Rnd)
End If
Else
b = Int((20 - a) * Rnd) '以免相加大于取值范围
If fh2 = "-" Then
c = Int((a + b + 1) * Rnd)
Else
c = Int((20 - (a + b) + 1) * Rnd)
End If
End If
s = s & a & fh1 & b & fh2 & c & "=" & Space(12 - Len(a) - Len(b) - Len(c))
End If
Label1.Caption = s
Command1.Caption = 10
Timer1.Enabled = True
Open App.Path & "/口算题.txt" For Append As #1
Print #1, s
Close #1
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Form1.Caption = 120
zj = 0
tj = 0
Command1.Caption = "开始"
Command2.Caption = "退出"
Option1.Caption = "加减"
Text1.Text = ""
Label1.Caption = ""
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Command1.Caption = Command1.Caption - 1
If Command1.Caption = 0 Then
Call Command1_Click
End If
End Sub
板凳
老大徒伤悲 [专家分:29120] 发布于 2011-01-13 11:37:00
新建的文件中显示完整题目和答案?
这“新建的文件”……
实在费解
3 楼
ictest [专家分:0] 发布于 2011-01-13 11:52:00
我给儿子编了一个20以内加减法口算程序,请问如何在按下“开始”按钮后或者10秒倒计时结束后会新建的一个文件,要求在文件中显示完整题目和答案。例如,运行程序后,按开始,界面上会出一道题(如1+1+1=),这时,程序会新建一个文本文件,内容是刚才出的题(1+1+1=),问题是,我希望文本里的内容是(1+1+1=3)。在哪里修改?谢谢!这么说版主明白了么?
4 楼
ictest [专家分:0] 发布于 2011-01-13 12:01:00
斑竹不愿意帮助我么?简单地说就是“希望在按下那个倒计时按钮(或者倒计时结束),生成文本文件里就立即显示出刚才的那道题目和答案。”我现在不会修改,只能在文本文件中显示刚才的题目。得不出答案。
5 楼
老大徒伤悲 [专家分:29120] 发布于 2011-01-13 15:47:00
我11:37问了你
到11:52你才回答,过了15分钟;
你到12:01就认为,我不愿意帮你,才过了9分钟!
更何况,我就得一直在这里看着你的问题不断刷新?也不做饭,也不吃饭,也不工作?
6 楼
老大徒伤悲 [专家分:29120] 发布于 2011-01-13 16:53:00
1、option不是这样用的;
2、缺少判定显示;
3、缺少成绩汇总。
对以上补充后,代码如下:
Const 范围 = 20
Dim 倒计时 As Integer
Dim 题目数 As Integer
Dim 正确数 As Integer
Dim 留空数 As Integer
Dim 错误数 As Integer
Dim 答案 As Integer
Private Sub Command1_Click()
If Command1.Caption = "开始(&Begin)" Or Command1.Caption = "下一题(&Next)" Then
新题目
Else
判定答案
End If
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Load()
Form1.Caption = 120
zj = 0
tj = 0
Command1.Caption = "开始(&Begin)"
Command2.Caption = "退出(&Exit)"
Option1.Caption = "连续运算(&Mixed)"
Option2.Caption = "单一运算(&Simple)"
Option2 = True
Text1.Text = ""
Label1.Caption = ""
Label2 = ""
Label3 = ""
Timer1.Enabled = False
Timer1.Interval = 1000
题目数 = 0
正确数 = 0
错误数 = 0
留空数 = 0
End Sub
Private Sub Timer1_Timer()
倒计时 = 倒计时 - 1
Label2 = 倒计时
If 倒计时 = 0 Then 判定答案
End Sub
Private Sub 新题目()
Dim a As Integer, b As Integer, c As Integer
Randomize
a = Int(范围 * Rnd)
b = Int(范围 * Rnd)
If Option1.Value = True Then
fh1 = IIf(Int(2 * Rnd) = 0, "+", "-")
fh2 = IIf(Int(2 * Rnd) = 0, "+", "-")
If fh1 = "-" Then
b = Int((a + 1) * Rnd) '在a以内取随机数,以免出现负数
答案 = a - b
If fh2 = "-" Then
c = Int((a - b + 1) * Rnd)
答案 = 答案 - c
Else
c = Int((20 - (a - b) + 1) * Rnd)
答案 = 答案 + c
End If
Else
b = Int((20 - a) * Rnd) '以免相加大于取值范围
答案 = a + b
If fh2 = "-" Then
c = Int((a + b + 1) * Rnd)
答案 = 答案 - c
Else
c = Int((20 - (a + b) + 1) * Rnd)
答案 = 答案 + c
End If
End If
Label1.Caption = a & fh1 & b & fh2 & c & "="
Else
If a + b > 范围 Then
If a < b Then 交换 a, b
运算符 = "-"
答案 = a - b
Else
运算符 = "+"
答案 = a + b
End If
Label1.Caption = a & 运算符 & b & "="
End If
Command1.Caption = "确定(&Ok)"
倒计时 = 10
Label2 = 倒计时
题目数 = 题目数 + 1
Text1.Locked = False
Text1 = ""
End Sub
Private Sub 判定答案()
If Text1 = "" Then
Text1 = "未完成!"
留空数 = 留空数 + 1
ElseIf 答案 = CInt(Trim(Text1)) Then
Text1 = Text1 & " √"
正确数 = 正确数 + 1
Else
Text1 = Text1 & " ×"
错误数 = 错误数 + 1
End If
Text1.Locked = True
Label3 = "目前做过题目:" & 题目数 & "个"
Label3 = Label3 & vbCrLf & " 正确:" & 正确数 & "个"
Label3 = Label3 & vbCrLf & " 错误:" & 错误数 & "个"
Label3 = Label3 & vbCrLf & " 没有做:" & 留空数 & "个"
Command1.Caption = "下一题(&Next)"
End Sub
Private Sub 交换(x As Integer, y As Integer)
t = x
x = y
y = t
End Sub
7 楼
孙瑞 [专家分:590] 发布于 2011-01-29 09:07:00
http://bbs.pfan.cn/post-242771.html
以上是我的加减乘除法考试工具。含源代码。你可以看看。
我来回复