Private
Declare
Function
FindWindow
Lib
"user32"
Alias
"FindWindowA"
(ByVal
lpClassName
As
String,
ByVal
lpWindowName
As
String)
As
Long
Private
Sub
Command5_Click()
Dim
lHwnd
As
Long
lHwnd
=
FindWindow(vbNullString,
"程序的Title或Caption")
If
lHwnd
<>
0
Then
MsgBox
"程序正在运行!"
End
If
End
Sub
向它发送指令:
AppActivate
"程序的Title或Caption"
SendKeys
"指令"
要启动程序:
Call
Shell("完整路径和程序名称.exe")
新建一个工程
Form1最上方添加一个Label1
然后在下方添加一个Label2,标题为:"请输入结果:"后面添加一个Text1(TextBox)
Label1下方添加一个Label3
Label3下方添加一个Label4
Label2下方添加两个按钮
Command1标题为 "下一题"
Command2标题为 "重来"
如图:
在Form1中添加代码:
'******************************************************************
Private Type OPER
i As Integer
k As Integer
a As Integer
b As Integer
p As String
c As Single
End Type
Dim OP() As OPER, n As Integer, r As Integer
Private Sub Command1_Click()
Text1.Text = ""
If n <9 Then
n = n + 1
Label3.Caption = OP(n).i + 1 &". " &OP(n).a &OP(n).p &OP(n).b &" = ?"
Text1.Text = ""
Else
Label4.Caption = "全部答完!正确率为:" &r * 10 &"%"
End If
End Sub
Private Sub Command2_Click()
ReDim OP(9)
For i = 0 To 9
Randomize
OP(i).i = i
OP(i).k = Int(Rnd * 4 + 1)
OP(i).a = Int(Rnd * 90 + 10)
OP(i).b = Int(Rnd * 90 + 10)
Select Case OP(i).k
Case 1
OP(i).c = OP(i).a + OP(i).b
OP(i).p = " + "
Case 2
OP(i).c = OP(i).a - OP(i).b
OP(i).p = " - "
Case 3
OP(i).c = OP(i).a * OP(i).b
OP(i).p = " * "
Case 4
OP(i).c = CLng((OP(i).a / OP(i).b) * 100) / 100
OP(i).p = " / "
End Select
Next
n = 0
r = 0
Label3.Caption = OP(0).i + 1 &". " &OP(0).a &OP(0).p &OP(0).b &" = ?"
Label4.Caption = ""
End Sub
Private Sub Form_Load()
Label1.Caption = "请根据下面的运算表达式计算出结果,并且填写在文本框中并回车(小数保留两位)。"
Label2.Caption = "请输入结果:"
Command1.Caption = "下一题"
Command2.Caption = "重来"
ReDim OP(9)
For i = 0 To 9
Randomize
OP(i).i = i
OP(i).k = Int(Rnd * 4 + 1)
OP(i).a = Int(Rnd * 90 + 10)
OP(i).b = Int(Rnd * 90 + 10)
Select Case OP(i).k
Case 1
OP(i).c = OP(i).a + OP(i).b
OP(i).p = " + "
Case 2
OP(i).c = OP(i).a - OP(i).b
OP(i).p = " - "
Case 3
OP(i).c = OP(i).a * OP(i).b
OP(i).p = " * "
Case 4
OP(i).c = CLng((OP(i).a / OP(i).b) * 100) / 100
OP(i).p = " / "
End Select
Next
n = 0
r = 0
Label3.Caption = OP(0).i + 1 &". " &OP(0).a &OP(0).p &OP(0).b &" = ?"
Label4.Caption = ""
Text1.Text = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Val(Text1.Text) = OP(n).c Then
Label4.Caption = "结果正确!" &OP(n).a &OP(n).p &OP(n).b &" = " &OP(n).c
Label4.ForeColor = &HFF
r = r + 1
Else
Label4.Caption = "结果错误! " &". " &OP(n).a &OP(n).p &OP(n).b &" = " &OP(n).c
Label4.ForeColor = &HFF0000
End If
Command1_Click
End If
End Sub
'*************************************************
运行效果如下:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)