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

📄 计算器1.frm

📁 可以实现各种计算运算
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "计算器"
   ClientHeight    =   3675
   ClientLeft      =   4965
   ClientTop       =   3810
   ClientWidth     =   4695
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3675
   ScaleWidth      =   4695
   Begin VB.Timer Timer1 
      Interval        =   1000
      Left            =   2400
      Top             =   3720
   End
   Begin VB.TextBox Text4 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "Times New Roman"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   3240
      TabIndex        =   18
      TabStop         =   0   'False
      Top             =   360
      Width           =   1455
   End
   Begin VB.TextBox Text3 
      BeginProperty Font 
         Name            =   "Times New Roman"
         Size            =   18
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   120
      TabIndex        =   5
      Top             =   360
      Width           =   3735
   End
   Begin VB.Frame Frame1 
      Caption         =   "请输入数字"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   2655
      Left            =   120
      TabIndex        =   0
      Top             =   960
      Width           =   4575
      Begin VB.CommandButton Command2 
         Caption         =   "√    3√"
         Height          =   495
         Left            =   2880
         TabIndex        =   17
         Top             =   2040
         Width           =   735
      End
      Begin VB.CommandButton Command15 
         Caption         =   "ctg ctg^-1"
         Height          =   495
         Left            =   2880
         TabIndex        =   14
         Top             =   1560
         Width           =   735
      End
      Begin VB.CommandButton Command14 
         Caption         =   "tan tan^-1"
         Height          =   495
         Left            =   2160
         TabIndex        =   13
         Top             =   1560
         Width           =   735
      End
      Begin VB.CommandButton Command13 
         Caption         =   "cos cos^-1"
         Height          =   495
         Left            =   2880
         TabIndex        =   10
         Top             =   1080
         Width           =   735
      End
      Begin VB.CommandButton Command12 
         Caption         =   "sin sin^-1"
         Height          =   495
         Left            =   2160
         TabIndex        =   9
         Top             =   1080
         Width           =   735
      End
      Begin VB.CommandButton Command10 
         Caption         =   "2ndF"
         Height          =   495
         Left            =   2160
         TabIndex        =   6
         Top             =   600
         Width           =   735
      End
      Begin VB.CommandButton Command9 
         Caption         =   "cls"
         Height          =   495
         Left            =   3600
         TabIndex        =   15
         Top             =   1560
         Width           =   735
      End
      Begin VB.CommandButton Command11 
         Caption         =   "+/-"
         Height          =   495
         Left            =   2160
         TabIndex        =   16
         Top             =   2040
         Width           =   735
      End
      Begin VB.CommandButton Command1 
         Caption         =   "="
         Default         =   -1  'True
         Height          =   495
         Left            =   3600
         TabIndex        =   4
         Top             =   2040
         Width           =   735
      End
      Begin VB.CommandButton Command5 
         Caption         =   "ln  e^x"
         Height          =   495
         Left            =   2880
         TabIndex        =   7
         Top             =   600
         Width           =   735
      End
      Begin VB.CommandButton Command3 
         Caption         =   "lg 10^x"
         Height          =   495
         Left            =   3600
         TabIndex        =   8
         Top             =   600
         Width           =   735
      End
      Begin VB.CommandButton Command4 
         Caption         =   "x^2  1/x"
         Height          =   495
         Left            =   3600
         TabIndex        =   12
         Top             =   1080
         Width           =   735
      End
      Begin VB.ComboBox Combo1 
         Height          =   300
         Left            =   240
         TabIndex        =   3
         Text            =   "Combo1"
         Top             =   1440
         Width           =   1095
      End
      Begin VB.TextBox Text2 
         BeginProperty Font 
            Name            =   "Times New Roman"
            Size            =   18
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   615
         Left            =   120
         TabIndex        =   2
         Top             =   1920
         Width           =   1815
      End
      Begin VB.TextBox Text1 
         BeginProperty Font 
            Name            =   "Times New Roman"
            Size            =   18
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   615
         Left            =   120
         TabIndex        =   1
         Top             =   600
         Width           =   1815
      End
   End
   Begin VB.Label Label1 
      Caption         =   "计算结果为:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   11
      Top             =   120
      Width           =   3735
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private g As Integer, pi As Single, e As Single, d As Single




Private Sub Combo1_KeyPress(KeyAscii As Integer)
'If KeyAscii = 13 Then Command1.SetFocus

End Sub

Private Sub Command1_Click()
Dim a, b, c As Single
a = Val(Text1.Text)
b = Val(Text2.Text)
Select Case Combo1.ListIndex
  Case 0
 c = a + b
 Text3.Text = Str(c)
 Case 1
 c = a - b
  Text3.Text = Str(c)
Case 2
c = a * b
 Text3.Text = Str(c)
Case 3
c = a / b
 Text3.Text = Str(c)
 End Select
 If Val(Text3.Text) > 100000000000000# Then Text3.Text = "0"
If Abs(Val(Text3.Text)) < 0.00000001 Then
Text3.Text = "0"
End If

End Sub

Private Sub Command10_Click()

Select Case g
 Case 0
 g = 1
 Case 1
 g = 0
 End Select

End Sub

Private Sub Command11_Click()
Combo1.Enabled = False
c = Val(Text3.Text)
Text3.Text = Str(-c)
End Sub

Private Sub Command12_Click()
Combo1.Enabled = False
Dim d  As Single, e As Single
c = Val(Text3.Text)
X = 2 * pi * c / 360

d = Sin(X)
If g = 0 Then
  Text3.Text = Str(d)
Else
  If c < -1 Then
  Text3.Text = MsgBox("反正弦参数不能小于-1", 0, "提示")
      Text3.Text = "0"
     Text3.SetFocus
   ElseIf c > 1 Then
     Text3.Text = MsgBox("反正弦参数不能大于1", 0, "提示")
      Text3.Text = " 0"
     Text3.SetFocus
  ElseIf c = 1 Then
   Text3.Text = "90"
    ElseIf c = -1 Then
   Text3.Text = "270"
  Else
    Text3.Text = Str(Atn(c / Sqr(-c * c + 1)) * 360 / (2 * pi))
  End If
End If
If Abs(Val(Text3.Text)) < 0.00000001 Then
 Text3.Text = "0"
 End If
End Sub

Private Sub Command13_Click()
Combo1.Enabled = False

Dim d, e As Single
c = Val(Text3.Text)
d = Cos(X)
X = 2 * pi * c / 360
If g = 0 Then
Text3.Text = Str(d)
Else
  If c < -1 Then
   Text3.Text = MsgBox("反余弦参数不能小于-1", 0, "提示")
      Text3.Text = "0 "
     Text3.SetFocus
  ElseIf c > 1 Then
    Text3.Text = MsgBox("反余弦参数不能大于1", 0, "提示")
      Text3.Text = " 0"
     Text3.SetFocus
   ElseIf c = 1 Then
   Text3.Text = "0"
    ElseIf c = -1 Then
   Text3.Text = "180"
  Else
    Text3.Text = Str((Atn(-c / Sqr(-c * c + 1)) + 2 * Atn(1)) * 360 / (2 * pi))
 End If
End If
If Abs(Val(Text3.Text)) < 0.00000001 Then
 Text3.Text = "0"
 End If

End Sub

Private Sub Command14_Click()
Combo1.Enabled = False

Dim e As Single, d As Single

c = Val(Text3.Text)
X = 2 * pi * c / 360
d = Tan(X)
If g = 0 Then
  If c = 90 Then
    Text3.Text = MsgBox("正切角度不能等于90", 0, "提示")
      Text3.Text = " "
     Text3.SetFocus
  ElseIf c = 270 Then
   Text3.Text = MsgBox("正切角度不能等于270", 0, "提示")
      Text3.Text = "0 "
     Text3.SetFocus
  Else
   'Text3.Text = Str(Tan(X))
   Text3.Text = Str(d)
  End If
Else
  Text3.Text = Str(Atn(c) * 360 / (2 * pi))
End If
If Abs(Val(Text3.Text)) < 0.000001 Then
 Text3.Text = "0"
 End If

End Sub

Private Sub Command15_Click()
Combo1.Enabled = False

Dim d, e As Single

c = Val(Text3.Text)
X = 2 * pi * c / 360
d = 1 / Tan(X)
If g = 0 Then
  If c = 180 Then
   Text3.Text = MsgBox("余切角度不能等于180", 0, "提示")
      Text3.Text = "0 "
     Text3.SetFocus
   ElseIf c = 360 Then
     Text3.Text = MsgBox("余切角度不能等于360", 0, "提示")
      Text3.Text = "0 "
     Text3.SetFocus
  Else
   Text3.Text = Str(d)
  End If
Else
Text3.Text = Str((Atn(c) + 2 * Atn(1)) * 360 / 2 * pi)
End If
  If Abs(Val(Text3.Text)) < 0.00000001 Then
  Text3.Text = "0"
  End If

End Sub

Private Sub Command2_Click()
Combo1.Enabled = False
Dim d, e As Single

c = Val(Text3.Text)

d = Sqr(Abs(c))
e = Sgn(c) * c ^ (1 / 3)

If g = 0 Then
  If c < 0 Then
   Text3.Text = MsgBox("开根数不能小于零", 0, "提示")
   Text3.Text = "0 "
   Text3.SetFocus
  Else
   Text3.Text = Str(d)
   End If
Else
Text3.Text = Str(e)
End If
If Abs(Val(Text3.Text)) < 0.00000001 Then
 Text3.Text = "0"
 End If
 If Val(Text3.Text) > 100000000000000# Then Text3.Text = "0"

 

End Sub

Private Sub Command3_Click()
Combo1.Enabled = False
Dim d, e As Single

If Val(Text3.Text) > 100000000000000# Then Text3.Text = "0"

c = Val(Text3.Text)
d = Log(c) / Log(10)
If g = 0 Then
  If c <= 0 Then
     Text3.Text = MsgBox("对数参数不能小于或等于零", 0, "提示")
      Text3.Text = " 0"
     Text3.SetFocus
  Else
    Text3.Text = Str(d)
  End If
Else
If Val(Text3.Text) > 15# Then
Text3.Text = "0"

Else
 e = Exp(c * Log(10))

 Text3.Text = Str(e)
End If
End If
End Sub

Private Sub Command4_Click()
Combo1.Enabled = False
Dim d, e As Single

c = Val(Text3.Text)
d = c ^ 2
e = 1 / c

If g = 0 Then
   Text3.Text = Str(d)
Else
   If c = 0 Then
     Text3.Text = MsgBox("除数不能小于零", 0, "提示")
      Text3.Text = "0 "
     Text3.SetFocus
   Else
      Text3.Text = Str(e)
    End If
End If
If Abs(Val(Text3.Text)) < 0.00000001 Then
 Text3.Text = "0"
 End If
If Val(Text3.Text) > 100000000000000# Then Text3.Text = "0"
End Sub

Private Sub Command5_Click()
Combo1.Enabled = False
'Dim d, e As Single

c = Val(Text3.Text)
d = Log(c)

If g = 0 Then
  If c <= 0 Then
     Text3.Text = MsgBox("对数参数不能小于或等于零", 0, "提示")
      Text3.Text = "0 "
     Text3.SetFocus
  Else
    Text3.Text = Str(d)
  End If
Else

If Val(Text3.Text) > 20# Then
 Text3.Text = "0"
 Else
 If Exp(c) > 1000000000000# Then
Text3.Text = Str(Exp(c))
End If
End If
If Abs(Val(Text3.Text)) < 0.00000001 Then
Text3.Text = "0"
End If

End Sub

Private Sub Command9_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = "0"
End Sub

Private Sub Form_Load()
Combo1.AddItem "+"
Combo1.AddItem "-"
Combo1.AddItem "*"
Combo1.AddItem "/"
pi = 3.141592654
Text3.Text = "0"
'If Text1.Enabled = True Then
'Command2.TabStop
'Command3.TabStop
'End If



 
   
End Sub

Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
'If KeyAscii = 13 Then Command1.SetFocus

End Sub

Private Sub Text2_GotFocus()
Text2.SelStart = 0
Text2.SelLength = Len(Text2.Text)
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
'If KeyAscii = 13 Then Command1.SetFocus

End Sub

Private Sub Text3_GotFocus()
Text3.SelStart = 0
Text3.SelLength = Len(Text3.Text)
End Sub

Private Sub Timer1_Timer()
 Text4.Text = "2ndf=" & Str(g) & "  " & Time
End Sub

⌨️ 快捷键说明

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