科学计算器vb代码.docx
- 文档编号:9829673
- 上传时间:2023-05-21
- 格式:DOCX
- 页数:57
- 大小:103.58KB
科学计算器vb代码.docx
《科学计算器vb代码.docx》由会员分享,可在线阅读,更多相关《科学计算器vb代码.docx(57页珍藏版)》请在冰点文库上搜索。
科学计算器vb代码
?
用VB写计算器似乎有很多例子,这个代码就是其中之一,科学计算器是在基本计算器的基础上,加入角度、弧度、梯度、正切、余切、正弦余弦、平方根等的数学计
算,当然基础的加减乘除运算就更不用说了,这是在一本VB教程中摘录的代码,你可以此为基础完善扩展该计算器的功能,运行截图如下:
核心代码,只有一个文件代码:
VERSION5.00
BeginVB.FormFrm_Scientific
Caption
=
"
计算器"
ClientHeight
=
2925
ClientLeft
=
165
ClientTop
=
735
ClientWidth
=
5595
LinkTopic
=
"Form1"
LockControls
=
-1
'True
MaxButton
=
0
'False
ScaleHeight
=
2925
ScaleWidth
=
5595
StartUpPosition=
3
'
窗口缺省
BeginVB.CommandButtonCmd_Rnd
Caption
=
"Rnd"
Height
=
390
Left
=
5025
TabIndex
=
39
Top
=
1455
Width
=
510
精选文档
End
BeginVB.CommandButtonCmd_PI
Caption
=
"PI"
Height
=
390
Left
=
1575
TabIndex
=
38
Top
=
2400
Width
=
630
End
BeginVB.CommandButtonCmd_Fact
Caption
=
"N!
"
Height
=
390
Left
=
1575
TabIndex
=
37
Top
=
1935
Width
=
630
End
BeginVB.CommandButtonCmd_Log
Caption
=
"Log"
Height
=
390
Left
=
1575
TabIndex
=
36
Top
=
1455
Width
=
630
End
BeginVB.CommandButtonCmd_Ln
Caption
=
"Ln"
Height
=
390
Left
=
1575
TabIndex
=
35
Top
=
960
Width
=
630
End
BeginVB.CommandButtonCmd_Square
Caption="X^2"
Height=390
—2
精选文档
Left
=
840
TabIndex
=34
Top
=
2400
Width
=
630
End
BeginVB.CommandButtonCmd_Cube
Caption
="X^3"
Height
=
390
Left
=
825
TabIndex
=33
Top
=
1935
Width
=
630
End
BeginVB.CommandButtonCmd_Operator
Caption
="X^Y"
Height
=
390
Index
=
5
Left
=
840
TabIndex
=32
Top
=
1455
Width
=
630
End
BeginVB.CommandButtonCmd_Exp
Caption
="Exp"
Height
=
390
Left
=
840
TabIndex
=31
Top
=
960
Width
=
630
End
BeginVB.CommandButtonCmd_Sin
Caption
="Sin"
Height
=
390
Left
=
120
TabIndex
=30
Top
=
960
—3
精选文档
Width
=
630
End
BeginVB.CommandButtonCmd_Cos
Caption
=
"Cos"
Height
=
390
Left
=
120
TabIndex
=
29
Top
=
1455
Width
=
630
End
BeginVB.CommandButtonCmd_Tan
Caption
=
"Tan"
Height
=
390
Left
=
120
TabIndex
=
28
Top
=
1935
Width
=
630
End
BeginVB.CommandButtonCmd_Atan
Caption
=
"Atan"
Height
=
390
Left
=
120
TabIndex
=
27
Top
=
2400
Width
=
630
End
BeginVB.FrameFrame1
Height
=
510
Left
=
90
TabIndex
=
23
Top
=
330
Width
=
2625
BeginVB.OptionButtonOtn_Grd
Caption
=
"
梯度"
Height
=
180
Left
=
1695
—4
精选文档
TabIndex
=26
Top
=
210
Width
=
750
End
BeginVB.OptionButtonOtn_Rad
Caption
="
弧度"
Height
=
180
Left
=
900
TabIndex
=
25
Top
=
210
Width
=
795
End
BeginVB.OptionButtonOtn_Deg
Caption
="
角度"
Height
=
180
Left
=
135
TabIndex
=
24
Top
=
210
Value
=
-1'True
Width
=
675
End
End
BeginVB.CommandButtonCmd_Operator
Caption
=
"="
Height
=
390
Index
=
4
Left
=
5025
TabIndex
=
22
Top
=
2400
Width
=
510
End
BeginVB.CommandButtonCmd_Operator
Caption
=
"+"
Height
=
390
Index
=
3
Left
=
4470
—5
精选文档
MaskColor
=
&H00808080&
Style
=
1
'Graphical
TabIndex
=
21
Top
=
2400
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
=
"."
Height
=
390
Index
=
11
Left
=
3915
TabIndex
=
20
Top
=
2400
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
=
"+/-"
Height
=
390
Index
=
10
Left
=
3360
TabIndex
=
19
Top
=
2400
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
=
"0"
Height
=
390
Index
=
0
Left
=
2820
TabIndex
=
18
Top
=
2400
Width
=
510
End
BeginVB.CommandButtonCmd_fraction
Caption="1/x"
Height=390
—6
精选文档
Left
=
5025
TabIndex
=17
Top
=
1935
Width
=
510
End
BeginVB.CommandButtonCmd_sqrt
Caption
="Sqrt"
Height
=
390
Left
=
5025
TabIndex
=16
Top
=
960
Width
=
510
End
BeginVB.CommandButtonCmd_C
Caption
="C"
Height
=
405
Left
=
4785
TabIndex
=15
Top
=
405
Width
=
750
End
BeginVB.CommandButtonCmd_CE
Caption
="CE"
Height
=
405
Left
=
3975
TabIndex
=14
Top
=
405
Width
=
750
End
BeginVB.CommandButtonCmd_Backspace
Caption
="Backspace"
Height
=
405
Left
=
2820
TabIndex
=13
Top
=
405
Width
=
1110
—7
精选文档
End
BeginVB.CommandButtonCmd_Operator
Caption
="-"
Height
=
390
Index
=
2
Left
=
4470
TabIndex
=12
Top
=
1935
Width
=
510
End
BeginVB.CommandButtonCmd_Operator
Caption
=
"*"
Height
=
390
Index
=
1
Left
=
4470
TabIndex
=11
Top
=
1455
Width
=
510
End
BeginVB.CommandButtonCmd_Operator
Caption
=
"/"
Height
=
390
Index
=
0
Left
=
4470
TabIndex
=10
Top
=
960
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
="9"
Height
=
390
Index
=
9
Left
=
3915
TabIndex
=9
Top
=
960
Width
=
510
—8
精选文档
End
BeginVB.CommandButtonCommand1
Caption
="8"
Height
=
390
Index
=
8
Left
=
3360
TabIndex
=8
Top
=
960
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
=
"7"
Height
=
390
Index
=
7
Left
=
2820
TabIndex
=7
Top
=
960
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
=
"6"
Height
=
390
Index
=
6
Left
=
3915
TabIndex
=6
Top
=
1455
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
="5"
Height
=
390
Index
=
5
Left
=
3360
TabIndex
=5
Top
=
1455
Width
=
510
—9
精选文档
End
BeginVB.CommandButtonCommand1
Caption
="4"
Height
=
390
Index
=
4
Left
=
2820
TabIndex
=4
Top
=
1455
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
=
"3"
Height
=
390
Index
=
3
Left
=
3915
TabIndex
=3
Top
=
1935
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
=
"2"
Height
=
390
Index
=
2
Left
=
3360
TabIndex
=2
Top
=
1935
Width
=
510
End
BeginVB.CommandButtonCommand1
Caption
="1"
Height
=
390
Index
=
1
Left
=
2820
TabIndex
=1
Top
=
1935
Width
=
510
—10
精选文档
End
BeginVB.TextBoxTxt_Result
Alignment
=
1
'RightJustify
Height
=
315
Left
=
90
Locked
=
-1
'True
TabIndex
=
0
Text
=
"0."
Top
=
0
Width
=
5385
End
BeginVB.MenuMenu_Edit
Caption
=
"
编辑(&E)"
BeginVB.MenuMenu_Copy
Caption
=
"
复制"
Shortcut
=
^C
End
BeginVB.MenuMenu_Paste
Caption
=
"
粘贴"
Shortcut
=
^V
End
BeginVB.MenuMenu_Cut
Caption
=
"
剪切"
Shortcut
=
^X
End
BeginVB.Menuline1
Caption="-"
End
BeginVB.MenuMenu_All
Caption="全选"
Shortcut=^A
End
BeginVB.Menuline2
Caption="-"
End
—11
精选文档
BeginVB.MenuMenu_Exit
Caption="退出"
End
End
BeginVB.MenuMenu_Help
Caption="帮助(&H)"
BeginVB.MenuMenu_HelpSubject
Caption="帮助主题(&H)"
End
BeginVB.MenuMenu_About
Caption="关于计算器"
End
End
End
AttributeVB_Name="Frm_Scientific"
AttributeVB_GlobalNameSpace=False
AttributeVB_Creatable=False
AttributeVB_PredeclaredId=True
AttributeVB_Exposed=False
OptionExplicit
Dimque(25)AsDouble
PublicqtAsInteger
PublicqhAsInteger
PublicqvAsInteger
PublicangAsDouble
PublicmemoAsDouble
DimdflagAsInteger
DimiAsInteger
DimopnreAsInteger
DimprevAsDouble
DimoflagAsInteger
DimindAsInteger
PrivateSubCmd_Atan_Click()'Atan函数
Txt_Result.Text=Str((Atn(Val(Txt_Result.Text)))/ang)
prev=Txt_Result.Text
—12
精选文档
EndSub
PrivateSubCmd_Backspace_Click()'退格
IfTxt_Result.Text="0."Then
ExitSub
EndIf
If(Txt_Result.Text<>"")Then
Txt_Result.Text=Mid(Txt_Result.Text,1,Len(Txt_Result.Text)-
1)
ElseIfTxt_Result.Text=""Then
Txt_Result.Text="0."
EndIf
EndSub
PrivateSubCmd_C_Click()'清零
Txt_Result.Text="0"
prev=0
EndSub
PrivateSubCmd_CE_Click()
dflag=0
prev=0
oflag=0
ind=0
opnre=0
Txt_Result="0"
EndSub
PrivateSubCmd_Cos_Click()'Cos值
Txt_Result.Text=Str(Cos(ang*Val(Txt_Result.Text)))
prev=Txt_Result.Text
EndSub
PrivateSubCmd_Cube_Click()
Txt_Result.Text=Val(Txt_Result.Text)^3
prev=Txt_Result.Text
EndSub
PrivateSubCmd_Exp_Click()'计算Exp的值
Txt_Result.Text=Exp(Txt_Result.Text)
prev=Txt_Result.Text
EndSub
—13
精选文档
PrivateSubCmd_Fact_Click()'N!
Txt_Result.Text=Str(fac(Val(Txt_Result.Text)))
prev=Txt_Result.Text
EndSub
PrivateSubCmd_fraction_Click()'倒数
DimTemp
Temp=Val(Txt_Result.Text)
IfTemp<>0Then
Txt_Result.Text=Str(1/Temp)
Else
Txt_Result.Text="除数不能为零。
"
EndIf
prev=Txt_Result.Text
EndSub
PrivateSubCmd_Ln_Click()'LN
IfVal(Txt_Result.Text)>0Then
Txt_Result.Text=Str(Log(Val(Txt_Result.Text)))
Else
Txt_Result.Text="输入有误。
"
EndIf
prev=Txt_Result.Text
EndSub
PrivateSubCmd_Log_Click()'Log
IfVal(Txt_Result.Text)>0Then
Txt_Result.Text=Str((Log(Val(Txt_Result.Text))/Log(10)))
Else
Txt_Result.Text="输入有误。
"
EndIf
prev=Txt_Result.Text
EndSub
PrivateSubCmd_Operator_Click(IndexAsInteger)'单击操作符按钮
Ifopnre=0OrIndex=4Then
Ifind=3Then'加号
prev=prev+Val(Txt_Result.Text)
ElseIfind=2Then'减号
—14
精选文档
prev=prev-Val(Txt_Result.Text)
ElseIfind=0Then'除号
IfVal(Txt_Result.Text)=0Then
Txt_
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 科学 计算器 vb 代码