简易计算器
今年刚学VB,网上借鉴了一些,编了一个计算器,心中有小小的一点成就感,大家看看哦,给我提点建议哦,谢谢哦。Dim s1!, s3!, s2$, s4$, a%, b%, c%
Private Sub command1_click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
End Sub
Private Sub Command2_Click(Index As Integer)
s1 = Val(Text1.Text)
s2 = command2(Index).Caption
Text1.Text = ""
End Sub
Private Sub Command13_Click(Index As Integer)
s4 = Command13(Index).Caption
End Sub
Private Sub Command3_Click()
s3 = Val(Text1.Text)
Select Case s4
Case "cos"
Text1.Text = Cos(s3)
Case "1/x"
Text1.Text = 1 / s3
Case "rnd"
Text1.Text = Rnd(s3)
Case "sin"
Text1.Text = Sin(s3)
Case "tan"
Text1.Text = Tan(s3)
Case "exp"
Text1.Text = Exp(s3)
Case "abs"
Text1.Text = Abs(s3)
Case "log"
Text1.Text = Log(s3)
End Select
Select Case s2
Case "+"
Text1.Text = s1 + s3
Case "-"
Text1.Text = s1 - s3
Case "*"
Text1.Text = s1 * s3
Case "/"
Text1.Text = s1 / s3
End Select
End Sub
Private Sub Command200_Click()
Text1.Text = ""
End Sub
Private Sub Command6_Click()
If Text1.Text = "" Then
Exit Sub
End If
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End Sub
Private Sub Command5_Click()
Text1.Text = Text1.Text + "."
If (InStr(Text1.Text, ".") = 1) Then '第一位不能为小数
Text1.Text = ""
End If
If InStr(Text1.Text, ".") < Len(Text1.Text) Then
'防止出现两个小数点
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub
Private Sub Command7_Click()
If Left(Text1.Text, 1) <> "-" Then
Text1.Text = "-" & Text1.Text
Else
Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
End If
End Sub
Private Sub Command8_Click()
Text1.Text = Val(Text1.Text) * Val(Text1.Text)
End Sub
Private Sub Command9_Click()
Text1.Text = Text1.Text * Text1.Text * Text1.Text
End Sub
Private Sub Command10_Click()
Text1.Text = Sqr(Val(Text1.Text))
End Sub
Private Sub Command11_Click()
Text1.Text = Sqr(Val(Text1.Text))
End Sub
Private Sub Command30_Click()
Timer1.Enabled = True
Command30.Visible = False
Command31.Visible = True
a = Val(Text7.Text)
b = Val(Text6.Text)
c = Val(Text5.Text)
End Sub
Private Sub Command31_Click()
Timer1.Enabled = False
Command30.Visible = True
Command31.Visible = False
Command32.Visible = True
Command33.Visible = True
Command34.Visible = True
End Sub
Private Sub Command32_click()
If (a < 59) Then
a = a + 1
Else
a = 0
End If
Text7 = a
End Sub
Private Sub Command33_click()
If (b < 59) Then
b = b + 1
Else
b = 0
End If
Text6 = b
End Sub
Private Sub Command34_click()
If (c < 23) Then
c = c + 1
Else
c = 0
End If
Text5 = c
End Sub
Private Sub Timer1_Timer()
a = a + 1
If a > 59 Then
a = 0
b = b + 1
End If
If b > 59 Then
b = 0
c = c + 1
End If
If c > 23 Then
c = 0
b = 0
a = 0
End If
Text7 = a
Text6 = b
Text5 = c
End Sub
其计算器的蛮多功能都有了,自己也感觉要是再有括号,开立方,三角函数用度来表示,π的计算,LOG 2底,X的Y字方的话,就更好了,但是怎么搞也弄不出来