vb6.0编一个加减乘除四则运算的计算器主要思路和过程是怎样的?
vb6.0编一个加减乘除四则运算的计算器
主要思路和过程是怎样的?
vb6.0编一个加减乘除四则运算的计算器主要思路和过程是怎样的?
vb6.0编一个加减乘除四则运算的计算器
主要思路和过程是怎样的?
三个变量 分别存储 操作数 被操作数 和操作
根据对按钮的点击分别设置三个变量的值
创建一个窗口 画一个 文本框Text1
画一个按钮 Command1 设Index属性为0 粘贴如下代码
Option Explicit
Private dblOper1 As Double, dblOper2 As Double
Private lpType As String, b As Boolean
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 3, 7, 11, 15 '+-*/
lpType = Command1(Index).Caption
Me.Caption = CStr(dblOper1) & lpType
Text1.Text = ""
b = True
Case 12 '按下的是清屏
Text1.Text = ""
b = False
dblOper1 = 0
dblOper2 = 0
Case 14 '按下的是等于
Me.Caption = CStr(dblOper1) & lpType & CStr(dblOper2) & "="
Text1.Text = Calc()
b = False
dblOper1 = 0
dblOper2 = 0
Case Else '按下的是数字
Text1.Text = Text1.Text & Command1(Index).Caption
If b = False Then
dblOper1 = CDbl(Text1.Text)
Else
dblOper2 = CDbl(Text1.Text)
End If
End Select
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
Private Sub Form_Load()
Dim i As Integer
Me.Width = 4635
Me.Height = 2505
Text1.Left = 120
Text1.Top = 120
Text1.Width = 4275
Text1.Height = 315
Text1.Text = ""
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 = "/&q