VB计算器界面设计+ 全部代码.docx
- 文档编号:10465761
- 上传时间:2023-05-26
- 格式:DOCX
- 页数:19
- 大小:34.87KB
VB计算器界面设计+ 全部代码.docx
《VB计算器界面设计+ 全部代码.docx》由会员分享,可在线阅读,更多相关《VB计算器界面设计+ 全部代码.docx(19页珍藏版)》请在冰点文库上搜索。
VB计算器界面设计+全部代码
VB计算器
此计算器能够实现加减乘除等一系列的功能。
还有实现显示系统时间的附加功能。
截图如下:
程序设计:
0-9和点在command1的组内。
其他的按钮式运算符和其他功能。
正切和余切有对特殊值进行警告,除也有对除数为零的情况提示警告,还有阶乘等一系列计算溢出的情况提出警告,还有很多需要完善。
。
。
这仅供参考。
PublicsumAsDouble
PublickAsString
PublicdianAsBoolean
PublicbAsInteger
PublicpointflagAsBoolean
DimclearFlagAsBoolean
PublicFAsLong
'DimstartAsboolen
PublicreslAsBoolean'运算结果存储在resl里
PublicffAsDouble'resl里是否为空
'////////////////////////////////////////////////////////数字按钮在一个组内,点击按钮输入数字///////////////////////////////////////////
PrivateSubcommand1_click(IndexAsInteger)
SelectCaseIndex
Case1
IfNotclearFlagThen'不是等号,那么显示1
Text1.Text=Text1.Text&1
Else'是等号,那么清空
Text1.Text=1
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
'如果第一位的数位0,字符串的长度为2.那么取字符串右面的数,即两个数中右面的数
Case2
IfNotclearFlagThen
Text1.Text=Text1.Text&2
Else
Text1.Text=2
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
Case3
IfNotclearFlagThen
Text1.Text=Text1.Text&3
Else
Text1.Text=3
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
Case4
IfNotclearFlagThen
Text1.Text=Text1.Text&4
Else
Text1.Text=4
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
Case5
IfNotclearFlagThen
Text1.Text=Text1.Text&5
Else
Text1.Text=5
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
Case6
IfNotclearFlagThen
Text1.Text=Text1.Text&6
Else
Text1.Text=6
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
Case7
IfNotclearFlagThen
Text1.Text=Text1.Text&7
Else
Text1.Text=7
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
Case8
IfNotclearFlagThen
Text1.Text=Text1.Text&8
Else
Text1.Text=8
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
Case9
IfNotclearFlagThen
Text1.Text=Text1.Text&9
Else
Text1.Text=9
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
Case0
IfNotclearFlagThen
Text1.Text=Text1.Text&0
Else
Text1.Text=0
clearFlag=False
EndIf
IfLen(Text1.Text)=2AndInStr(1,Text1,"0")=1ThenText1=Right(Text1,1)
Case10
IfNotclearFlagThen
Text1.Text=Text1.Text+"."
Else
Text1.Text=""
clearFlag=False
EndIf
'//////////////////////////////////////////////////对输入点的个数进行约束///////////////////////////////////////////////////////////
If(InStr(Text1.Text,".")=1)Then
'对点的处理,检查是否有点,有点再输入的话为空,否则加入其中
Text1.Text=""
EndIf
IfInStr(Text1.Text,".") Text1.Text=Left(Text1.Text,Len(Text1.Text)-1) EndIf EndSelect Text1.SetFocus EndSub '////////////////////////定义加号按钮////////////////////////////////////// PrivateSubcommand2_click() IfText1.Text=""Then EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text Text1.Text="" k="+" Else ExitSub EndIf EndSub '/////////////////////////定义减号按钮////////////////////////////////////// PrivateSubcommand3_click() IfText1.Text=""Then EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text'第一个数字填入方框里 Text1.Text=""'方框的值置空 k="-" Else ExitSub EndIf EndSub '///////////////////////定义乘号按钮//////////////////////////////////////// PrivateSubcommand4_click() IfText1.Text=""Then EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text Text1.Text="" k="*" Else ExitSub EndIf EndSub '/////////////////////////定义除号按钮////////////////////////////////////////// PrivateSubcommand5_click() IfText1.Text=""Then EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text Text1.Text="" k="/" Else ExitSub EndIf EndSub '////////////////////////////定义sin号按钮///////////////////////////////////// PrivateSubcommand10_click() IfText1.Text=""Then EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text k="sin" Else ExitSub EndIf EndSub '/////////////////////////////定义cos按钮///////////////////////////////////// PrivateSubcommand11_click() IfText1.Text=""Then EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text k="cos" Else ExitSub EndIf EndSub '/////////////////////////////定义tan按钮//////////////////////////////////// PrivateSubcommand12_click() IfText1.Text=""Then EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text k="tan" Else ExitSub EndIf EndSub '//////////////////////////定义cot按钮////////////////////////////////////// PrivateSubcommand13_click() IfText1.Text=""Then EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text k="cot" Else ExitSub EndIf EndSub '///////////////////////////定义^按钮/////////////////////////////////////// PrivateSubCommand14_click() IfText1.Text=""Then ExitSub EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text Text1.Text="" k="^" Else ExitSub EndIf EndSub '/////////////////////////定义2^按钮/////////////////////////////////////////// PrivateSubcommand15_click() IfText1.Text=""Then ExitSub EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text k="2^" Else ExitSub EndIf EndSub '///////////////////////定义3^按钮/////////////////////////////////////////// PrivateSubcommand16_click() IfText1.Text=""Then ExitSub EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text k="3^" Else ExitSub EndIf EndSub '////////////////////定义X! 按钮///////////////////////////////////////////// PrivateSubcommand17_click() IfText1.Text=""Then ExitSub EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text k="x! " Else ExitSub EndIf EndSub '//////////////////定义sqrt按钮////////////////////////////////////////////// PrivateSubcommand18_click() IfText1.Text=""Then ExitSub EndIf IfTrim(Text1.Text)<>""Then sum=Text1.Text k="sqrt" Else ExitSub EndIf EndSub '/////////////////////////////定义阶乘的函数////////////////////////////////// PrivateFunctionNi(NAsLong)AsBoolean 'Ni=False DimMmAsLong 'DimF1AsLong F=1 ForMm=1ToN IfMm>12Then 'IfF1>Then Ni=False ExitFunction EndIf F=F*Mm NextMm Ni=True EndFunction PrivateSubequalbut_click() clearFlag=False EndSub PrivateSubcommand6_click() IfTrim(Text1.Text)<>""Then 'DimFAsDouble DimaAsDouble DimpiAsDouble Dimi,jAsInteger pi=3.14159265358979 IfText1.Text>2147483647Then MsgBox"溢出,请确认",vbExclamation,Me.Caption ExitSub EndIf a=Text1.Text clearFlag=True Ifk="+"Then sum=sum+a Text1.Text=sum ElseIfk="sin"Then sum=Sin(a*pi/180) Text1.Text=sum ElseIfk="cos"Then DimtAsInteger t=aMod180-90 Ift=0Then Text1.Text=0 Else sum=Cos(a*pi/180) Text1.Text=sum EndIf ElseIfk="tan"Then DimmAsInteger DimNAsInteger m=aMod180-90 Ifm=0Then MsgBox"(90+180*n)度的正切值无意义,请重新输入" Else sum=(Tan(a*pi/180)) Text1.Text=sum EndIf ElseIfk="cot"Then Ifa=0Then MsgBox"0度余切没有意义! 请重新输入! " Else sum=1/(Tan(a*pi/180)) Text1.Text=sum EndIf ' 'ElseIfk="x! "Then 'IfText1.Text>0Then 'Callfact(Text1.Text,F) 'Text1.Text=F 'ElseIfText1.Text=0Then 'sum=1 'Text1.Text=sum 'ElseIfText1.Text<0Then 'MsgBox"负数没有阶乘! " 'EndIf ElseIfk="x! "Then IfNi(Text1.Text)=FalseThen MsgBox"溢出",vbExclamation,Me.Caption Text1.Text="" ExitSub Else Text1.Text=F EndIf ElseIfk="2^"Then Text1.Text=Val(Text1.Text)*Val(Text1.Text) ElseIfk="3^"Then Text1.Text=Val(Text1.Text)*Val(Text1.Text)*Val(Text1.Text) ElseIfk="sqr"Then Ifa>=0Then sum=Math.Sqr(a) Text1.Text=sum Else MsgBox"开方数不能为负数! " EndIf ElseIfk="^"Then sum=sum^a Text1.Text=sum ElseIfk="-"Then'减法运算 sum=sum-a Text1.Text=sum 'resl=1 ElseIfk="*"Then sum=sum*a Text1.Text=sum ElseIfk="/"Then IfText1.Text=0Then MsgBox"除数不能为零! 请重新输入" Text1.Text="" Else sum=sum/a Text1.Text=sum IfLen(Text1.Text)>14Then MsgBox"溢出,请确认",vbExclamation,Me.Caption ExitSub EndIf ExitSub EndIf EndIf EndIf EndSub PrivateSubCommand9_Click() IfLen(Text1.Text)>=2Then Text1.Text=Left(Text1.Text,Len(Text1.Text)-1) Else Text1.Text="" EndIf EndSub PrivateSubform_load() pi=4*Atn (1) pointflag=False clearFlag=False EndSub PrivateSubcommand7_click() UnloadForm4 EndSub PrivateSubcommand8_click() Text1.Text="" EndSub PrivateSubLabel1_Click() Label1.Caption=Time EndSub PrivateSubTimer1_Timer() Label1.Caption=Time EndSub PrivateSubnumberic(sAsInteger) EndSub
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB计算器界面设计+ 全部代码 VB 计算器 界面设计 全部 代码