Private dblOper1 As Double, dblOper2 As Double
Private lpType As String, b As Boolean
Private Sub text_Change(Index As Integer)
Dim i As Integer
Me.Width = 4635
Me.Height = 2505
Text.Left = 120
Text.Top = 120
Text.Width = 4275
Text.Height = 315
Text.Text = ""
End Sub
Public Function Calc() As String
Select Case lpType
Case "+"
Calc = CStr(dblOper1 + dblOper2)
Case "-"
Calc = CStr(dblOper1 - dblOper2)
Case "*"
Calc = CStr(dblOper1 * dblOper2)
Case "/"
Calc = CStr(dblOper1 / dblOper2)
End Select
End Function
Option Explicit
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 3, 7, 11, 15 '+-*/
lpType = Command1(Index).Caption
Me.Caption = CStr(dblOper1) & lpType
Text.Text = ""
b = True
Case 12 '按下的是清屏
Text.Text = ""
b = False
dblOper1 = 0
dblOper2 = 0
Case 14 '按下的是等于
Me.Caption = CStr(dblOper1) & lpType & CStr(dblOper2) & "="
Text.Text = Calc()
b = False
dblOper1 = 0
dblOper2 = 0
Case Else '按下的是数字
Text.Text = "text.text&Command1(Index).Caption"
If b = False Then
dblOper1 = CDbl(Text.Text)
Else
dblOper2 = CDbl(Text.Text)
End If
End Select
End Sub
Private Sub Form_Load()
Dim i As Integer
Me.Width = 4635
Me.Height = 2505
Command1(0).Left = 120
Command1(0).Top = 480
Command1(0).Width = 1035
Command1(0).Height = 315
For i = 1 To 15
Load Command1(i)
If (i Mod 4) <> 0 Then
Command1(i).Left = Command1(i - 1).Left + 1080
Command1(i).Top = Command1(i - 1).Top
Else
Command1(i).Left = Command1(0).Left
Command1(i).Top = Command1(i - 4).Top + 360
End If
Command1(i).Visible = True
Next i
Command1(0).Caption = "1"
Command1(1).Caption = "2"
Command1(2).Caption = "3"
Command1(3).Caption = "+"
Command1(4).Caption = "4"
Command1(5).Caption = "5"
Command1(6).Caption = "6"
Command1(7).Caption = "-"
Command1(8).Caption = "7"
Command1(9).Caption = "8"
Command1(10).Caption = "9"
Command1(11).Caption = "*"
Command1(12).Caption = "C"
Command1(13).Caption = "0"
Command1(14).Caption = "="
Command1(15).Caption = "/"
End Sub
Private lpType As String, b As Boolean
Private Sub text_Change(Index As Integer)
Dim i As Integer
Me.Width = 4635
Me.Height = 2505
Text.Left = 120
Text.Top = 120
Text.Width = 4275
Text.Height = 315
Text.Text = ""
End Sub
Public Function Calc() As String
Select Case lpType
Case "+"
Calc = CStr(dblOper1 + dblOper2)
Case "-"
Calc = CStr(dblOper1 - dblOper2)
Case "*"
Calc = CStr(dblOper1 * dblOper2)
Case "/"
Calc = CStr(dblOper1 / dblOper2)
End Select
End Function
Option Explicit
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 3, 7, 11, 15 '+-*/
lpType = Command1(Index).Caption
Me.Caption = CStr(dblOper1) & lpType
Text.Text = ""
b = True
Case 12 '按下的是清屏
Text.Text = ""
b = False
dblOper1 = 0
dblOper2 = 0
Case 14 '按下的是等于
Me.Caption = CStr(dblOper1) & lpType & CStr(dblOper2) & "="
Text.Text = Calc()
b = False
dblOper1 = 0
dblOper2 = 0
Case Else '按下的是数字
Text.Text = "text.text&Command1(Index).Caption"
If b = False Then
dblOper1 = CDbl(Text.Text)
Else
dblOper2 = CDbl(Text.Text)
End If
End Select
End Sub
Private Sub Form_Load()
Dim i As Integer
Me.Width = 4635
Me.Height = 2505
Command1(0).Left = 120
Command1(0).Top = 480
Command1(0).Width = 1035
Command1(0).Height = 315
For i = 1 To 15
Load Command1(i)
If (i Mod 4) <> 0 Then
Command1(i).Left = Command1(i - 1).Left + 1080
Command1(i).Top = Command1(i - 1).Top
Else
Command1(i).Left = Command1(0).Left
Command1(i).Top = Command1(i - 4).Top + 360
End If
Command1(i).Visible = True
Next i
Command1(0).Caption = "1"
Command1(1).Caption = "2"
Command1(2).Caption = "3"
Command1(3).Caption = "+"
Command1(4).Caption = "4"
Command1(5).Caption = "5"
Command1(6).Caption = "6"
Command1(7).Caption = "-"
Command1(8).Caption = "7"
Command1(9).Caption = "8"
Command1(10).Caption = "9"
Command1(11).Caption = "*"
Command1(12).Caption = "C"
Command1(13).Caption = "0"
Command1(14).Caption = "="
Command1(15).Caption = "/"
End Sub