我做了一个简单型的,为简化代码用到了空间数组,希望你能看懂!
'-----------------------------------------------------------------------------------------
'程序:VB 简单计算器
'作者:王峰
'QQ:447201162
'日期:2010年1月16日
'博客:447201162.blog.163.com
'-----------------------------------------------------------------------------------------
Dim XS
Dim XSF
Dim SHU1
Dim CX
Dim XSD
Dim M
Dim DY
Dim SHU2
Private Sub Command1_Click(Index As Integer)
If XS = 1 Then
XS = 0
Text1 = Index
CX = 1
XSD = 0
Else
Text1 = Text1 & Index
End If
If DY = 1 Then XSF = 0
End Sub
Private Sub Command10_Click()
If DY = 0 Then SHU2 = Text1
If XSF = 1 Then
Text1 = Val(Text1) + Val(SHU1)
XS = 1
End If
If XSF = 2 Then
If DY = 0 Then Text1 = Val(SHU1) - Val(Text1) Else Text1 = Val(Text1) - Val(SHU1)
XS = 1
End If
If XSF = 3 Then
Text1 = Val(Text1) * Val(SHU1)
XS = 1
End If
If XSF = 4 Then
If Val(Text1) = "0" Then
Text1 = "除数不能为零。"
Else
If DY = 0 Then Text1 = Val(SHU1) / Val(Text1) Else Text1 = Val(Text1) / Val(SHU1)
End If
XS = 1
End If
If DY = 0 Then SHU1 = SHU2
DY = 1
CX = 0
XS = 1
End Sub
Private Sub Command11_Click()
M = M + Val(Text1)
XS = 1
If M <> 0 Then Label1.Caption = "M" Else Label1.Caption = ""
End Sub
Private Sub Command12_Click()
M = M - Val(Text1)
XS = 1
If M <> 0 Then Label1.Caption = "M" Else Label1.Caption = ""
End Sub
Private Sub Command13_Click()
Text1 = M
CX = 1
XS = 1
End Sub
Private Sub Command14_Click()
Label1.Caption = ""
M = 0
End Sub
Private Sub Command15_Click()
Text1 = 3.14159265358979
XS = 0
End Sub
Private Sub Command2_Click()
If DY = 1 Then
Text1 = "0."
XSD = 1
End If
If XSD <> 1 Then
Text1 = Text1 & "."
XSD = 1
End If
If Text1 = "." Then Text1 = "0."
XS = 0
End Sub
Private Sub Command3_Click()
Text1 = 0 - Text1
End Sub
Private Sub Command4_Click()
Text1 = ""
XS = 0
XSF = 0
SHU1 = 0
CX = 0
XSD = 0
DY = 0
SHU2 = 0
End Sub
Private Sub Command5_Click()
Text1 = ""
XS = 0
XSF = 0
SHU1 = 0
CX = 0
XSD = 0
DY = 0
SHU2 = 0
End Sub
Private Sub Command6_Click(Index As Integer)
If XSF <> 1 And XSF <> 2 And XSF <> 3 And XSF <> 4 Then
SHU1 = Text1
GoTo 1
End If
If DY = 1 Then GoTo 2
If CX = 0 Then GoTo 1
If Index + 1 = 1 Then
Text1 = Val(Text1) + Val(SHU1)
XS = 1
End If
If Index + 1 = 2 Then
Text1 = Val(SHU1) - Val(Text1)
XS = 1
End If
If Index + 1 = 3 Then
Text1 = Val(Text1) * Val(SHU1)
XS = 1
End If
If Index + 1 = 4 Then
Text1 = Val(SHU1) / Val(Text1)
XS = 1
End If
SHU1 = Text1
CX = 0
Exit Sub
2:
SHU1 = Text1
1:
DY = 0
XS = 1
XSF = Index + 1
End Sub
Private Sub Command7_Click()
Text1 = Sqr(Text1)
XS = 1
End Sub
Private Sub Command8_Click()
Text1 = Val(Text1) * Val(Text1)
XS = 1
End Sub
Private Sub Command9_Click()
Text1 = Val(Text1) * Val(Text1) * Val(Text1)
XS = 1
End Sub
Dim a As Double
Dim b As String
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
End Sub
Private Sub Command2_Click()
If InStr(Text1.Text, ".") = 0 Then
Text1.Text = Text1.Text & Command2.Caption
End If
If Left(Text1.Text, 1) = "." Then
Text1.Text = "0" & Text1.Text
End If
End Sub
Private Sub Command3_Click()
If Text1.Text = "" Then
Text1.Text = a
Exit Sub
End If
Select Case b
Case "+"
a = a + Val(Text1.Text)
Case "-"
a = a - Val(Text1.Text)
Case "X"
a = a * Val(Text1.Text)
Case "÷"
If Text1.Text = "0" Then
Text1.Text = "0"
Else
a = a / Val(Text1.Text)
End If
End Select
Text1.Text = a
End Sub
Private Sub Command4_Click(Index As Integer)
If Text1.Text = "" Then
b = Command4(Index).Caption
Exit Sub
End If
If b = "" Then
a = Text1.Text
b = Command4(Index).Caption
Text1.Text = ""
Exit Sub
End If
Select Case b
Case "+"
a = a + Val(Text1.Text)
Case "-"
a = a - Val(Text1.Text)
Case "X"
a = a * Val(Text1.Text)
Case "÷"
If Text1.Text = "0" Then
Text1.Text = "0"
Else
a = a / Val(Text1.Text)
End If
End Select
Text1.Text = ""
b = Command4(Index).Caption
Text2.Text = a
End Sub
Private Sub Form_Load()
b = ""
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr("1234567890.", Chr(KeyAscii)) = 0 Then KeyAscii = 0
If Chr(KeyAscii) = "." And InStr(Text1.Text, ".") <> 0 Then KeyAscii = 0
End Sub
1块
给你一个,
百度上有免费的。
10026.3668.33218.49776.211.vbm 最佳啊!!!!