vb复数计算器
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 nPublic F As Long'Dim 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 dex Case 1If Not clearFlag The n ' 不是等号,那么显示 1 Text1.Text = Text1.Text & 1 Else'是等号,那么清空Text1.Text = 1 clearFlag = False End IfIf Len(Text1.Text) = 2 And InStr(1, Text1, "0") = 1 Then Text1 = Right(Text1, 1) '如果第一位的数位 0,字符串的长度为 2.那么取字符串右面的数,即两个数中右面的数Case 2If Not clearFlag Then Text1.Text = Text1.Text & 2 ElseText1.Text = 2 clearFlag = False End IfIf Len (Text1.Text) = 2 And In Str(1, Text1, "0") = 1 The n Text1 : Case 3 If Not clearFlag The n Text1.Text = Text1.Text & 3 Else=Right(Text1, 1)Text1.Text clearFlag = End If=3 False If Len (Text1.Text) = 2 And In Str(1, Text1, "0") = 1 The n Text1 : =Right(Text1, 1)Case 4If Not clearFlag The 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 & 5 ElseTextl.Text = 5 clearFlag = False End IfIf Len(Text1.Text) = 2 And InStr(1, Text1, "0")= =1 The n Text1 ==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 n Text1.Text = Text1.Text & 7 ElseTextl.Text = 7 clearFlag = False End IfIf Len(Textl.Text) = 2 And InStr(1, Textl, "0") = 1 Then Textl = Right(Text1, 1) Case 8If Not clearFlag The n Textl.Text = Textl.Text & 8 ElseTextl.Text = 8 clearFlag = False End IfIf Len(Textl.Text) = 2 And InStr(1, Textl, "0") = 1 Then Textl = Right(Text1, 1) Case 9If Not clearFlag The n Text1.Text = Text1.Text & 9 ElseText1.Text = 9 clearFlag = False End IfIf Len(Text1.Text) = 2 And InStr(1, Text1, "0") = 1 Then Text1 = Right(Text1, 1) Case 0定义加号按钮 //////////////////////////////////////If Not clearFlag Then Textl.Text = Textl.Text & 0 ElseText1.Text = 0 clearFlag = False End IfIf Len(Text1.Text) = 2 And InStr(1, Text1, "0") = 1 Then Text1 = Right(Text1, 1) Case 10If Not clearFlag The n Text1.Text = Text1.Text + "." ElseText1.Text ="" clearFlag = False End 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 End Sub '////////////////////////Private Sub comma nd2_click() If Text1.Text = "" The n End IfIf Trim(Text1.Text) <> "" Then sum = Text1.Text Text1.Text ="" k = "+" Else Exit Sub End If End Sub 7////////////////////////定义减号按钮 ////////////////////////////////////// Private Sub comma nd3_click()定义除号按钮If Text1.Text = "" Then End IfIf Trim(Text1.Text) <> "" The n sum = Text1.Text ' 第一个数字填入方框里 Text1.Text =""' 方框的值置空k ="-" Else Exit Sub End If End Sub '///////////////////////定义乘号按钮 ////////////////////////////////////////Private Sub comma nd4_click()If Text1.Text = "" The n End IfIf Trim(Text1.Text) <> "" Then sum = Text1.Text Text1.Text ="" k = "*" Else Exit Sub End If End Sub '/////////////////////////////////////////////////////////////////// Private Sub comma nd5_click() If Text1.Text = "" Then End IfIf Trim(Text1.Text) <> "" Then sum = Text1.Text Text1.Text ="" k = "/" Else Exit Sub End If End Sub'IIIIIIIIIIIIIIIIIIIIIIIIIIII 定 义sin号 按钮/////////////////////////////////////Private Sub comma nd1O_click() If Text1.Text = "" Then End IfIf Trim(Text1.Text) <> "" The n sum = Text1.TextElseExit SubEnd IfEnd Sub'///////////////////////////// 定义cos 按钮/////////////////////////////////////Private Sub comma nd11_click()If Text1.Text = "" The nEnd IfIf Trim(Text1.Text) <> "" The nsum = Text1.Textk ="cos"ElseExit SubEnd IfEnd Sub'///////////////////////////// 定义tan 按钮////////////////////////////////////Private Sub comma nd12_click()If Text1.Text = "" The nEnd IfIf Trim(Text1.Text) <> "" The nsum = Text1.Textk = "tan"ElseExit SubEnd IfEnd Sub'////////////////////////// 定义cot 按钮//////////////////////////////////////Private Sub comma nd13_click()If Text1.Text = "" The nEnd IfIf Trim(Text1.Text) <> "" Then sum = Textl.Textk = "cot"ElseExit SubEnd IfEnd Sub7////////////////////////// 定义人按钮///////////////////////////////////////Private Sub Comma nd14_click()If Textl.Text = "" The nExit SubIf Trim(Textl.Text) <> "" The nsum = Textl.TextTextl.Text =""k = "A"ElseExit SubEnd IfEnd Sub'///////////////////////// 定义2A ///////////////////////////////////////////Private Sub comma nd15_click()If Textl.Text = "" The nExit SubEnd IfIf Trim(Textl.Text) <> "" The nsum = Textl.Textk = "2人"ElseExit SubEnd IfEnd Sub'/////////////////////// 定义3A 按钮/////////////////////////////////////////// Private Sub comma nd16_click()If Textl.Text = "" The nExit SubEnd IfIf Trim(Textl.Text) <> "" The nsum = Textl.Textk = "3A"ElseExit SubEnd IfEnd Sub'IIIIIIIIIIIIIIIIIIII定义X!按钮///////////////////////////////////////////// Private Sub comma nd17_click()If Text1.Text = "" The nExit SubEnd IfIf Trim(Text1.Text) <> "" The nsum = Text1.Textk = "x!"ElseExit SubEnd If'////////////////// 定义sqrt 按钮////////////////////////////////////////////// Private Sub comma nd18_click()If Text1.Text = "" The nExit SubEnd IfIf Trim(Text1.Text) <> "" The nsum = Text1.Textk = "sqrt"ElseExit 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 = 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.14159265358979If 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 = 0If m = 0 The n MsgBox " ElseElsesum = Cos(a * pi / 180) Textl.Text = sum End IfElseIf k = "tan" Then Dim m As In teger Dim N As In teger m = a Mod 180 - 90(90+180*n )度的正切值无意义,请重新输入 sum = (Tan(a * pi / 180)) Textl.Text = sum End IfElseIf k = "cot" The n If a = 0 The n MsgBox "0 度余切没有意义!请重新输入!Elsesum = 1 / (Tan(a * pi / 180)) Textl.Text = sum End If'ElseIf k = "x!" The n 'If Text1.Text > 0 The n 'Call fact(Text1.Text, F) ' Text1.Text = F'ElseIf Text1.Text = 0 The n 'sum = 1' Text1.Text = sum'ElseIf Text1.Text < 0 The n 'MsgBox " 负数没有阶乘! ”'End If减法运算Elself k = "x!" The nIf Ni(Textl.Text) = False The nMsgBox "溢出", vbExclamation, Me.CaptionText1.Text =""Exit SubElseText1.Text = FEnd IfElself k = "2A " The nTextl.Text = Val(Textl.Text) * Val(Textl.Text)Elself k = "3A" The nTextl.Text = Val(Textl.Text) * Val(Textl.Text) * Val(Textl.Text) Elself k = "sqr" The nIf a >= 0 The nsum = Math.Sqr(a)Textl.Text = sumElseMsgBox "开方数不能为负数!”End If Elself k = "A" The n sum =sum A a Textl.Text = sum Elself k = "-" The n sum = sum - a Textl.Text = sum resl = 1Elself k = "*" The n sum = sum * a Textl.Text = sum Elself k = "/" The nIf Textl.Text = 0 The nMsgBox "除数不能为零!请重新输入Textl.Text =""Elsesum = sum / aTextl.Text = sumIf Len( Textl.Text) > 14 The nMsgBox "溢出,请确认", vbExclamation, Me.Caption Exit SubEnd IfExit SubEnd 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」。
VB简单计算器(截图附代码)
VB程序简单计算器最近学完VB,感觉很好,写了个计算器程序,虽然花了不少时间,可也着实高兴。
其中遇到很多问题,最终也在各种资料中得到解决。
现在附上截图和全部代码,希望和大家交流一下,相互学习。
也希望能帮助到准备做计算器的同学。
计算器最终执行文件图标:计算器包括三个窗体(form):主页面form1:其中的“欢迎各位到此一游”是闪烁效果,呵呵,是自己想着无聊,就想出这么个玩意。
与计算器计算功能无关。
具体实现看下来代码。
Form1的实现代码:Public haha As BooleanPrivate Sub Command1_Click()Dim a As Integera = MsgBox("亲爱的你,真的想要退出本系统吗?", _vbYesNo + vbInformation + vbDefaultButton1, "退出系统前的询问撒(⊙o⊙)")If a = 6 Then '表示当选择“是”的时候的返回值EndEnd IfEnd SubPrivate Sub Command2_Click()Me.HideForm2.ShowEnd SubPrivate Sub Command3_Click()Me.HideForm3.ShowEnd SubPrivate Sub Form_Load()haha = FalseEnd SubPrivate Sub Timer1_Timer()haha = Not hahaIf haha ThenLabel2.ForeColor = &HFF00FFElseLabel2.ForeColor = vbWhiteEnd IfEnd Sub有些像图像等一些可见的控件属性就没在代码里写了,直接在属性里设置了。
页面(form2):此页面将鼠标点上去,还有意想不到的效果喲。
全部代码为:Dim isFocus1, isFocus2 As BooleanPrivate Sub Command1_Click()If isFocus1 Then '判断焦点在那个文本框中,便于实现按钮输入Text1.Text = Text1.Text & 0End IfIf isFocus2 ThenText2.Text = Text2.Text & 0End IfEnd SubPrivate Sub Command10_Click() If isFocus1 ThenText1.Text = Text1.Text & 9 End IfIf isFocus2 ThenText2.Text = Text2.Text & 9 End IfEnd SubPrivate Sub Command11_Click() If isFocus1 ThenText1.Text = Text1.Text & "." End IfIf isFocus2 ThenText2.Text = Text2.Text & "." End IfEnd SubPrivate Sub Command12_Click() If isFocus1 ThenText1.Text = -Val(Text1.Text)End IfIf isFocus2 ThenText2.Text = -Val(Text2.Text)End IfEnd SubPrivate Sub Command13_Click()Dim a As Integera = Val(Text1.Text) + Val(Text2.Text)Text3.Text = Val(Text1.Text) & "+" & Val(Text2.Text) & "=" & aIf Text1.Text = "" Or Text2.Text = "" ThenMsgBox "哼哼,双目运算一定要是两个数喔" & vbCrLf & vbCrLf & _ "不用说,补上去是必须的撒", vbCritical, "温馨小提醒(*^__^*)" End IfEnd SubPrivate Sub Command14_Click()Dim a As Integera = Val(Text1.Text) - Val(Text2.Text)Text3.Text = Val(Text1.Text) & "-" & Val(Text2.Text) & "=" & aIf Text1.Text = "" Or Text2.Text = "" ThenMsgBox "哼哼,双目运算一定要是两个数喔" & vbCrLf & vbCrLf & _ "不用说,补上去是必须的撒", vbCritical, "温馨小提醒(*^__^*)" End IfEnd SubPrivate Sub Command15_Click()a = Val(Text1.Text) * Val(Text2.Text)Text3.Text = Val(Text1.Text) & "×" & Val(Text2.Text) & "=" & aIf Text1.Text = "" Or Text2.Text = "" ThenMsgBox "哼哼,双目运算一定要是两个数喔" & vbCrLf & vbCrLf & _ "不用说,补上去是必须的撒", vbCritical, "温馨小提醒(*^__^*)" End IfEnd SubPrivate Sub Command16_Click() '除法的特殊性,除数不能为零If Val(Text2.Text) Thena = Val(Text1.Text) / Val(Text2.Text)Text3.Text = Val(Text1.Text) & "÷" & Val(Text2.Text) & "=" & aIf Text1.Text = "" Or Text2.Text = "" ThenMsgBox "哼哼,双目运算一定要是两个数喔" & vbCrLf & vbCrLf & _ "不用说,补上去是必须的撒", vbCritical, "温馨小提醒(*^__^*)" End IfElseText3.Text = "无穷大∞"MsgBox "亲,除数不可以为零的哟!", vbInformation, "矮油,不得了嘞(*^__^*)"Text2.Text = ""Text2.SetFocusEnd IfEnd SubPrivate Sub Command17_Click() '实现清零,并将焦点给文本框1Text1.Text = ""Text2.Text = ""Text3.Text = ""Text1.SetFocusEnd SubPrivate Sub Command18_Click()Me.Hide '进入计算器1Form1.ShowEnd SubPrivate Sub Command2_Click() If isFocus1 ThenText1.Text = Text1.Text & 1 End IfIf isFocus2 ThenText2.Text = Text2.Text & 1 End IfEnd SubPrivate Sub Command3_Click() If isFocus1 ThenText1.Text = Text1.Text & 2 End IfIf isFocus2 ThenText2.Text = Text2.Text & 2 End IfEnd SubPrivate Sub Command4_Click() If isFocus1 ThenText1.Text = Text1.Text & 3 End IfIf isFocus2 ThenText2.Text = Text2.Text & 3 End IfEnd SubPrivate Sub Command5_Click() If isFocus1 ThenText1.Text = Text1.Text & 4 End IfIf isFocus2 ThenText2.Text = Text2.Text & 4 End IfEnd SubPrivate Sub Command6_Click() If isFocus1 ThenText1.Text = Text1.Text & 5 End IfIf isFocus2 ThenText2.Text = Text2.Text & 5 End IfEnd SubPrivate Sub Command7_Click() If isFocus1 ThenText1.Text = Text1.Text & 6 End IfIf isFocus2 ThenText2.Text = Text2.Text & 6 End IfEnd SubPrivate Sub Command8_Click() If isFocus1 ThenText1.Text = Text1.Text & 7 End IfIf isFocus2 ThenText2.Text = Text2.Text & 7 End IfEnd SubPrivate Sub Command9_Click() If isFocus1 ThenText1.Text = Text1.Text & 8End IfIf isFocus2 ThenText2.Text = Text2.Text & 8End IfEnd SubPrivate Sub Form_Load()isFocus1 = False: isFocus2 = FalseEnd SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Label4.ForeColor = vbBlackLabel4.FontUnderline = FalseLabel4.FontBold = FalseEnd SubPrivate Sub Label4_Click()Form3.ShowEnd SubPrivate Sub Label4_MouseMove(Button As Integer, Shift As Integer, X AsSingle, Y As Single)Label4.ForeColor = vbGreen Label4.FontUnderline = True Label4.FontBold = True End SubPrivate Sub Text1_GotFocus() isFocus1 = TrueisFocus2 = FalseEnd SubPrivate Sub Text2_GotFocus() isFocus2 = TrueisFocus1 = FalseEnd Sub页面(form3):这里面的亮点自己找哦。
VB简易计算器的制作
问题四: 语句格式是什么? 问题四:select case 语句格式是什么?
Select Case 表达式 Case 表达式值一 语句块一 Case 表达式值二 语句块二 … Case Else 语句块n 语句块 End Select
制作界面
一、先作一个框架frame1,清空frame1的 caption属性。(作用?) 二、拉出一个文本框,设置为右对齐。 (作用?) 三、拉出一组“cmdshu”的命令按钮控件数 组, caption分别为 “0”,“1”,“2”,“3”,“4”,“5”, “6”,“7”,“8”,“9”,“.”。 index的值分别为0,1,2,3,4,5,6,用开始输入? 怎样判断应该用连接或者用开始输入?
答:可以添加一个用来判断的变量 问题三: 问题三:
怎样判断该用什么运算? 怎样判断该用什么运算? 可以用一个变量记住点击的运算符, 答:可以用一个变量记住点击的运算符,即 是记住点击时返回的index值。然后用select case 值 然后用 是记住点击时返回的 语句。 语句。
制作界面
四、拉出一组“cmdsuanfu”的命令按钮控件数 组,caption分别为“+”,“-”,“*”,“/”。index的值分 别为0,1,2,3。 cmdresult” 五、拉出一个“cmdresult” 的命令按钮。
算法
将输入文本框的第一个数作为num1, 将输入文本框的第二个数作为num2,然后按 照所选择的运算,算出结果输出到文本框。
将输入文本框的第一个数作为num1将输入文本框的第二个数作为num2然后按照所选择的运算算出结果输出到文本框
简易计算器的制作 简易计算器的制作 计算器
广东广雅中学
控件数组的使用
vb计算器 简单程序(包含 进制转换 )
Option ExplicitDim s1 As Integer, N As Single, r As IntegerPrivate Sub Command1_Click(Index As Integer) Text1.Text = Text1.Text & IndexEnd Sub'CEPrivate Sub Command11_Click()Text1.Text = ""End SubPrivate Sub Command12_Click()Text1.Text = (Text1.Text) ^ 2End SubPrivate Sub Command17_Click()Text1.Text = " "End SubPrivate Sub Command18_Click()Text1.Text = (Text1.Text) ^ 3End SubPrivate Sub Command20_Click()If Text1.Text = "" ThenMsgBox ("²Ù×÷´íÎó")ElseText1.Text = Val(Text1.Text) * (-1)End IfEnd SubPrivate Sub Command21_Click()If InStr(Text1.Text, ".") ThenMsgBox ("СÊýµãÒÑ´æÔÚ")ElseText1.Text = Text1 & Chr(46)End IfEnd SubPrivate Sub Command23_Click()If N = 1 ThenIf Text1.Text = 0 ThenMsgBox "³ýÊý²»ÄÜΪÁã"ElseText1 = s1 / Text1.TextEnd IfElseIf N = 2 ThenText1 = s1 * Text1.TextElseIf N = 3 ThenText1 = s1 - Text1.TextElseIf N = 4 ThenText1 = s1 + Text1.TextEnd IfEnd SubPrivate Sub Command24_Click()Text1.Text = 1 / Text1.TextEnd SubPrivate Sub Command25_Click(Index As Integer) Select Case IndexCase 0Text1.Text = Text1.Text & "A"Case 1Text1.Text = Text1.Text & "B"Case 2Text1.Text = Text1.Text & "C"Case 3Text1.Text = Text1.Text & "D"Case 4Text1.Text = Text1.Text & "E"Case 5Text1.Text = Text1.Text & "F"End SelectEnd SubPrivate Sub Command4_Click(Index As Integer) Select Case IndexCase 0N = 1s1 = Text1.TextText1.Text = ""Case 1N = 2s1 = Text1.TextText1.Text = ""Case 2N = 3s1 = Text1.TextText1.Text = ""Case 3N = 4s1 = Text1.TextText1.Text = ""End SelectEnd SubPrivate Sub Command5_Click()Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) End SubPrivate Sub Command6_Click()Text1.Text = Sqr(Text1.Text)End SubPrivate Sub Form_Load()r = 10End Sub'Ê®Áù½øÖÆPrivate Sub Option1_Click()Command25(1).Enabled = TrueCommand25(0).Enabled = TrueCommand25(2).Enabled = TrueCommand25(3).Enabled = TrueCommand25(4).Enabled = TrueCommand25(5).Enabled = TrueCommand1(6).Enabled = TrueCommand1(9).Enabled = TrueCommand1(2).Enabled = TrueCommand1(3).Enabled = TrueCommand1(4).Enabled = TrueCommand1(5).Enabled = TrueCommand1(7).Enabled = TrueIf r = 10 ThenText1.Text = trandec(Val(Text1.Text), 16) ElseText1.Text = Two16(Text1.Text)End Ifr = 16End Sub'Ê®½øÖÆPrivate Sub Option2_Click()Command1(6).Enabled = TrueCommand1(9).Enabled = TrueCommand1(2).Enabled = TrueCommand1(3).Enabled = TrueCommand1(4).Enabled = TrueCommand1(5).Enabled = TrueCommand1(8).Enabled = TrueCommand1(7).Enabled = TrueCommand25(0).Enabled = FalseCommand25(1).Enabled = FalseCommand25(2).Enabled = FalseCommand25(3).Enabled = FalseCommand25(4).Enabled = FalseCommand25(5).Enabled = FalseText1.Text = Convert(Text1.Text, r)r = 10End Sub'¶þ½øÖÆPrivate Sub Option3_Click()Command1(6).Enabled = FalseCommand1(9).Enabled = FalseCommand1(2).Enabled = FalseCommand1(3).Enabled = FalseCommand1(4).Enabled = FalseCommand1(5).Enabled = FalseCommand1(8).Enabled = FalseCommand1(7).Enabled = FalseCommand25(0).Enabled = FalseCommand25(1).Enabled = FalseCommand25(2).Enabled = FalseCommand25(3).Enabled = FalseCommand25(4).Enabled = FalseIf r = 10 ThenText1.Text = trandec(Val(Text1.Text), 2)ElseText1.Text = HEX_to_BIN(Text1.Text)End Ifr = 2End SubPrivate Sub Text1_Change()If Mid(Text1.Text, 1, 1) = "." ThenText1.Text = 0 & Text1.TextEnd IfEnd Sub'Ê®½øÖÆת¶þºÍÊ®Áù½øÖÆPublic Function trandec$(ByVal m%, ByVal r%)Dim strdtor$Dim iB%, mr%strdtor = ""Do While m <> 0mr = m Mod rm = m \ rIf mr >= 10 Thenstrdtor = Chr(mr - 10 + 65) & strdtorElsestrdtor = mr & strdtorEnd IfLooptrandec = strdtorEnd FunctionPublic Function Convert(ByVal S As String, ByVal N As Integer) As Double 'ÈÎÒâ½øÖÆת»»³É10½øÖÆDim L As StringDim r() As StringDim i As IntegerDim j As IntegerL = "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W |X|Y|Z" '½øÖÆ×Ö·û´®×Öµär = Split(L, "|")For i = 1 To Len(S)For j = 0 To UBound(r)If UCase(Mid(S, i, 1)) = r(j) ThenConvert = Convert * N + jEnd IfNext jNext iEnd FunctionPrivate Function Two16(ByVal X As String) As String '°Ñ¶þ½øÖÆÊýת»¯ÎªÊ®Áù½øÖÆÊýDo While Len(X) Mod 4 <> 0X = "0" + XLoopDo While Len(X) > 0Select Case Right(X, 4)Case "0000"Two16 = "0" + Two16Case "0001"Two16 = "1" + Two16Case "0010"Two16 = "2" + Two16Case "0011"Two16 = "3" + Two16Case "0100"Two16 = "4" + Two16Case "0101"Two16 = "5" + Two16Case "0110"Two16 = "6" + Two16Case "0111"Two16 = "7" + Two16Case "1000"Two16 = "8" + Two16Case "1001"Two16 = "9" + Two16Case "1010"Two16 = "A" + Two16Case "1011"Two16 = "B" + Two16Case "1100"Two16 = "C" + Two16Case "1101"Two16 = "D" + Two16Case "1110"Two16 = "E" + Two16Case "1111"Two16 = "F" + Two16End SelectX = Left(X, Len(X) - 4)LoopEnd Function'Ê®Áùת¶þPublic Function HEX_to_BIN(ByVal Hex As String) As String Dim i As LongDim B As StringHex = UCase(Hex)For i = 1 To Len(Hex)Select Case Mid(Hex, i, 1)Case "0": B = B & "0000"Case "1": B = B & "0001"Case "2": B = B & "0010"Case "3": B = B & "0011"Case "4": B = B & "0100"Case "5": B = B & "0101"Case "6": B = B & "0110"Case "7": B = B & "0111"Case "8": B = B & "1000"Case "9": B = B & "1001"Case "A": B = B & "1010"Case "B": B = B & "1011"Case "C": B = B & "1100"Case "D": B = B & "1101"Case "E": B = B & "1110"Case "F": B = B & "1111"End SelectNext iDo While Left(B, 1) = "0"B = Right(B, Len(B) - 1)LoopHEX_to_BIN = BEnd Function。
最新如何制作一个VB计算器
如何制作一个V B计算器如何制作一个VB计算器功能说明:支持加、减、乘、除、取反、阶乘、x的y次方、括号按键重新分配、提高了工作效率窗口过渡动画实时输入纠错,计算纠错其它经典实用的小功能期待发现与添加界面预览:前期准备:有Microsoft Visual Basic 开发平台,懂基本的VB语法(有明白时查资料就行了)计算顺序为()、!、^、*/、取反、加减算法为:①首先扫描出()内需要优先计算的部分,将这部分用来计算②依照计算顺序进行计算③用计算结果替换原()联同()内表达式④循环①~③直至只剩下一个数据⑤结果的处理主要内容:怎样扫描出各个计算符号和需要运算的数据,怎样纠错,后面会详细介绍开始动手之窗体设计:(1)新建工程——标准exeForm属性:BordStyle=1,Caption=计算器,FillStyle=1,Height=4455,Width=7995,(近似的黄金分割)Picture自己找一张图片(2)菜单工程——部件——控件——勾选Microsoft Forms 2.0 Object Library——确定(3)在新出现的控件中添加一个Textbox名称=tb,Backstyle=0,Boardstyle=1,Height=3615,Left=0,Top=0,Width=7995,Font适当(4)一个Image名称=img,Height=3615,Left=0,Top=0,Width=7995(尺寸位置与Textbox相同),visibal=false,stretch=true,Picture自己找一张图片(5)在新出现的控件中添加一个Label将长度调整为与窗体同长,高度刚好可以填补视界中两张图片的差,放过去填补这个差,这样应该懂了用意了吧,Backstyle=0,Boardstyle=0,Caption随意,Font适当用鼠标点选这个标签,ctrl+c,ctrl+v创建数组,放到适当位置,重复总共放置5个,包含原来的那个。
VB写简易计算器附图
用V B6.0编写简易计算器效果图:废话不多说,直接上步骤一、创建控件组1、创建控件组的方法??首先创建一个命令按钮,调整其大小(觉得合适就行),名称为Command1,Caption属性为数字 0 ;然后进行“复制”和“粘贴”,当选择“粘贴”时,出现对话框提示已有一个同名控件,询问是否创建控件组,选择“是”后,即创建了一个名为“Command”的控件组。
这时,第一个按钮的Index属性值默认为“0”,第二个的Index属性值自动设为“1”,并且大小与第一个按钮相同,只需修改其 Caption 属性为数字“1”并将其拖至合适位置即可。
此后继续使用“粘贴”的方法建立其他控件组中其余按钮,共20个按钮,每建立一个,就将它拖到合适处,并修改相应的Caption属性值。
二、编写代码Dim s1 As Single, s2 As Single, ysf As String'定义两个单精度数变量用与存放参与运算的数,一个字符型存放运算符Private Sub Command1_Click(Index As Integer)Text1.Text = Text1.Text & Command1(Index).Caption'将command1的单击事件与文本框显示的内容连接End SubPrivate Sub Command2_Click()Text1.Text = Text1.Text + "."If (InStr(Text1.Text, ".") = 1) Then'第一位不能为小数Text1.Text = ""End IfIf InStr(Text1.Text, ".") < Len(Text1.Text) Then '防止出现两个小数点Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)End IfEnd SubPrivate Sub Command3_Click()s2 = Val(Text1.Text) '开始加减乘除运算Select Case ysfCase "+"Text1.Text = s1 + s2Case "-"Text1.Text = s1 - s2Case "*"Text1.Text = s1 * s2Case "/"If s2 = 0 ThenMsgBox "分母不能为零!"Text1.Text = ""ElseText1.Text = s1 / s2End IfEnd SelectText1 = IIf(Left(Text1.Text, 1) = ".", 0 & Text1.Text, Text1.Text) '这个很关键,如果没有这个的话,得出小于1的小数前面没有0End SubPrivate Sub Command4_Click()If Text1.Text = "" Then '文本为空就结束Exit SubEnd IfText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) '文本退一格End SubPrivate Sub Command5_Click()Text1.Text = "" '清除当前框内文本End SubPrivate Sub Command6_Click(Index As Integer)s1 = Val(Text1.Text) '将s1隐藏起来ysf = Command6(Index).CaptionText1.Text = ""End SubPrivate Sub Command7_Click()If Left(Text1.Text, 1) <> "-" Then '判断作为负数Text1.Text = "-" & Text1.TextElseText1.Text = Right(Text1.Text, Len(Text1.Text) - 1)End IfEnd SubPrivate Sub Command8_Click()Text1.Text = Text1.Text * Text1.Text '平方End Sub各位朋友,可以将红色代码复制到相应位置,不清楚的可以全选复制,但是一定要按照我的步骤和给的名称来哦!还可以再添加按钮Private Sub Command9_Click() '这是退出代码EndEnd Sub三、测试,成功的话给个好评哦!谢谢各位下载与支持!这个可以编写作为作业哦!。
使用VB制作计算器程序
多功能计算器界面如下图所示。
实现代码如下:Public b As SinglePublic flag, first As IntegerDim narray(100) As Single '存放文本框1中输入的多个数据Dim i As Integer '存放输入数组的实际长度'单次运算Dim a As Single '存放第一个操作数Dim key As String '存放运算符'以上在模块中定义变量Private Sub cmd0_Click() '单击数字键0Text1.Text = Text1.Text + cmd0.Caption '可用"&"代替"+"End SubPrivate Sub cmd1_Click() '单击数字键1Text1.Text = Text1.Text + cmd1.CaptionEnd SubPrivate Sub cmd2_Click() '单击数字键2Text1.Text = Text1.Text + cmd2.CaptionEnd SubPrivate Sub cmd3_Click() '单击数字键3Text1.Text = Text1.Text + cmd3.CaptionEnd SubPrivate Sub cmd4_Click() '单击数字键4Text1.Text = Text1.Text + cmd4.CaptionEnd SubPrivate Sub cmd5_Click() '单击数字键5Text1.Text = Text1.Text + cmd5.CaptionEnd SubPrivate Sub cmd6_Click() '单击数字键6Text1.Text = Text1.Text + cmd6.CaptionEnd SubPrivate Sub cmd7_Click() '单击数字键7Text1.Text = Text1.Text + cmd7.CaptionEnd SubPrivate Sub cmd8_Click() '单击数字键8Text1.Text = Text1.Text + cmd8.CaptionEnd SubPrivate Sub cmd9_Click() '单击数字键9Text1.Text = Text1.Text + cmd9.CaptionEnd SubPrivate Sub cmddot_Click() '连接小数点Text1.Text = Text1.Text + cmddot.CaptionIf InStr(Text1.Text, ".") < Len(Text1.Text) Then'防止出现多个小数点Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)End IfEnd SubPrivate Sub cmdcls_Click() '单击CE键Text1.Text = ""End SubPrivate Sub add_Click() '单击“+”,保存第一个操作数和运算符 a = Val(Text1.Text)key = add.CaptionText1.Text = " "End SubPrivate Sub subs_Click() '单击“-”a = Val(Text1.Text)key = subs.CaptionText1.Text = " "End SubPrivate Sub mul_Click() '单击“*”a = Val(Text1.Text)key = mul.CaptionText1.Text = " "End SubPrivate Sub div_Click() '单击“/”a = Val(Text1.Text)key = div.CaptionText1.Text = " "End SubPrivate Sub modi_Click() '单击“Mod”a = Val(Text1.Text)key = more.CaptionText1.Text = " "End SubPrivate Sub mulpi_Click() '单击“^”a = Val(Text1.Text)key = mulpi.CaptionText1.Text = " "End SubPrivate Sub sign_Click() '单击“+/-”,改变操作数符号Text1.Text = -Val(Text1.Text)End SubPrivate Sub equal_Click() '单击“=”Select Case key '判断运算符Case "+": Text1.Text = a + Val(Text1.Text)Case "-": Text1.Text = a - Val(Text1.Text)Case "*": Text1.Text = a * Val(Text1.Text)Case "/": Text1.Text = a / Val(Text1.Text)Case "\": Text1.Text = a \ Val(Text1.Text)Case "mod": Text1.Text = a Mod Val(Text1.Text)Case "^": Text1.Text = a ^ Val(Text1.Text)Case "<": Text1.Text = a < Val(Text1.Text)Case ">": Text1.Text = a > Val(Text1.Text)Case "<>": Text1.Text = a <> Val(Text1.Text)Case "Like": b = "*" & Trim(Text1.Text) & "*"If (Str(a) Like b) Then Text1.Text = True Else Text1.Text = False Case "Not": Text1.Text = Not aCase "And": Text1.Text = a And Val(Text1.Text)Case "Or": Text1.Text = a Or Val(Text1.Text)Case "Xor": Text1.Text = a Xor Val(Text1.Text)End SelectEnd SubPrivate Sub less_Click() '单击“<”a = Val(Text1.Text)key = less.CaptionText1.Text = " "End SubPrivate Sub more_Click() '单击“>”a = Val(Text1.Text)key = more.CaptionText1.Text = " "End SubPrivate Sub notequal_Click() '单击“<>”a = Val(Text1.Text)key = notequal.CaptionText1.Text = " "End SubPrivate Sub likes_Click() '单击“Likes”a = Val(Text1.Text)key = likes.CaptionText1.Text = " "End SubPrivate Sub cmdnot_Click() '单击“Not”a = Val(Text1.Text)key = cmdnot.CaptionText1.Text = " "End SubPrivate Sub cmdand_Click() '单击“And”a = Val(Text1.Text)key = cmdand.CaptionText1.Text = " "End SubPrivate Sub cmdor_Click() '单击“Or”a = Val(Text1.Text)key = cmdor.CaptionText1.Text = " "End SubPrivate Sub cmdxor_Click() '单击“Xor”a = Val(Text1.Text)key = cmdxor.CaptionText1.Text = " "End SubPrivate Sub Command3_Click(Index As Integer) '函数区中功能实现,Command3'为函数区控件数组名Select Case IndexCase 0Text2.Text = Sin(Val(Trim$(Text1.Text))) '调用内部函数sinCase 1Text2.Text = Cos(Val(Trim$(Text1.Text)))Case 2Text2.Text = Abs(Val(Trim$(Text1.Text)))Case 3Text2.Text = Sqr(Val(Trim$(Text1.Text)))Case 4Text2.Text = Hex$(Val(Trim$(Text1.Text)))Case 5Text2.Text = Oct$(Val(Trim$(Text1.Text)))Case 6Text2.Text = Asc(Trim$(Text1.Text))Case 7Text2.Text = Rnd(Val(Trim$(Text1.Text)))Case 8Text2.Text = DateCase 9Text2.Text = Len(Trim$(Text1.Text))Case 10Text2.Text = sum1() '调用自定义函数求和Case 11Text2.Text = ave() '调用自定义函数求平均值Case 12 '12为max命令按钮的控件数组Index值Dim m As SingleCall max2(m) '调用自定义子过程求最大值Text2.Text = m 'm为调用过程得到的最大值'Text2.Text = max() '调用自定义函数过程求最大值Case 13Text2.Text = min() '调用自定义函数过程求最小值Case 14Text2.Text = sort() '调用自定义函数过程排序Case 15'Text2.Text = fac() '调用自定义函数过程求阶乘Text2.Text = fac1(Val(Text1.Text))'调用自定义函数过程求阶乘,用递归实现End SelectEnd SubPrivate Function sum1()Dim k As IntegerDim s As Singles = 0For k = 1 To i - 1s = s + narray(k)Next ksum1 = sEnd FunctionPrivate Function max()Dim k As IntegerDim s As Single, m As Singlem = narray(1)For k = 2 To iIf m < narray(k) Then m = narray(k) Next kmax = mEnd FunctionPrivate Function ave() '求平均值Dim k As IntegerDim s As Single, m As SingleFor k = 1 To is = s + narray(k)Next kave = s / (i - 1)End FunctionPrivate Function min() '求最小值函数Dim k As IntegerDim s As Single, m As Singlem = narray(1)For k = 2 To i - 1If m > narray(k) Then m = narray(k) Next kmin = mEnd FunctionPrivate Function sort() '排序函数Dim k As Integer, j As IntegerDim s As String, m As SingleFor k = 1 To i - 2For j = 1 To i - 1If narray(j) < narray(j + 1) Thenm = narray(j)narray(j) = narray(j + 1)narray(j + 1) = mEnd IfNext jNext kFor k = 1 To i - 1s = s+" "+Str$(narray(k)) '将排序结果存放到字符串s,以便带回到主调程序中Next ksort = sEnd FunctionPrivate Function fac() '求阶乘函数Dim k As Integer, j As IntegerDim m As SingleIf InStr(Trim$(Text1.Text), " ") > 1 Then'如果在文本输入框中输入了多个数据,则计算一个'数据的阶乘j = first '数组元素narray()中第一个元素Else: j = Val(Trim$(Text1.Text))End Ifm = 1For k = 1 To jm = m * kNext kfac = mEnd FunctionPrivate Sub Text1_KeyPress(Keyasc As Integer)'在文本框1中输入多个数据,以空格分隔,按回'车键结束,识别数据存放到数组narray( )中Dim c As StringDim n As Integer, k As Integeri = 1k = 1If Keyasc = 13 Then '按下回车键For n = 0 To Len(Text1.Text) - 1c = Mid$(Text1.Text, n + 1, 1)If c = " " Thennarray(i) = Val(Mid$(Text1.Text, k, n - k + 1))'识别数据存放在数组narray(i)中k = k + Len(Str$(narray(i))) '下一个数据位置起点i = i + 1 '每识别一个数据数组实际长度加1End IfNext nEnd Iffirst = narray(1)End SubPrivate Sub max2(m As Single) '求数组元素的最大值Dim k As Integerm = narray(1)For k = 2 To iIf m < narray(k) Then m = narray(k)Next kEnd SubPrivate Function fac1(n As Long) '递归求阶乘If n > 1 Thenfac1 = fac1(n - 1) * nElsef ac1 = 1End IfEnd Function。
VB计算器
用VB写计算器这是我设计的计算器样式,代码如下:Dim data1 As Double‘定义变量类型’Dim data2 As DoubleDim j As IntegerDim flag As BooleanDim result As StringPrivate Sub Form_Load()flag = TrueText1 = "0"End Sub0~9的代码:Private Sub Command1_Click(Index As Integer)‘0’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "0"End IfElseText1 = ""Text1 = Text1 + "0"End Ifflag = TrueEnd SubPrivate Sub Command11_Click(Index As Integer)‘1’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "1"ElseText1 = ""Text1 = "1"End IfElseText1 = ""Text1 = Text1 + "1"End Ifflag = TrueEnd SubPrivate Sub Command12_Click(Index As Integer)‘2’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "2"ElseText1 = ""Text1 = "2"End IfElseText1 = ""Text1 = Text1 + "2"End Ifflag = TrueEnd SubPrivate Sub Command13_Click(Index As Integer)‘3’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "3"ElseText1 = ""Text1 = "3"End IfElseText1 = ""Text1 = Text1 + "3"End Ifflag = TrueEnd SubPrivate Sub Command14_Click(Index As Integer)‘4’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "4"ElseText1 = ""Text1 = "4"End IfElseText1 = ""Text1 = Text1 + "4"End Ifflag = TrueEnd SubPrivate Sub Command15_Click(Index As Integer)‘5’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "5"ElseText1 = ""Text1 = "5"End IfElseText1 = ""Text1 = Text1 + "5"End Ifflag = TrueEnd SubPrivate Sub Command16_Click(Index As Integer)‘6’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "6"ElseText1 = ""Text1 = "6"End IfElseText1 = ""Text1 = Text1 + "6"End Ifflag = TrueEnd SubPrivate Sub Command17_Click(Index As Integer)‘7’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "7"ElseText1 = ""Text1 = "7"End IfElseText1 = ""Text1 = Text1 + "7"End Ifflag = TrueEnd SubPrivate Sub Command18_Click(Index As Integer)‘8’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "8"ElseText1 = ""Text1 = "8"End IfElseText1 = ""Text1 = Text1 + "8"End Ifflag = TrueEnd SubPrivate Sub Command19_Click(Index As Integer)‘9’If flag = True ThenIf Text1 <> "0" ThenText1 = Text1 + "9"ElseText1 = ""Text1 = "9"End IfElseText1 = ""Text1 = Text1 + "9"End Ifflag = TrueEnd SubPrivate Sub Command2_Click()‘小数点的实现’If Text1 <> "" ThenText1 = Text1 + "."End Ifflag = TrueEnd SubPrivate Sub Command3_Click()‘正负号的转换’If Text1 > 0 And Text1 < 1 ThenText1 = Trim("-") + Trim(Text1)Exit SubEnd IfIf Text1 > -1 And Text1 < 0 ThenText1 = "0" + Trim(-Text1)Exit SubEnd IfText1 = -Text1End Sub‘+-*/加减乘除的实现’Private Sub Command4_Click()‘+’data1 = Text1j = "1"Text1 = "0"Text1.SetFocusEnd SubPrivate Sub Command5_Click()‘-‘data1 = Text1j = "2"Text1 = "0"Text1.SetFocusEnd SubPrivate Sub Command6_Click()‘*’data1 = Text1j = "3"Text1 = "0"Text1.SetFocusEnd SubPrivate Sub Command7_Click()‘/’data1 = Text1j = "4"Text1 = "0"Text1.SetFocusEnd SubPrivate Sub Command10_Click()‘=’data2 = Text1If j = 1 Thenresult = data1 + data2ElseIf j = 2 Thenresult = data1 - data2ElseIf j = 3 Thenresult = data1 * data2ElseIf j = 4 Thenresult = data1 / data2End IfIf result > 0 And result < 1 Thenresult = "0" + Trim(result)End IfIf result > -1 And result < 0 Thenresult = "0" + Trim(-result)result = "-" + resultEnd IfText1 = resultdata1 = "0"flag = FalseEnd SubPrivate Sub Command9_Click()‘C清除按钮’Text1 = "0"Text1.SetFocusEnd Sub。
用VB制作计算器
用VB制作计算器在VB编程语言中,可以使用Windows Forms应用程序来制作一个简单的计算器。
Windows Forms应用程序是VB的一种可视化编程工具,可以为用户提供一个图形用户界面。
首先,我们需要创建一个新的Windows Forms应用程序项目,并打开默认生成的Form1窗体。
接下来,我们可以使用Windows Forms控件来创建一个计算器的用户界面。
在Form1窗体上,我们可以添加一个TextBox控件用于显示计算结果,并设置其属性为只读。
```vbPrivate ReadOnly resultTextBox As TextBox = New TextBox```然后,我们可以添加一些Button控件来表示计算器的数字和操作符。
我们可以使用按钮的Click事件来处理用户的点击操作。
```vbPrivate ReadOnly buttons As List(Of Button) = New List(Of Button)```接下来,我们需要实现按钮的Click事件处理程序来执行相应的计算逻辑。
我们可以使用Eval函数来计算表达式的值,并将结果显示在TextBox中。
Private Sub Button_Click(sender As Object, e As EventArgs) Dim button As Button = TryCast(sender, Button)If button IsNot Nothing ThenDim buttonText As String = button.TextIf buttonText = "=" Then'计算表达式的值Dim expression As String = resultTextBox.TextDim value As Double = Eval(expression)resultTextBox.Text = value.ToStringElseIf buttonText = "C" Then'清空文本框resultTextBox.Text = ""Else'添加数字或操作符resultTextBox.Text += buttonTextEnd IfEnd IfEnd Sub最后,我们需要在窗体的构造函数或Load事件处理程序中将按钮和TextBox添加到窗体上。
vb简易计算器
vb简易计算器本⼈⼀觉醒来闲得⽆聊,正在学习VB,便⽤VB写个简易的计算器吧!巩固基础。
代码如下:1 /**2 *Author:乌鸟heart3 *Version:1.04 */5Dim IntX As Double'全局变量,⽤于存储计算的数值6Dim IntOperation As Double'标记运算类型7Dim isBegin As Boolean'标记是否已经给IntX赋值8Public Sub Clear() '清空命令函数910 screen.Caption = ""11End Sub12Public Sub SavaToIntX()1314Select Case IntOperation1516Case1'加法17If isBegin = False Then18 IntX = Val(screen.Caption)19 isBegin = True20Else21 IntX = IntX + Val(screen.Caption)22End If2324Case2'减法25If isBegin = False Then26 IntX = Val(screen.Caption)27 isBegin = True28Else29 IntX = IntX - Val(screen.Caption)30End If3132Case3'乘法33If isBegin = False Then34 IntX = Val(screen.Caption)35 isBegin = True36Else37 IntX = IntX * Val(screen.Caption)38'screen.Caption = IntX39End If4041Case4'除法42If isBegin = False Then43 IntX = Val(screen.Caption)44 isBegin = True45Else46 IntX = IntX / Val(screen.Caption)47End If4849End Select5051End Sub5253Private Sub Command0_Click()54 screen.Caption = screen.Caption & 055End Sub56Private Sub Command1_Click()57 screen.Caption = screen.Caption & 158End Sub59Private Sub Command2_Click()60 screen.Caption = screen.Caption & 261End Sub62Private Sub Command3_Click()63 screen.Caption = screen.Caption & 364End Sub65Private Sub Command4_Click()66 screen.Caption = screen.Caption & 467End Sub68Private Sub Command5_Click()69 screen.Caption = screen.Caption & 570End Sub71Private Sub Command6_Click()72 screen.Caption = screen.Caption & 673End Sub74Private Sub Command7_Click()75 screen.Caption = screen.Caption & 776End Sub77Private Sub Command8_Click()78 screen.Caption = screen.Caption & 879End Sub80Private Sub Command9_Click()81 screen.Caption = screen.Caption & 982End Sub8384Private Sub CommandClear_Click() '清空命令85 isBegin = False86 IntOperation = 087 IntX = 088 screen.Caption = ""89End Sub9091Private Sub CommandEqual_Click() '等号运算 9293If IntOperation <> 0Then'有运算标记的情况94Call SavaToIntX95 IntOperation = 096 isBegin = False97 screen.Caption = IntX98End If99100End Sub101102Private Sub CommandMinus_Click() '减法运算103104If IntOperation <> 0Then'有运算标记的情况105Call SavaToIntX106 IntOperation = 2107Call Clear108109Else110 IntOperation = 2111Call SavaToIntX112Call Clear113114End If115End Sub116117Private Sub CommandMultiple_Click() '乘法运算118If IntOperation <> 0Then'有运算标记的情况119Call SavaToIntX120 IntOperation = 3121Call Clear122123Else124 IntOperation = 3125Call SavaToIntX126Call Clear127128End If129130End Sub131132Private Sub CommandPlus_Click() '加法运算133134If IntOperation <> 0Then'有运算标记的情况135Call SavaToIntX136 IntOperation = 1137Call Clear138139Else140 IntOperation = 1141Call SavaToIntX142Call Clear143144End If145146End Sub147148Private Sub CommandSlash_Click() '除法运算149150If IntOperation <> 0Then'有运算标记的情况151Call SavaToIntX152 IntOperation = 4153Call Clear154155Else156 IntOperation = 4157Call SavaToIntX158Call Clear159160End If161End SubOK,DONE!。
使用VB制作计算器程序
使用VB制作计算器程序计算器程序是一种用于进行数学计算的工具。
最常见的计算器是电子计算器,它可以实现简单的加减乘除等基本计算。
而现在,我们可以使用VB(即Visual Basic)编程语言制作一个计算器程序,使其在计算能力上有所提升。
首先,我们需要创建一个VB Windows Forms应用程序。
在创建项目时,我们可以选择桌面应用程序(Windows Forms)模板。
接下来,我们需要设计计算器的用户界面。
可以使用按钮、文本框等控件来实现基本的数字输入和计算。
假设我们的计算器有一个文本框用于显示输入和结果,并且有数字按钮和运算符按钮来输入表达式,并且还有一个等号按钮用于计算结果。
我们可以使用VB代码来实现各种按钮的功能。
以下是一个简单的计算器程序示例:```vbPublic Class Form1Dim num1 As Double ' 第一个操作数Dim num2 As Double ' 第二个操作数Dim result As Double ' 结果Dim operator As String ' 运算符'数字按钮的点击事件处理函数Private Sub NumberButton_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button0.ClickDim number As Button = CType(sender, Button)TextBox1.Text += number.TextEnd Sub'运算符按钮的点击事件处理函数Private Sub OperatorButton_Click(sender As Object, e As EventArgs) Handles PlusButton.Click, MinusButton.Click, MultiplyButton.Click, DivideButton.ClickDim op As Button = CType(sender, Button)num1 = CDbl(TextBox1.Text)TextBox1.Clear[operator] = op.TextEnd Sub'等号按钮的点击事件处理函数Private Sub EqualsButton_Click(sender As Object, e As EventArgs) Handles EqualsButton.Clicknum2 = CDbl(TextBox1.Text)Select Case [operator]Case "+"result = num1 + num2Case "-"result = num1 - num2Case "*"result = num1 * num2Case "/"result = num1 / num2End SelectTextBox1.Text = result.ToStringEnd Sub'清除按钮的点击事件处理函数Private Sub ClearButton_Click(sender As Object, e As EventArgs) Handles ClearButton.ClickTextBox1.ClearEnd SubEnd Class```以上代码实现了简单的加减乘除功能,并将结果显示在文本框中。
用VB制作计算器
摘要这个程序是我用VB制作的简单计算器,它可以实现简单的四则运算,数字的平方,平方根,正弦,余弦,倒数,以及进制的相互转换。
而且它的功能还有退格,清除当前数据,清除所有数据,复制数据,粘贴数据,退出程序。
在这个计算器的程序中,我用到了单行选择语句If …Then …Else…,If语句的嵌套,多条件选择语句Select Case,而且还用到了组合框,框架,菜单的设计,以及键盘事件,可以通过键盘来用于计算。
在此报告中我重点叙述了计算机的各个功能及用法。
特别是进制间的转换和数字与运算符之间的联系。
还有说明了键盘怎样用于操作计算。
虽然表达能力不太行,但我会尽力使用系统结构图,程序流程图,划分多个模块,让大家明白我设计的运算器的功能的。
目录摘要 (1)目录 (2)第一章任务概述 (3)1.1、目标 (3)1.2、需求概述 (3)1.2.1、鼠标操作 (3)1.2.2、键盘操作 (3)第二章总体设计 (4)2.1、系统结构功能图 (4)第三章功能分配 (5)3.1、打开计算器界面 (5)3.2、平方根,平方,倒数,正弦,余弦的实现 (7)3.3、退格 (8)3.4、清除 (8)3.4.1、清除当前数据 (8)3.4.2清除所有数据 (8)3.5、鼠标的输入 (9)3.6、进制间的转换 (11)小结 (13)第一章任务概述1.1、目标本系统的目标是建立一套可以计算数的平方,平方根,倒数,正弦,余弦,数字的进制转换的计算器系统,系统可以帮助我们更好的学习,更好的节省时间。
还能避免出现一些不必要的计算错误。
1.2、需求概述根据本系统的需求分析,系统的需求可以分为以下的几个方面:1.2.1、鼠标操作你可以利用鼠标点击界面上的各个按钮来实现计算器的运算。
1.2.2、键盘操作当不方便使用鼠标时可以利用键盘来实现运算,数字的复制和粘贴。
第二章总体设计2.1、系统结构功能图图2-1系统结构功能图第三章功能分配3.1、打开计算器界面图3-1 计算器界面Dim dflag As Integer‘小数点仍然存在吗?Dim i As IntegerDim opnre As Integer ‘初始值Dim prev As Double‘前面输入的操作数Dim oflag As Integer ‘等号前后对数字的标记Dim ind As Integer ‘cmdoperator控件数组的数Dim x As DoubleDim y As Double' 运算符 (+, -, x, /, =) 的 Click 事件过程' 如果接下来的按键是数字键,增加 val(text1.Caption)。
vb计算器 实验报告
vb计算器实验报告VB计算器实验报告引言:计算器是人们日常生活中常用的工具之一,无论是进行简单的数学运算还是复杂的科学计算,计算器都能提供帮助。
本实验旨在使用VB(Visual Basic)编程语言设计和实现一个功能完善的计算器,通过该实验,我们可以深入了解计算器的原理和实现方法,并掌握VB编程的基本技巧。
一、实验目的本实验的主要目的是设计和实现一个VB计算器,具体包括以下几个方面:1. 学习VB编程语言的基本语法和数据类型;2. 掌握VB窗体的设计和布局;3. 实现基本的计算功能,包括加减乘除、取余、开方等;4. 实现科学计算功能,包括三角函数、指数函数、对数函数等;5. 实现计算器的界面美化和用户友好性。
二、实验原理1. VB编程语言VB是一种事件驱动的编程语言,它提供了丰富的控件和库函数,方便开发者进行图形界面的设计和实现。
在本实验中,我们将使用VB编程语言来实现计算器的功能。
2. VB窗体设计VB窗体是计算器的主界面,通过在窗体上添加各种控件,如按钮、文本框等,来实现计算器的各种功能。
通过设置控件的属性和事件,可以实现用户与计算器的交互。
3. 计算器的基本功能实现计算器的基本功能包括加减乘除、取余、开方等,这些功能可以通过VB编程语言中提供的数学函数和运算符来实现。
通过捕捉用户输入的数据和操作符,计算器可以进行相应的计算并将结果显示在屏幕上。
4. 科学计算功能的实现科学计算功能是计算器的扩展功能,包括三角函数、指数函数、对数函数等。
这些函数可以通过VB编程语言中提供的数学库函数来实现,通过捕捉用户的选择和输入,计算器可以根据用户的需求进行相应的科学计算。
5. 界面美化和用户友好性为了提高计算器的用户体验,我们需要对计算器的界面进行美化和优化。
通过设置控件的样式、颜色和布局,可以使计算器界面更加美观和易用。
三、实验步骤1. 创建VB工程,并添加一个窗体;2. 在窗体上添加各种控件,如按钮、文本框等,用于实现计算器的各种功能;3. 设置控件的属性和事件,实现计算器的基本功能,包括加减乘除、取余、开方等;4. 添加科学计算功能,如三角函数、指数函数、对数函数等,实现科学计算器的功能;5. 美化计算器界面,通过设置控件的样式、颜色和布局,提高用户体验;6. 进行测试和调试,确保计算器的功能正常。
vb复数计算器
Dim save As StringDim a As SingleDim points, over, b, c, d, e As BooleanPrivate Sub Command1_Click(Index As Integer) If over = True ThenText1.Text = ""End IfIf b = True ThenText1.Text = Text1.Text & Trim(Str(Index)) ElseIf c = True ThenText2.Text = Text2.Text & Trim(Str(Index))ElseIf d = True ThenText4.Text = Text4.Text & Trim(Str(Index)) ElseIf e = True ThenText5.Text = Text5.Text & Trim(Str(Index)) End Ifover = FalseEnd SubPrivate Sub Command2_Click()If points = False ThenIf b = True ThenIf Text1.Text = "" ThenText1.Text = 0 & "."points = TrueElseText1.Text = Text1.Text & "."points = TrueEnd IfElseIf c = True ThenIf Text2.Text = "" ThenText2.Text = 0 & "."points = TrueElseText2.Text = Text2.Text & "."points = TrueEnd IfElseIf d = True ThenIf Text4.Text = "" ThenText4.Text = 0 & "."points = TrueElseText4.Text = Text4.Text & "."points = TrueEnd IfElseIf e = True ThenIf Text5.Text = "" ThenText5.Text = 0 & "."points = TrueElseText5.Text = Text5.Text & "."points = TrueEnd IfEnd IfEnd IfEnd SubPrivate Sub Command3_Click()If b = True ThenIf Text1.Text <> "" ThenText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) End IfElseIf c = True ThenIf Text2.Text <> "" ThenText2.Text = Left(Text2.Text, Len(Text2.Text) - 1) End IfElseIf d = True ThenIf Text4.Text <> "" ThenText4.Text = Left(Text4.Text, Len(Text4.Text) - 1) End IfElseIf e = True ThenIf Text5.Text <> "" ThenText5.Text = Left(Text5.Text, Len(Text5.Text) - 1)End IfEnd IfEnd SubPrivate Sub Command4_Click(Index As Integer)Const Pi = 3.1415926Select Case IndexCase 0Text3.Text = Str(Val(Text1.Text) + Val(Text2.Text))Text6.Text = Str(Val(Text4.Text) + Val(Text5.Text))Text7.Text = Sqr(Val((Text4.Text) * Val(Text4.Text)) + (Val(Text1.Text) * Val(Text1.Text)))Text8.Text = Sqr(Val((Text2.Text) * Val(Text2.Text)) + (Val(Text5.Text) * Val(Text5.Text)))Text9.Text = Sqr(Val((Text3.Text) * Val(Text3.Text)) + (Val(Text6.Text) * Val(Text6.Text)))Case 1Text3.Text = Str(Val(Text1.Text) - Val(Text2.Text))Text6.Text = Str(Val(Text4.Text) - Val(Text5.Text))Text7.Text = Sqr(Val((Text4.Text) * Val(Text4.Text)) + (Val(Text1.Text) * Val(Text1.Text)))Text8.Text = Sqr(Val((Text2.Text) * Val(Text2.Text)) + (Val(Text5.Text) * Val(Text5.Text)))Text9.Text = Sqr(Val((Text3.Text) * Val(Text3.Text)) + (Val(Text6.Text) * Val(Text6.Text)))Case 2Text3.Text = Str(Val(Text1.Text) * Val(Text2.Text) - Val(Text4.Text) * Val(Text5.Text))Text6.Text = Str(Val(Text1.Text) * Val(Text5.Text) + Val(Text4.Text) * Val(Text2.Text))Text7.Text = Sqr(Val((Text4.Text) * Val(Text4.Text)) + (Val(Text1.Text) * Val(Text1.Text)))Text8.Text = Sqr(Val((Text2.Text) * Val(Text2.Text)) + (Val(Text5.Text) * Val(Text5.Text)))Text9.Text = Sqr(Val((Text3.Text) * Val(Text3.Text)) + (Val(Text6.Text) * Val(Text6.Text)))Case 3Text3.Text = (V al(Text1.Text) * Val(Text2.Text) + Val(Text4.Text) * Val(Text5.Text)) / (Val(Text2.Text) * Val(Text2.Text) + Val(Text5.Text) * Val(Text5.Text))Text6.Text = (Val(Text4.Text) * Val(Text2.Text) - Val(Text1.Text) * Val(Text5.Text)) / (Val(Text2.Text) * Val(Text2.Text) + Val(Text5.Text) * Val(Text5.Text))Text7.Text = Sqr(Val((Text4.Text) * Val(Text4.Text)) + (Val(Text1.Text) * Val(Text1.Text)))Text8.Text = Sqr(Val((Text2.Text) * Val(Text2.Text)) + (Val(Text5.Text) *Val(Text5.Text)))Text9.Text = Sqr(Val((Text3.Text) * Val(Text3.Text)) + (Val(Text6.Text) * Val(Text6.Text)))End Selectpoints = FalseEnd SubPrivate Sub Command6_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text5.Text = ""Text6.Text = ""Text7.Text = ""Text8.Text = ""Text9.Text = ""over = 0points = 0save = 0End SubPrivate Sub Command7_Click()If b = True ThenText1.Text = Str(-Val(Text1.Text))ElseIf c = True ThenText2.Text = Str(-Val(Text2.Text))ElseIf d = True ThenText4.Text = Str(-Val(Text4.Text))ElseIf e = True ThenText5.Text = Str(-Val(Text5.Text))End IfEnd SubPrivate Sub Command8_Click()If Text1.Text = Text2.Text And Text4.Text = Text5.Text ThenText3.Text = "相等"Text6.Text = " "End IfIf Text1.Text <> Text2.Text Or Text4.Text <> Text5.Text ThenText3.Text = "不相等"Text6.Text = " "End IfEnd SubPrivate Sub Form_Load() points = Falseover = Falsec = Falseb = Trued = Falsee = FalseEnd SubPrivate Sub Text1_Click()b = Truec = Falsed = Falsee = FalseEnd SubPrivate Sub Text2_Click() c = Trueb = Falsed = Falsee = FalseEnd SubPrivate Sub Text4_Click() c = Falseb = Falsee = Falsed = TrueEnd SubPrivate Sub Text5_Click() e = Trueb = Falsed = Falsec = FalseEnd SubPrivate Sub 关于_Click() form2.ShowEnd Sub。
vb计算器 简单程序(包含 进制转换 )
Option ExplicitDim s1 As Integer, N As Single, r As IntegerPrivate Sub Command1_Click(Index As Integer> Text1.Text = Text1.Text & IndexEnd Sub'CEPrivate Sub Command11_Click(>Text1.Text = ""End SubPrivate Sub Command12_Click(>Text1.Text = (Text1.Text> ^ 2End SubPrivate Sub Command17_Click(>Text1.Text = " "End SubPrivate Sub Command18_Click(>Text1.Text = (Text1.Text> ^ 3End SubPrivate Sub Command20_Click(>If Text1.Text = "" ThenMsgBox ("²Ù×÷´íÎó">ElseText1.Text = Val(Text1.Text> * (-1> End IfEnd SubPrivate Sub Command21_Click(>If InStr(Text1.Text, "."> Then MsgBox ("СÊýµãÒÑ´æÔÚ">ElseText1.Text = Text1 & Chr(46>End IfEnd SubPrivate Sub Command23_Click(>If N = 1 ThenIf Text1.Text = 0 ThenMsgBox "³ýÊý²»ÄÜΪÁã"ElseText1 = s1 / Text1.TextEnd IfElseIf N = 2 ThenText1 = s1 * Text1.TextElseIf N = 3 ThenText1 = s1 - Text1.TextElseIf N = 4 ThenText1 = s1 + Text1.TextEnd IfEnd SubPrivate Sub Command24_Click(>Text1.Text = 1 / Text1.TextEnd SubPrivate Sub Command25_Click(Index As Integer> Select Case IndexCase 0Text1.Text = Text1.Text & "A"Case 1Text1.Text = Text1.Text & "B"Case 2Text1.Text = Text1.Text & "C"Case 3Text1.Text = Text1.Text & "D"Case 4Text1.Text = Text1.Text & "E"Case 5Text1.Text = Text1.Text & "F"End SelectEnd SubPrivate Sub Command4_Click(Index As Integer> Select Case IndexCase 0N = 1s1 = Text1.TextText1.Text = ""Case 1N = 2s1 = Text1.TextText1.Text = ""Case 2N = 3s1 = Text1.TextText1.Text = ""Case 3N = 4s1 = Text1.TextText1.Text = ""End SelectEnd SubPrivate Sub Command5_Click(>Text1.Text = Left(Text1.Text, Len(Text1.Text> - 1> End SubPrivate Sub Command6_Click(>Text1.Text = Sqr(Text1.Text>End SubPrivate Sub Form_Load(>r = 10End Sub'Ê®Áù½øÖÆPrivate Sub Option1_Click(> Command25(1>.Enabled = True Command25(0>.Enabled = True Command25(2>.Enabled = True Command25(3>.Enabled = True Command25(4>.Enabled = True Command25(5>.Enabled = True Command1(6>.Enabled = True Command1(9>.Enabled = True Command1(2>.Enabled = True Command1(3>.Enabled = True Command1(4>.Enabled = True Command1(5>.Enabled = True Command1(8>.Enabled = TrueIf r = 10 ThenText1.Text = trandec(Val(Text1.Text>, 16> ElseText1.Text = Two16(Text1.Text>End Ifr = 16End Sub'Ê®½øÖÆPrivate Sub Option2_Click(>Command1(6>.Enabled = TrueCommand1(9>.Enabled = TrueCommand1(2>.Enabled = TrueCommand1(3>.Enabled = TrueCommand1(4>.Enabled = TrueCommand1(5>.Enabled = TrueCommand1(8>.Enabled = TrueCommand1(7>.Enabled = TrueCommand25(0>.Enabled = FalseCommand25(1>.Enabled = FalseCommand25(2>.Enabled = FalseCommand25(3>.Enabled = FalseCommand25(5>.Enabled = FalseText1.Text = Convert(Text1.Text, r> r = 10End Sub'¶þ½øÖÆPrivate Sub Option3_Click(> Command1(6>.Enabled = False Command1(9>.Enabled = False Command1(2>.Enabled = False Command1(3>.Enabled = False Command1(4>.Enabled = False Command1(5>.Enabled = False Command1(8>.Enabled = False Command1(7>.Enabled = False Command25(0>.Enabled = False Command25(1>.Enabled = False Command25(2>.Enabled = False Command25(3>.Enabled = False Command25(4>.Enabled = False Command25(5>.Enabled = FalseIf r = 10 ThenText1.Text = trandec(Val(Text1.Text>, 2> ElseText1.Text = HEX_to_BIN(Text1.Text>End Ifr = 2End SubPrivate Sub Text1_Change(>If Mid(Text1.Text, 1, 1> = "." ThenText1.Text = 0 & Text1.TextEnd IfEnd Sub'Ê®½øÖÆת¶þºÍÊ®Áù½øÖÆPublic Function trandec$(ByVal m%, ByVal r%> Dim strdtor$Dim iB%, mr%strdtor = ""Do While m <> 0mr = m Mod rm = m \ rIf mr >= 10 Thenstrdtor = Chr(mr - 10 + 65> & strdtorElsestrdtor = mr & strdtorEnd IfLooptrandec = strdtorEnd FunctionPublic Function Convert(ByVal S As String, ByVal N As Integer> As Double 'ÈÎÒâ½øÖÆת»»³É10½øÖÆb5E2RGbCAPDim L As StringDim r(> As StringDim i As IntegerDim j As IntegerL = "0|1|2|3|4|5|6|7|8|9|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T |U|V|W|X|Y|Z" '½øÖÆ×Ö·û´®×Öµäp1EanqFDPwr = Split(L, "|">For i = 1 To Len(S>For j = 0 To UBound(r>If UCase(Mid(S, i, 1>> = r(j> ThenConvert = Convert * N + jEnd IfNext jNext iEnd FunctionPrivate Function Two16(ByVal X As String> As String '°Ñ¶þ½øÖÆÊýת»¯ÎªÊ®Áù½øÖÆÊýDXDiTa9E3dDo While Len(X> Mod 4 <> 0X = "0" + XLoopDo While Len(X> > 0Select Case Right(X, 4>Case "0000"Two16 = "0" + Two16Case "0001"Two16 = "1" + Two16Two16 = "2" + Two16 Case "0011"Two16 = "3" + Two16 Case "0100"Two16 = "4" + Two16 Case "0101"Two16 = "5" + Two16 Case "0110"Two16 = "6" + Two16 Case "0111"Two16 = "7" + Two16 Case "1000"Two16 = "8" + Two16 Case "1001"Two16 = "9" + Two16 Case "1010"Two16 = "A" + Two16 Case "1011"Two16 = "B" + Two16 Case "1100"Two16 = "C" + Two16Two16 = "D" + Two16Case "1110"Two16 = "E" + Two16Case "1111"Two16 = "F" + Two16End SelectX = Left(X, Len(X> - 4>LoopEnd Function'Ê®Áùת¶þPublic Function HEX_to_BIN(ByVal Hex As String> As StringRTCrpUDGiTDim i As LongDim B As StringHex = UCase(Hex>For i = 1 To Len(Hex>Select Case Mid(Hex, i, 1>Case "0": B = B & "0000"Case "1": B = B & "0001"Case "2": B = B & "0010" Case "3": B = B & "0011" Case "4": B = B & "0100" Case "5": B = B & "0101" Case "6": B = B & "0110" Case "7": B = B & "0111" Case "8": B = B & "1000" Case "9": B = B & "1001" Case "A": B = B & "1010" Case "B": B = B & "1011" Case "C": B = B & "1100" Case "D": B = B & "1101" Case "E": B = B & "1110" Case "F": B = B & "1111" End SelectNext iDo While Left(B, 1> = "0"B = Right(B, Len(B> - 1>LoopHEX_to_BIN = BEnd Function。
vb科学计算器
课程设计指导书课程vb计算器程序设计班级姓名学号目录一功能描述 (3)二概要设计及设计流程框图 (3)三详细设计..................................................................。
3 四效果及运行界面图......................................................。
.4 五心得体会.. (4)六附录.........................................................................。
6 七参考文献...................................................................。
6 八本人在改组中完成的部分.. (7)九进度安排……………………………………………。
……………。
7一、功能描述:窗体通过窗体命令按钮或键盘输入数字实现基本的数学运算,使用窗体的功能按钮计算某些特殊函数二、概要设计及设计流程框图:使用vb设计科学型计算器,功能介于科学型和简单型之间,要求能进行加、减、乘、除和开方、乘方、对数、三角函数计算,可以存储与调出数据。
在这个计算器的程序中,我用到了单行选择语句If …Then …Else…,If语句的嵌套,多条件选择语句Select Case。
三、详细设计:本系统1个文本框,数个命令按钮,数个数字按钮用文本框显示输入的数字并将结果显示在文本框中,用命令按钮来计算和输入数字。
详细内容:command12(0-9)为数字的控件数组,command13(4—11)为功能函数的控件数组,command13(0-3)为运算符的控件数组,command25为小数点按钮,command26为等号按钮,command1为开关按钮,command2为清除按钮。
四、效果及运行界面:基本能完成所有运算五、心得体会为期一周的实训即将结束,通过这次的实训使我们学到了很多,同时也让我们意识到我们要学的更多.本次实训的内容是科学计算器的程序设计,以小组的形式进行分工合作,我组共4个人,从程序的需求分析、可行性分析、设计到编写、调试、修改、完善、到最后的实训报告,每个人都付出了时间和精力去做好自己的任务并努力地去完善它。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Dim save As StringDim a As SingleDim points, over, b, c, d, e As BooleanPrivate Sub Command1_Click(Index As Integer) If over = True ThenText1.Text = ""End IfIf b = True ThenText1.Text = Text1.Text & Trim(Str(Index)) ElseIf c = True ThenText2.Text = Text2.Text & Trim(Str(Index))ElseIf d = True ThenText4.Text = Text4.Text & Trim(Str(Index)) ElseIf e = True ThenText5.Text = Text5.Text & Trim(Str(Index)) End Ifover = FalseEnd SubPrivate Sub Command2_Click()If points = False ThenIf b = True ThenIf Text1.Text = "" ThenText1.Text = 0 & "."points = TrueElseText1.Text = Text1.Text & "."points = TrueEnd IfElseIf c = True ThenIf Text2.Text = "" ThenText2.Text = 0 & "."points = TrueElseText2.Text = Text2.Text & "."points = TrueEnd IfElseIf d = True ThenIf Text4.Text = "" ThenText4.Text = 0 & "."points = TrueElseText4.Text = Text4.Text & "."points = TrueEnd IfElseIf e = True ThenIf Text5.Text = "" ThenText5.Text = 0 & "."points = TrueElseText5.Text = Text5.Text & "."points = TrueEnd IfEnd IfEnd IfEnd SubPrivate Sub Command3_Click()If b = True ThenIf Text1.Text <> "" ThenText1.Text = Left(Text1.Text, Len(Text1.Text) - 1) End IfElseIf c = True ThenIf Text2.Text <> "" ThenText2.Text = Left(Text2.Text, Len(Text2.Text) - 1) End IfElseIf d = True ThenIf Text4.Text <> "" ThenText4.Text = Left(Text4.Text, Len(Text4.Text) - 1) End IfElseIf e = True ThenIf Text5.Text <> "" ThenText5.Text = Left(Text5.Text, Len(Text5.Text) - 1)End IfEnd IfEnd SubPrivate Sub Command4_Click(Index As Integer)Const Pi = 3.1415926Select Case IndexCase 0Text3.Text = Str(V al(Text1.Text) + V al(Text2.Text))Text6.Text = Str(V al(Text4.Text) + V al(Text5.Text))Text7.Text = Sqr(V al((Text4.Text) * V al(Text4.Text)) + (V al(Text1.Text) * V al(Text1.Text)))Text8.Text = Sqr(V al((Text2.Text) * V al(Text2.Text)) + (V al(Text5.Text) * V al(Text5.Text)))Text9.Text = Sqr(V al((Text3.Text) * V al(Text3.Text)) + (V al(Text6.Text) * V al(Text6.Text)))Case 1Text3.Text = Str(V al(Text1.Text) - V al(Text2.Text))Text6.Text = Str(V al(Text4.Text) - V al(Text5.Text))Text7.Text = Sqr(V al((Text4.Text) * V al(Text4.Text)) + (V al(Text1.Text) * V al(Text1.Text)))Text8.Text = Sqr(V al((Text2.Text) * V al(Text2.Text)) + (V al(Text5.Text) * V al(Text5.Text)))Text9.Text = Sqr(V al((Text3.Text) * V al(Text3.Text)) + (V al(Text6.Text) * V al(Text6.Text)))Case 2Text3.Text = Str(V al(Text1.Text) * V al(Text2.Text) - V al(Text4.Text) * V al(Text5.Text))Text6.Text = Str(V al(Text1.Text) * V al(Text5.Text) + V al(Text4.Text) * V al(Text2.Text))Text7.Text = Sqr(V al((Text4.Text) * V al(Text4.Text)) + (V al(Text1.Text) * V al(Text1.Text)))Text8.Text = Sqr(V al((Text2.Text) * V al(Text2.Text)) + (V al(Text5.Text) * V al(Text5.Text)))Text9.Text = Sqr(V al((Text3.Text) * V al(Text3.Text)) + (V al(Text6.Text) * V al(Text6.Text)))Case 3Text3.Text = (V al(Text1.Text) * V al(Text2.Text) + V al(Text4.Text) * V al(Text5.Text)) / (V al(Text2.Text) * V al(Text2.Text) + V al(Text5.Text) * V al(Text5.Text))Text6.Text = (V al(Text4.Text) * V al(Text2.Text) - V al(Text1.Text) * V al(Text5.Text)) / (V al(Text2.Text) * V al(Text2.Text) + V al(Text5.Text) * V al(Text5.Text))Text7.Text = Sqr(V al((Text4.Text) * V al(Text4.Text)) + (V al(Text1.Text) * V al(Text1.Text)))Text8.Text = Sqr(V al((Text2.Text) * V al(Text2.Text)) + (V al(Text5.Text) *V al(Text5.Text)))Text9.Text = Sqr(V al((Text3.Text) * V al(Text3.Text)) + (V al(Text6.Text) * V al(Text6.Text)))End Selectpoints = FalseEnd SubPrivate Sub Command6_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""Text4.Text = ""Text5.Text = ""Text6.Text = ""Text7.Text = ""Text8.Text = ""Text9.Text = ""over = 0points = 0save = 0End SubPrivate Sub Command7_Click()If b = True ThenText1.Text = Str(-V al(Text1.Text))ElseIf c = True ThenText2.Text = Str(-V al(Text2.Text))ElseIf d = True ThenText4.Text = Str(-V al(Text4.Text))ElseIf e = True ThenText5.Text = Str(-V al(Text5.Text))End IfEnd SubPrivate Sub Command8_Click()If Text1.Text = Text2.Text And Text4.Text = Text5.Text ThenText3.Text = "相等"Text6.Text = " "End IfIf Text1.Text <> Text2.Text Or Text4.Text <> Text5.Text ThenText3.Text = "不相等"Text6.Text = " "End IfEnd SubPrivate Sub Form_Load() points = Falseover = Falsec = Falseb = Trued = Falsee = FalseEnd SubPrivate Sub Text1_Click()b = Truec = Falsed = Falsee = FalseEnd SubPrivate Sub Text2_Click() c = Trueb = Falsed = Falsee = FalseEnd SubPrivate Sub Text4_Click() c = Falseb = Falsee = Falsed = TrueEnd SubPrivate Sub Text5_Click() e = Trueb = Falsed = Falsec = FalseEnd SubPrivate Sub 关于_Click() form2.ShowEnd Sub。