⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 这是一个用VB编写的很实用的计算器,能够实现数据的加减乘除,乘方,开放,操作简单,而且程序条理清晰,希望大家指点
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "简易计算器"
   ClientHeight    =   6015
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   6315
   LinkTopic       =   "Form1"
   ScaleHeight     =   6015
   ScaleWidth      =   6315
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame1 
      Caption         =   "计算器"
      Height          =   5655
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   6015
      Begin VB.CommandButton Operator 
         Caption         =   "="
         Height          =   495
         Index           =   19
         Left            =   4920
         TabIndex        =   25
         Top             =   3960
         Width           =   615
      End
      Begin VB.CommandButton Percent 
         Caption         =   "%"
         Height          =   495
         Index           =   18
         Left            =   4920
         TabIndex        =   24
         Top             =   3120
         Width           =   615
      End
      Begin VB.CommandButton Countdown 
         Caption         =   "1/x"
         Height          =   495
         Index           =   17
         Left            =   4920
         TabIndex        =   23
         Top             =   2280
         Width           =   615
      End
      Begin VB.CommandButton Sqrt 
         Caption         =   "sqrt"
         Height          =   495
         Index           =   16
         Left            =   4920
         TabIndex        =   22
         Top             =   1440
         Width           =   615
      End
      Begin VB.CommandButton Operator 
         Caption         =   "+"
         Height          =   495
         Index           =   15
         Left            =   3720
         TabIndex        =   21
         Top             =   3960
         Width           =   615
      End
      Begin VB.CommandButton Operator 
         Caption         =   "-"
         Height          =   495
         Index           =   14
         Left            =   3720
         TabIndex        =   20
         Top             =   3120
         Width           =   615
      End
      Begin VB.CommandButton Operator 
         Caption         =   "*"
         Height          =   495
         Index           =   13
         Left            =   3720
         TabIndex        =   19
         Top             =   2280
         Width           =   615
      End
      Begin VB.CommandButton Operator 
         Caption         =   "/"
         Height          =   495
         Index           =   12
         Left            =   3720
         TabIndex        =   18
         Top             =   1440
         Width           =   615
      End
      Begin VB.CommandButton Decimal 
         Caption         =   "."
         Height          =   495
         Index           =   11
         Left            =   2520
         TabIndex        =   17
         Top             =   3960
         Width           =   615
      End
      Begin VB.CommandButton sgn 
         Caption         =   "+/-"
         Height          =   495
         Index           =   10
         Left            =   1440
         TabIndex        =   16
         Top             =   3960
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "0"
         Height          =   495
         Index           =   9
         Left            =   360
         TabIndex        =   15
         Top             =   3960
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "3"
         Height          =   495
         Index           =   8
         Left            =   2520
         TabIndex        =   14
         Top             =   3120
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "2"
         Height          =   495
         Index           =   7
         Left            =   1440
         TabIndex        =   13
         Top             =   3120
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "1"
         Height          =   495
         Index           =   6
         Left            =   360
         TabIndex        =   12
         Top             =   3120
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "6"
         Height          =   495
         Index           =   5
         Left            =   2520
         TabIndex        =   11
         Top             =   2280
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "5"
         Height          =   495
         Index           =   4
         Left            =   1440
         TabIndex        =   10
         Top             =   2280
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "4"
         Height          =   495
         Index           =   3
         Left            =   360
         TabIndex        =   9
         Top             =   2280
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "9"
         Height          =   495
         Index           =   2
         Left            =   2520
         TabIndex        =   8
         Top             =   1440
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "8"
         Height          =   495
         Index           =   1
         Left            =   1440
         TabIndex        =   7
         Top             =   1440
         Width           =   615
      End
      Begin VB.CommandButton Number 
         Caption         =   "7"
         Height          =   495
         Index           =   0
         Left            =   360
         TabIndex        =   6
         Top             =   1440
         Width           =   615
      End
      Begin VB.CommandButton cmdCancel 
         Caption         =   "C"
         Height          =   375
         Left            =   4680
         TabIndex        =   5
         Top             =   840
         Width           =   855
      End
      Begin VB.CommandButton cmdCE 
         Caption         =   "CE"
         Height          =   375
         Left            =   2520
         TabIndex        =   4
         Top             =   840
         Width           =   1335
      End
      Begin VB.CommandButton cmdBackspace 
         Caption         =   "Backspace"
         Height          =   375
         Left            =   360
         TabIndex        =   3
         Top             =   840
         Width           =   1695
      End
      Begin VB.TextBox Readout 
         Alignment       =   1  'Right Justify
         Height          =   375
         Left            =   1440
         TabIndex        =   2
         Text            =   "0."
         Top             =   240
         Width           =   4215
      End
      Begin VB.Label Label1 
         Caption         =   "输入框"
         Height          =   375
         Left            =   360
         TabIndex        =   1
         Top             =   360
         Width           =   1215
      End
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Op1, Op2
Dim DecimalFlag As Integer
Dim NumOps As Integer
Dim LastInput
Dim Opflag
Dim TempReadout

'   窗体的初始化过程
'   设置所有变量为其初始值
Private Sub Form_Load()
 DecimalFlag = False
 NumOps = 0
 LastInput = "NONE"
 Opflag = "   "
 Readout = Format(0, "0.")
End Sub
'Backspace(退格)按钮的click事件过程
Private Sub cmdBackspace_Click()
If Readout.Text = " " Then
Exit Sub
End If
 If DecimalFlag = False Then
 Readout.Text = Left(Readout.Text, Len(Readout.Text) - 2) + Format(0, ".")
 Else
 Readout.Text = Left(Readout.Text, Len(Readout.Text) - 1)
' DecimalFlag = False
 End If
End Sub

' C (取消) 按钮的 Click 事件过程
' 重新设置显示并初始化变量。

Private Sub cmdCancel_Click()
  Readout = Format(0, "0.")
  Op1 = 0
  Op2 = 0
  Form_Load
End Sub

' CE (取消输入)按钮的   Click   事件过程
Private Sub cmdCE_Click()
  Readout = Format(0, "0.")
  DecimalFlag = False
  LastInput = "CE"
End Sub
'计算倒数(1/x)按钮的click过程
Private Sub Countdown_Click(Index As Integer)
  Readout = 1 / Readout
  Opflag = "1/x"
  NumOps = NumOps + 1
 DecimalFlag = True
 LastInput = "NUMS"
End Sub

'   小数点   (.)   按钮的   Click   事件过程
'   如果上一次按键为运算符,初始化   readout   为   "0.";
'   否则显示时追加一个小数点
Private Sub Decimal_Click(Index As Integer)
  If LastInput = "NEG" Then
    Readout = Format(0, "-0.")
  ElseIf LastInput <> "NUMS" Then
    Readout = Format(0, "0.")
 End If
  DecimalFlag = True
  LastInput = "NUMS"
End Sub

'   数字键   (0-9)   的   Click   事件过程
'   向显示中的数追加新数
Private Sub Number_Click(Index As Integer)
 If LastInput <> "NUMS" Then
   Readout = Format(0, ".")
   DecimalFlag = False
End If
 
 If DecimalFlag Then
   Readout = Readout + Number(Index).Caption
 Else
   Readout = Left(Readout, InStr(1, Readout, Format(0, "."), 1) - 1) + Number(Index).Caption + Format(0, ".")
  ' Readout.Text = Left(Readout.Text, Len(Readout.Text) - 1) + Number(Index).Caption + Format(0, ".")
 End If
 If LastInput = "NEG" Then
 Readout = "-" & Readout
 End If
   LastInput = "NUMS"

End Sub
  

 '   运算符   (+,   -,   x,   /,   =)   的   Click   事件过程
 '   如果接下来的按键是数字键,增加   NumOps。
 '   如果有一个操作数,则设置   Op1。
 '   如果有两个操作数,则将   Op1   设置为   Op1   与
 '   当前输入字符串的运算结果,并显示结果

Private Sub Operator_Click(Index As Integer)
TempReadout = Readout
  If LastInput = "NUMS" Then
    NumOps = NumOps + 1
  End If
  Select Case NumOps
  Case 0
  If Operator(Index).Caption = "-" And LastInput <> "NEG" Then
  Readout = "-" + Readout
  LastInput = "NEG"
  End If
  Case 1
  Op1 = Readout
  If Operator(Index).Caption = "-" And LastInput <> "NUMS" And Opflag <> "=" Then
   Readout = "-"
   LastInput = "NEG"
  End If
  Case 2
  Op2 = TempReadout
  Select Case Opflag
    Case "+"
      Op1 = CDbl(Op1) + CDbl(Op2)
    Case "-"
      Op1 = CDbl(Op1) + CDbl(Op2)
    Case "*"
      Op1 = CDbl(Op1) * CDbl(Op2)
    Case "/"
     If Op2 = 0 Then
       MsgBox "除数不能为0", 48, "计算器"
     Else
     Op1 = CDbl(Op1) / CDbl(Op2)
     End If
    Case "="
     Op1 = CDbl(Op2)
 End Select
     Readout = Op1
     NumOps = 1
 End Select
 If LastInput <> "NEG" Then
     LastInput = "OPS"
     Opflag = Operator(Index).Caption
 End If
    
End Sub
'计算被分数的(%)的click的过程
Private Sub Percent_Click(Index As Integer)
  Readout = Readout / 100
  LastInput = "NUMS"
  Opflag = "%"
  NumOps = NumOps + 1
  DecimalFlag = True
End Sub

'计算平方根(sqrt)按钮的click过程
Private Sub Sqrt_Click(Index As Integer)
  Readout = Sqr(Readout)
  LastInput = "NUMS"
  Opflag = "sqrt"
  NumOps = NumOps + 1
  DecimalFlag = True
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -