计算器.frm
来自「上传的包含两个文件」· FRM 代码 · 共 652 行 · 第 1/2 页
FRM
652 行
Height = 400
Index = 1
Left = 240
Picture = "计算器.frx":5C2AD
Style = 1 'Graphical
TabIndex = 2
Top = 2040
Width = 600
End
Begin VB.CommandButton Command1
BackColor = &H00C0C0C0&
Height = 400
Index = 0
Left = 240
Picture = "计算器.frx":5E7F4
Style = 1 'Graphical
TabIndex = 1
Top = 4560
Width = 600
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BeginProperty Font
Name = "宋体"
Size = 14.25
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 405
Left = 360
TabIndex = 0
Top = 1290
Width = 4095
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Unknownn1 As Long, ByVal Unknownn2 As Long, ByVal fCheckOnly As Long) As Long
Public num1 As Double '第一个操作数
Public num2 As Double '第2个操作数
Public temp As Double '中间变量
Public deci As Integer '是否在输入小数状态
Public state As Integer '处于那个操作数的状态中
Public opstate As Integer '符号状态
Public doubleop As Integer '是否连续多次按双目运算符
Public exitnum2 As Integer '有否输入第二个操作数
Public bit As Integer '总位数
Public debit As Integer '小数位数
Private Function ExecuteLine(sCode As String, Optional fCheckOnly As Boolean) As Boolean
ExecuteLine = EbExecuteLine(StrPtr(sCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
Sub calc(ByVal x As String)
Dim result
ExecuteLine "dim x as double"
ExecuteLine "x= " & x
ExecuteLine "clipboard.settext x"
result = Clipboard.GetText
Text1.Text = result
Set result = Nothing
End Sub
Public Sub Form() '字符转数据
If state = 0 Then
num1 = Val(Text1.Text)
Else
num2 = Val(Text1.Text)
End If
End Sub
Public Sub initial() '初始化数值
debit = 0
temp = 0
deci = 0
bit = 0
End Sub
Public Sub cal() '计算结果并把结果存入num1中
Select Case opstate
Case 0: num1 = num1 + num2
Case 1: num1 = num1 - num2
Case 2: num1 = num1 * num2
Case 3: num1 = num1 / num2
Case 4: num1 = num1 ^ num2
End Select
Text1.Text = num1
End Sub
Public Sub command1_click(index As Integer) '数据输入键系列
Dim n
If bit = 0 Then
Text1.Text = ""
End If
Select Case index
Case 10
If deci = 0 Then
Text1.Text = Text1.Text & "."
End If
deci = 1
n = ""
Case index: n = index
End Select
If state = 0 Then
Text1.Text = Text1.Text & n
bit = bit + 1
If deci = 1 Then
debit = debit + 1
End If
Else
exitnum2 = -1
Text1.Text = Text1.Text & n
bit = bit + 1
If deci = 1 Then
debit = debit + 1
End If
doubleop = 1
End If
End Sub
Public Sub command2_click(index As Integer) '单目运算符
Call Form
Dim subnum As Double
If state = 0 Then
subnum = num1
Else
subnum = num2
End If
Select Case index
Case 1
If subnum = 0 Then
MsgBox (" 0 没有倒数!")
Text1.SetFocus
Else
subnum = 1 / subnum
End If
Case 2: subnum = subnum / 100
Case 3: subnum = -subnum
Case 4:
If subnum < 0 Then
MsgBox ("请输入正数!")
Text1.SetFocus
Else
subnum = Sqr(subnum)
End If
Case 5
Dim temp2
If subnum < 0 Or deci = 1 Then
MsgBox ("请输入正整数!")
Text1.SetFocus
ElseIf subnum > 170 Then
MsgBox ("请输入数值过大!")
Text1.SetFocus
Else
Dim count As Long
count = subnum - 1
subnum = 1
For temp2 = 0 To count
subnum = (temp2 + 1) * subnum
Next temp2
End If
Case 6: subnum = Log(subnum)
Case 7: subnum = Sin(subnum * 3.14152 / 180)
Case 8: subnum = Cos(subnum * 3.14152 / 180)
Case 9: subnum = Tan(subnum * 3.14152 / 180)
End Select
If state = 0 Then
num1 = subnum
Else
num2 = subnum
End If
Call initial
Text1.Text = subnum
End Sub
Public Sub command3_click(index As Integer) '双目运算符
Call Form
If doubleop = 0 And exitnum2 = 0 Then
state = -1
Select Case index
Case index: opstate = index
End Select
Call initial
ElseIf doubleop = 0 And exitnum2 <> 0 Then '基础结果后与结果进行运算
Select Case index
Case index: opstate = index
End Select
Call initial
ElseIf doubleop = 1 And exitnum2 <> 0 Then '增多等号功能
Call cal
Select Case index
Case index: opstate = index
End Select
Call initial
Else '人为错误的多次按双目运算符按钮
Select Case index
Case index: opstate = index
End Select
Call initial
End If
doubleop = doubleop + 1
End Sub
Private Sub command4_click(index As Integer)
Select Case index
Case 0
If bit = 0 Then
Text1.Text = 0
Else
bit = bit - 1
If deci = 0 Then
Text1.Text = Left(Text1.Text, bit)
Else
debit = debit - 1
Text1.Text = Left(Text1.Text, bit) '如果最后一位小数也被删除,则去掉小数点
If debit = 0 Then
bit = bit - 1
deci = 0
Text1.Text = Left(Text1.Text, bit)
End If
End If
End If
Case 1
num1 = 0
num2 = 0
temp = 0
deci = 0
state = 0
opstate = 0
doubleop = 0
exitnum2 = 0
bit = 0
Text1.Text = ""
Case 2
Call Form
Call cal
Call initial
doubleop = 0
Case 3
Unload Form1
End Select
End Sub
Private Sub Command5_Click()
Dim message, title, myvalue
message = "VB数学函数列表:" & Chr(10) & Chr(10) & "开方: sqr " & "绝对值: abs " & "自然对数: log" & Chr(10) & Chr(10) & "计算e的n次方: exp" & Chr(10) & Chr(10) & "三角函数: sin, cos, tan, "
title = "请直接输入数学表达式"
myvalue = InputBox(message, title, Text1.Text)
calc myvalue
End Sub
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?