问题描述:
我能VB编写一个简易的计算机,但不知道从何入手,请各位指点一二!!!!!!
解析:
Option Explicit
Dim sz As Integer &闹衡察#39用来记录进行何种运算
Dim x As Single, y As Single &#39用来记录进行运算的两个数
&#39从第一个命令按钮到第十个是用来输入0至9十个数字的
Private Sub Command1_Click()
Text1.Text = Text1.Text &"1"
End Sub
Private Sub Command2_Click()
Text1.Text = Text1.Text &"2"
End Sub
Private Sub Command3_Click()
Text1.Text = Text1.Text &"3"
End Sub
Private Sub Command4_Click()
Text1.Text = Text1.Text &"4"
End Sub
Private Sub Command5_Click()
Text1.Text = Text1.Text &"5"
End Sub
Private Sub Command6_Click()
Text1.Text = Text1.Text &"6"
End Sub
Private Sub Command7_Click()
Text1.Text = Text1.Text &"7"
End Sub
Private Sub Command8_Click()
Text1.Text = Text1.Text &"8"
End Sub
Private Sub Command9_Click()
Text1.Text = Text1.Text &"9"
End Sub
Private Sub Command10_Click()
Text1.Text = Text1.Text &"0"
End Sub
Private Sub Command11_Click()
Text1.Text = Text1.Text &"." &#39输拦轮入小数点
End Sub
Private Sub Command12_Click()
x = CSng(Text1.Text) &#39将输入的数转液茄换成单精度型的
sz = 1 &#39设置即将进行的是加法运算
Text1.Text = "" &#39将文本框清空,以便输入第二个数
End Sub
Private Sub Command13_Click()
x = CSng(Text1.Text)
sz = 2
Text1.Text = ""
End Sub
Private Sub Command14_Click()
x = CSng(Text1.Text)
sz = 3
Text1.Text = ""
End Sub
Private Sub Command15_Click()
x = CSng(Text1.Text)
sz = 4
Text1.Text = ""
End Sub
Private Sub Command16_Click()
x = CSng(Text1.Text)
sz = 5
Text1.Text = ""
End Sub
Private Sub Command17_Click()
x = CSng(Text1.Text)
Text1.Text = Sqr(x) &#39因为求平方根只需一个运算对象,因此在此就给出结果
End Sub
Private Sub Command18_Click()
On Error GoTo ex &#39设置如果遇到错误就退出此过程
y = CSng(Text1.Text)
Select Case sz &#39根据sz的值来决定进行何种运算
Case 1
Text1.Text = x + y &#39进行加法运算并将结果显示在文本框中
Case 2
Text1.Text = x - y
Case 3
Text1.Text = x * y
Case 4
Text1.Text = x / y
Case 5
Text1.Text = x Mod y
End Select
ex:
End Sub
Private Sub Command19_Click()
Text1.Text = "" &#39将文本框清空,以便输入新的数字
End Sub
我做的,你看看,自己修改修改吧,附件传不上,就贴代码吧,控件就几个
2个command,2个label,1个text,1个timer。直接放就行
Dim sj As Integer, jia As Integer, bjia As Integer, total As IntegerPrivate Sub Command1_Click()
Call chou
Timer1.Enabled = True
Command2.Top = Command1.Top
Command2.Left = Command1.Left
Command1.Visible = False
Command2.Visible = True
End Sub
Private Sub Command2_Click()
If Val(Text1) = jia + bjia Then
total = total + 10
Else
total = total - 10
End If
Label2.Caption = "总分:" + Str(total)
Call chou
Text1 = ""
If total < 0 Then
MsgBox "分数低于0,GameOver!", vbExclamation, "游戏"
Timer1.Enabled = False
Command1.Visible = True
Command2.Visible = False
total = 0
Exit Sub
ElseIf total = 100 Then
MsgBox "分数满100分,游戏结束!", vbExclamation, "游戏"
Timer1.Enabled = False
total = 0
Exit Sub
End If
sj = 10
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000
Me.Caption = "小游戏"
Command1.Caption = "开始"
Command2.Caption = "确定"如颤
Command2.Visible = False
Text1 = ""
Label2.Caption = "总分:?"
Label1.Caption = "?+?"
sj = 10
End Sub
Sub chou()
Randomize
jia = Int(Rnd(1) * 89 + 10)
bjia = Int(Rnd(1) * 89 + 10)
Label1.Caption = Str(jia) + "+" + CStr(bjia) + "= ?"
Text1.SetFocus
End Sub
Private Sub Timer1_Timer()
If sj = 0 Then
total = total - 10
sj = 10
Call chou
End If
Me.Caption 键者= "小游戏 " + Str(sj) 稿橡薯+ "秒"
sj = sj - 1
End Sub
先在程序中加一个Label,名字应该符合竖滚陵VB程序控余戚件命名规范:lbl<名称>
再加一个Timer控件,名字也要符合命名规范
在窗体代码对话框中打备中入
Private Sub Form_Load()
On Error Resume Next
Me.Font = "Arial"
Me.FontSize = 24
Me.FontBold = True
<Timer控件名>.Enabled = True
<Timer控件名>.Interval = 1000
End Sub
'下列函数只能二选其一
'是时间显示
Private Sub <Timer控件名>_Timer()
On Error Resume Next
<Label控件名>.Caption = Time
End Sub
'是日期与时间显示
Private Sub <Timer控件名>_Timer()
On Error Resume Next
<Label控件名>.Caption = Now
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)