1、VB计算器界面设计全部代码VB计算器此计算器能够实现加减乘除等一系列的功能。还有实现显示系统时间的附加功能。程序设计:0-9和点在command1的组内。其他的按钮式运算符和其他功能。正切和余切有对特殊值进行警告, 除也有对除数为零的情况提示警告, 还有阶乘等一系列计算溢出的情况提出警告,还有很多需要完善。 。这仅供参考。Public sum As DoublePublic k As Stri ngPublic dia n As Boolea nPublic b As In tegerPublic poin tflag As Boolea nDim clearFlag As Boolea nP
2、ublic F As LongDim start As boole nPublic resl As Boolean 运算结果存储在 resl里Public ff As Double resl 里是否为空数字按钮在一个组内,点llllllllllllllllllllllllllllllllllllllllllllllllllllllll击按钮输入数字 lllllllllllllllllllllllllllllllllllllllllllPrivate Sub comma nd1_click(l ndex As In teger)Select Case In dexCase 1If Not cle
3、arFlag The n 不是等号,那么显示 1Text1.Text = Text1.Text & 1Else 是等号,那么清空Text1.Text = 1clearFlag = FalseEnd IfIf Len(Text1.Text) = 2 And InStr(1, Text1, 0) = 1 Then Text1 = Right(Text1, 1)如果第一位的数位 0,字符串的长度为 2.那么取字符串右面的数,即两个数中右面的数Case 2If Not clearFlag ThenText1.Text = Text1.Text & 2ElseText1.Text = 2clearFla
4、g = FalseEnd IfIf Len (Text1.Text) = 2 And In Str(1, Text1, 0) = 1 The n Text1 : Case 3If Not clearFlag The nText1.Text = Text1.Text & 3Else=Right(Text1, 1)Text1.Text clearFlag = End If=3FalseIf Len (Text1.Text) = 2 And In Str(1, Text1, 0) = 1 The n Text1 :=Right(Text1, 1)Case 4If Not clearFlag The
5、nText1.Text=Text1.Text & 4ElseText1.Text=4clearFlag =FalseEnd IfIf Len (Text1.Text) = 2 And In Str(1, Text1, 0) = 1 The n Text1 :=Right(Text1, 1)Case 5If Not clearFlag ThenTextl.Text = Textl.Text & 5ElseTextl.Text = 5clearFlag = FalseEnd IfIf Len(Text1.Text) = 2 And InStr(1, Text1, 0)=1 The n Text1
6、=Right(Text1, 1)Case 6If Not clearFlag The nText1.Text=Text1.Text & 6ElseText1.Text=6clearFlag = End IfFalseIf Len(Text1.Text) = 2 And InStr(1, Text1, 0)=1 The n Text1 =Right(Text1, 1)Case 7If Not clearFlag The nText1.Text = Text1.Text & 7ElseTextl.Text = 7clearFlag = FalseEnd IfIf Len(Textl.Text) =
7、 2 And InStr(1, Textl, 0) = 1 Then Textl = Right(Text1, 1)Case 8If Not clearFlag The nTextl.Text = Textl.Text & 8ElseTextl.Text = 8clearFlag = FalseEnd IfIf Len(Textl.Text) = 2 And InStr(1, Textl, 0) = 1 Then Textl = Right(Text1, 1)Case 9If Not clearFlag The nText1.Text = Text1.Text & 9ElseText1.Tex
8、t = 9clearFlag = FalseEnd IfIf Len(Text1.Text) = 2 And InStr(1, Text1, 0) = 1 Then Text1 = Right(Text1, 1)Case 0If Not clearFlag ThenTextl.Text = Textl.Text & 0ElseText1.Text = 0 clearFlag = False End IfIf Len(Text1.Text) = 2 And InStr(1, Text1, 0) = 1 Then Text1 = Right(Text1, 1)Case 10If Not clear
9、Flag The nText1.Text = Text1.Text + .ElseText1.Text =clearFlag = FalseEnd If7/ 对输入点 的个数进行约 束/If (In Str(Text1.Text, .)=1) The n对点的处理,检查是否有点,有点再输入的话为空,否则加入其中Textl.Text =End IfIf InStr(Text1.Text, .) Len(Textl.Text) Then Textl.Text = Left(Text1.Text, Len(Textl.Text) - 1) End IfEnd SelectText1.SetFocus
10、End Sub定义加号按钮 /Private Sub comma nd2_click()If Text1.Text = The nEnd IfIf Trim(Text1.Text) Thensum = Text1.TextText1.Text =k = +ElseExit SubEnd IfEnd Sub7/ 定义减号按钮 /Private Sub comma nd3_click()If Text1.Text = ThenEnd IfIf Trim(Text1.Text) The nsum = Text1.Text 第一个数字填入方框里Text1.Text = 方框的值置空k =-ElseEx
11、it SubEnd IfEnd Sub/ 定义乘号按钮 /Private Sub comma nd4_click()If Text1.Text = The nEnd IfIf Trim(Text1.Text) Then sum = Text1.TextText1.Text =k = *ElseExit SubEnd IfEnd Sub定 义 除 号 按 钮/Private Sub comma nd5_click()If Text1.Text = ThenEnd IfIf Trim(Text1.Text) Then sum = Text1.TextText1.Text =k = /ElseExi
12、t SubEnd IfEnd SubIIIIIIIIIIIIIIIIIIIIIIIIIIII 定 义 sin 号 按 钮/Private Sub comma nd1O_click()If Text1.Text = ThenEnd IfIf Trim(Text1.Text) The nsum = Text1.Textk = si nElseExit SubEnd IfEnd Sub/ 定 义 cos 按 钮/Private Sub comma nd11_click()If Text1.Text = The nEnd IfIf Trim(Text1.Text) The nsum = Text1.T
13、extk =cosElseExit SubEnd IfEnd Sub/ 定义 tan 按钮 /Private Sub comma nd12_click()If Text1.Text = The nEnd IfIf Trim(Text1.Text) The nsum = Text1.Textk = tanElseExit SubEnd IfEnd Sub/ 定义 cot 按钮 /Private Sub comma nd13_click()If Text1.Text = The nEnd IfIf Trim(Text1.Text) Then sum = Textl.Textk = cotElseE
14、xit SubEnd IfEnd Sub7/ 定义人按钮 /Private Sub Comma nd14_click()If Textl.Text = The nExit SubEnd IfIf Trim(Textl.Text) The nsum = Textl.TextTextl.Text =k = AElseExit SubEnd IfEnd Sub/ 定 义 2A/Private Sub comma nd15_click()If Textl.Text = The nExit SubEnd IfIf Trim(Textl.Text) The nsum = Textl.Textk = 2人E
15、lseExit SubEnd IfEnd Sub/ 定义 3A 按钮 /Private Sub comma nd16_click()If Textl.Text = The nExit SubEnd IfIf Trim(Textl.Text) The nsum = Textl.Textk = 3AElseExit SubEnd IfEnd SubIIIIIIIIIIIIIIIIIIII 定义 X!按钮 /Private Sub comma nd17_click()If Text1.Text = The nExit SubEnd IfIf Trim(Text1.Text) The nsum = T
16、ext1.Textk = x!ElseExit SubEnd IfEnd Sub/ 定义 sqrt 按钮 /Private Sub comma nd18_click()If Text1.Text = The nExit SubEnd IfIf Trim(Text1.Text) The nsum = Text1.Textk = sqrtElseExit SubEnd IfEnd Sub/ 定义阶乘的函数 /Private Fu nction Ni(N As Long) As Boolea n Ni = FalseDim Mm As Long Dim F1 As Lo ngF = 1For Mm
17、= 1 To NIf Mm 12 The n If F1 The n Ni = False Exit Fun cti on End IfF = F * MmNext MmNi = TrueEnd FunctionPrivate Sub equalbut_click() clearFlag = FalseEnd SubPrivate Sub comma nd6_click()If Trim(Text1.Text) Then Dim F As DoubleDim a As DoubleDim pi As DoubleDim i, j As In tegerpi = 3.14159265358979
18、If Text1.Text 2147483647 ThenMsgBox 溢出,请确认, vbExclamation, Me.CaptionExit SubEnd If a = Text1.Text clearFlag = TrueIf k = + Then sum = sum + a Text1.Text = sumElseIf k = s in The n sum = Sin(a * pi / 180) Textl.Text = sumElseIf k = cos ThenDim t As In tegert = a Mod 180 - 90If t = 0 ThenText1.Text =
19、 0Elsesum = Cos(a * pi / 180)Textl.Text = sumEnd IfElseIf k = tan ThenDim m As In tegerDim N As In tegerIf m = 0 The nMsgBox Elsem = a Mod 180 - 90(90+180*n )度的正切值无意义,请重新输入sum = (Tan(a * pi / 180)Textl.Text = sumEnd IfElseIf k = cot The nIf a = 0 The nMsgBox 0 度余切没有意义!请重新输入!Elsesum = 1 / (Tan(a * pi
20、 / 180)Textl.Text = sumEnd IfElseIf k = x! The nIf Text1.Text 0 The nCall fact(Text1.Text, F) Text1.Text = FElseIf Text1.Text = 0 The nsum = 1 Text1.Text = sumElseIf Text1.Text = 0 The nsum = Math.Sqr(a)Textl.Text = sumElseMsgBox 开方数不能为负数! ”End If减法运算Elself k = A The n sum = sum a a Textl.Text = sum
21、Elself k = - The n sum = sum - a Textl.Text = sumresl = 1Elself k = * The n sum = sum * a Textl.Text = sumElself k = / The nIf Textl.Text = 0 The nMsgBox 除数不能为零!请重新输入Textl.Text =Elsesum = sum / aTextl.Text = sumIf Len( Textl.Text) 14 The nMsgBox 溢出,请确认, vbExclamation, Me.CaptionExit SubEnd IfExit Su
22、bEnd IfEnd IfEnd IfEnd SubPrivate Sub Comma nd9_Click()If Len(Text1.Text) = 2 ThenText1.Text = Left(Text1.Text, Len(Text1.Text) - 1)ElseText1.Text =End IfEnd SubPrivate Sub form。ad()pi = 4 * Atn(1)poin tflag = FalseclearFlag = FalseEnd SubPrivate Sub comma nd7_click()Uni oad Form4End SubPrivate Sub comma nd8_click()Textl.Text =End SubPrivate Sub Label1_Click()Label1.Capti on = TimeEnd SubPrivate Sub Timer1_Timer()Label1.Capti on = TimeEnd SubPrivate Sub nu mberic(s As In teger)End Sub
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2