简单科学计算器vb程序
VB简易计算器代码
VB简易计算器代码下面是一个简单的VB计算器代码,用于执行基本的加、减、乘、除运算。
```vbOption Strict OnPublic Class CalculatorPrivate Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.ClickDim num1 As Double = CDbl(txtNum1.Text)Dim num2 As Double = CDbl(txtNum2.Text)Dim result As Double = num1 + num2txtResult.Text = result.ToStringEnd SubPrivate Sub btnSubtract_Click(sender As Object, e As EventArgs) Handles btnSubtract.ClickDim num1 As Double = CDbl(txtNum1.Text)Dim num2 As Double = CDbl(txtNum2.Text)Dim result As Double = num1 - num2txtResult.Text = result.ToStringPrivate Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles btnMultiply.ClickDim num1 As Double = CDbl(txtNum1.Text)Dim num2 As Double = CDbl(txtNum2.Text)Dim result As Double = num1 * num2txtResult.Text = result.ToStringEnd SubPrivate Sub btnDivide_Click(sender As Object, e As EventArgs) Handles btnDivide.ClickDim num1 As Double = CDbl(txtNum1.Text)Dim num2 As Double = CDbl(txtNum2.Text)If num2 = 0 ThenMessageBox.Show("除数不能为0!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)ElseDim result As Double = num1 / num2txtResult.Text = result.ToStringEnd IfEnd Sub```此代码创建了一个简单的窗体应用程序,其中包含两个文本框用于输入两个数字,四个按钮用于执行不同的计算操作,以及一个文本框用于显示结果。
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简易计算器代码
VB简易计算器代码以下是一个简单的VB计算器代码:```Public Class Form1Dim firstNum As Double ' 第一个数字Dim secondNum As Double ' 第二个数字Dim operation As Integer ' 1-加法,2-减法,3-乘法,4-除法Private Sub Button0_Click(sender As Object, e As EventArgs) Handles Button0.ClickTextBoxResult.Text = TextBoxResult.Text & "0"End SubPrivate Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.ClickTextBoxResult.Text = TextBoxResult.Text & "1"End SubPrivate Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.ClickTextBoxResult.Text = TextBoxResult.Text & "2"End SubHandles Button3.ClickTextBoxResult.Text = TextBoxResult.Text & "3"End SubPrivate Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.ClickTextBoxResult.Text = TextBoxResult.Text & "4"End SubPrivate Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.ClickTextBoxResult.Text = TextBoxResult.Text & "5"End SubPrivate Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.ClickTextBoxResult.Text = TextBoxResult.Text & "6"End SubPrivate Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.ClickTextBoxResult.Text = TextBoxResult.Text & "7"End SubHandles Button8.ClickTextBoxResult.Text = TextBoxResult.Text & "8"End SubPrivate Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.ClickTextBoxResult.Text = TextBoxResult.Text & "9"End SubPrivate Sub ButtonDot_Click(sender As Object, e As EventArgs) Handles ButtonDot.ClickIf Not TextBoxResult.Text.Contains(".") ThenTextBoxResult.Text = TextBoxResult.Text & "."End IfEnd SubPrivate Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.ClickfirstNum = Double.Parse(TextBoxResult.Text)TextBoxResult.Text = ""operation = 1End SubPrivate Sub ButtonSubtract_Click(sender As Object, e As EventArgs) Handles ButtonSubtract.ClickfirstNum = Double.Parse(TextBoxResult.Text)TextBoxResult.Text = ""operation = 2End SubPrivate Sub ButtonMultiply_Click(sender As Object, e As EventArgs) Handles ButtonMultiply.ClickfirstNum = Double.Parse(TextBoxResult.Text)TextBoxResult.Text = ""operation = 3End SubPrivate Sub ButtonDivide_Click(sender As Object, e As EventArgs) Handles ButtonDivide.ClickfirstNum = Double.Parse(TextBoxResult.Text)TextBoxResult.Text = ""operation = 4End SubPrivate Sub ButtonClear_Click(sender As Object, e As EventArgs) Handles ButtonClear.ClickTextBoxResult.Text = ""End SubPrivate Sub ButtonEquals_Click(sender As Object, e As EventArgs) Handles ButtonEquals.ClickDim result As DoublesecondNum = Double.Parse(TextBoxResult.Text)Select Case operationCase 1result = firstNum + secondNumCase 2result = firstNum - secondNumCase 3result = firstNum * secondNumCase 4result = firstNum / secondNumEnd SelectTextBoxResult.Text = result.ToStringEnd SubEnd Class```这个计算器包括数字按钮0-9、小数点按钮、加法、减法、乘法、除法和等于按钮。
科学计算器vb代码
TabIndex = 21
Top = 2400
Width = 510
End
Begin Command1
Caption = "."
Height = 390
Index = 11
Left = 3915
TabIndex = 20
Top = 2400
Width = 510
Top = 1455
Width = 510
End
Begin Command1
Caption = "4"
Height = 390
Index = 4
Left = 2820
TabIndex = 4
Top = 1455
Width = 510
End
Begin Command1
Caption = "3"
Height = 390
End
End
End
Attribute VB_Name = "Frm_Scientific"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Caption = "*"
Height = 390
IndexLeabharlann = 1Left = 4470
TabIndex = 11
Top = 1455
Width = 510
End
VB编写简单计算器程序
Option ExplicitDim LastInput As String * 3 '记录上次按下的按键Dim Num1 As Double '第一个操作数Dim Num2 As Double '第二个操作数Dim OptType As Integer '按下哪一个操作符Dim Result As Double '表示运算结果Dim shuzhi As Integer '表示当前采用的shuzhiDim FirstNum As Boolean '是否是第一个操作数Sub keyp(keynum As Integer)Dim CHAR As String * 1CHAR = Chr(keynum)If CHAR = "+" Or keynum = 43 Then Command5(0).Value = TrueIf CHAR = "-" Or keynum = 45 Then Command5(1).Value = TrueIf CHAR = "*" Or keynum = 42 Then Command5(2).Value = TrueIf CHAR = "/" Or keynum = 47 Then Command5(3).Value = TrueIf shuzhi = 2 And CHAR >= "2" And CHAR <= "9" Thenkeynum = 0Exit SubEnd IfIf keynum >= 48 And keynum <= 57 Then Command1(keynum - 48).Value = True If keynum = 46 Then Command2.Value = TrueIf UCase(CHAR) = "C" Then Command3.Value = TrueIf keynum = 27 Then Command4.Value = TrueIf keynum = 61 Then Command6.Value = Truekeynum = 0End SubFunction angle(ByVal j1 As Integer) As Singleangle = j1If Option1.Value Then angle = j1 * 3.14 / 180End FunctionFunction ArcSin(ByVal Num As Single) As SingleIf Num = 1 ThenArcSin = 3.1415926 / 2ElseIf Num = -1 ThenArcSin = 3.1415926 * 3 / 2ElseArcSin = Atn(Num / Sqr(-Num * Num + 1))End IfIf Option1.Value Then ArcSin = ArcSin * 180 / 3.1415926End FunctionFunction ArcCos(ByVal Num As Single) As SingleIf Num = 1 ThenArcCos = 0ElseIf Num = -1 ThenArcCos = 3.1415926ElseArcCos = Atn(-Num / Sqr(-Num * Num + 1)) + 2 * Atn(1)End IfIf Option1.Value Then ArcCos = ArcCos * 180 / 3.1415926 End FunctionFunction jiecheng(ByVal n As Integer) As SingleDim COUNT As Integerjiecheng = 1For COUNT = 1 To njiecheng = jiecheng * COUNTNextEnd FunctionFunction n10to2(ByVal Number As Single) As SingleDim IntN As Long 'Number的整数部分Dim FracN As Single 'Number的小数部分Dim ModN As Integer '整数部分换算时,记录余数Dim RltN As String '换算结果Dim i As IntegerIf InStr(Number, "e") > 0 Or InStr(Number, "E") > 0 Then MsgBox "不能转换以科学记数法表示的数据!"Exit FunctionEnd IfModN = 0'Number = Val(Text1.Text)IntN = Int(Number)FracN = Number - IntN'以下代码用于将十进制的整数部分换算为二进制Do While IntN > 0ModN = IntN Mod 2IntN = IntN \ 2RltN = ModN & RltNLoopRltN = RltN & "."i = 1'以下代码用于将十进制的小数部分换算为二进制Do While i <= 7 Or FracN <> 0FracN = FracN * 2If FracN >= 1 ThenFracN = FracN - 1RltN = RltN & "1"ElseRltN = RltN & "0"End Ifi = i + 1Loopn10to2 = RltN'Option3.Value = TrueEnd FunctionFunction n2to10(ByVal Number As Double) As SingleDim i As Integer, j As IntegerDim IntN As Long, FracN As SingleDim RltN As SingleDim POS As Integer '记录小数点位置If InStr(Number, "e") > 0 Or InStr(Number, "E") > 0 ThenMsgBox "不能转换以科学记数法表示的数据!"Exit FunctionEnd IfOn Error GoTo ErrIntN = Int(Number)FracN = Number - IntNDo While IntN > 0 '换算整数部分RltN = RltN + (IntN Mod 10) * 2 ^ jj = j + 1IntN = IntN \ 10LoopPOS = InStr(1, Str(FracN), ".")j = -1For i = POS + 1 To Len(Str(FracN)) '换算小数部分RltN = RltN + 2 ^ j * Val(Mid(Str(FracN), i, 1))j = j - 1Next in2to10 = RltN'Option4.Value = TrueExit FunctionErr:Text1.Text = "数据太大,溢出!"End FunctionPrivate Sub Command1_Click(Index As Integer)'当按下数字键(0-9)时,向文本框尾部追加数据'并通过变量LastInput记录上次按键为数字键If Len(Text1.Text) > 16 Then Exit SubIf Text1.Text = "0" Or LastInput = "Eqv" Then Text1.Text = ""Text1.Text = Text1.Text & Index '追加数据LastInput = "Num"Command1(0).SetFocusEnd SubPrivate Sub Command1_KeyPress(Index As Integer, KeyAscii As Integer) Call keyp(KeyAscii)End SubPrivate Sub Command2_Click()'按下小数点按钮的处理过程'如果数据位数超出范围,或数据中已包含小数点,退出本过程If Len(Text1.Text) > 16 Or InStr(1, Text1.Text, ".") > 0 _And LastInput <> "Eqv" Then Exit Sub'如果以"."开始输入新数据,在"."前加"0";'如果在数据输入过程中按下".",直接将"."追加在数据尾部If LastInput = "Opt" Or LastInput = "Eqv" Or LastInput = "Neg" Then Text1.Text = Text1.Text + "0."ElseText1.Text = Text1.Text + "."End IfLastInput = "Num"Command1(0).SetFocusEnd SubPrivate Sub Command3_Click()'按下"C"(取消) 按钮的Click 事件过程'重新设置并初始化变量。
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计算器 简单程序(包含 进制转换 )
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)
风铃计算器程序代码青春风铃西南交通大学Dim sum As Double, Expr, A, B, D, Cha As String Dim Time As IntegerDim leftbracket, rbracket As IntegerDim Bo1, Bo2, Sto As BooleanPublic Function Fact(n As Long) As DoubleIf n > 0 ThenIf n = 1 ThenFact = 1ElseFact = n * Fact(n - 1)End IfElseIf n = 0 ThenFact = 1ElseIf n = -1 ThenFact = -1ElseFact = n * Fact(n + 1)End IfEnd IfEnd FunctionPrivate Function leftfind(ByV al Expr As String, Where As Long) As String Dim i, leftbracket, rbracket As IntegerDim numl As StringIf Mid(Expr, Where - 1, 1) = ")" Then '-------------左有括号For i = Where To 1 Step -1If Mid(Expr, i, 1) = ")" Thenrbracket = rbracket + 1ElseIf Mid(Expr, i, 1) = "(" Thenlbracket = lbracket + 1End IfIf lbracket = rbracket And lbracket <> 0 Thennuml = Mid(Expr, i, Where - i)Exit ForEnd IfNext iElse '-------------无括号For i = Where - 1 To 1 Step -1numl = Mid(Expr, i, 1)If numl = "+" Or numl = "-" Or numl = "*" Or numl = "/" Or numl = "(" Then numl = Mid(Expr, i + 1, Where - i - 1)Exit ForEnd IfIf i = 1 Thennuml = Mid(Expr, 1, Where - 1)Exit ForEnd IfNext iEnd Ifleftfind = numlEnd FunctionPrivate Function rightfind(ByV al Expr As String, Where As Long) As String Dim i, leftbracket, rbracket As IntegerDim numr As StringIf Mid(Expr, Where + 1, 1) = "(" Then '-------------右有括号For i = Where + 1 To Len(Expr)If Mid(Expr, i, 1) = ")" Thenrbracket = rbracket + 1ElseIf Mid(Expr, i, 1) = "(" Thenlbracket = lbracket + 1End IfIf lbracket = rbracket And lbracket <> 0 Thennumr = Mid(Expr, Where + 1, i - Where)Exit ForEnd IfNext iElse '-------------无括号For i = Where + 1 To Len(Expr)numr = Mid(Expr, i, 1)If numr = "+" Or numr = "-" Or numr = "*" Or numr = "/" Or numl = "(" Then numr = Mid(Expr, Where + 1, i - Where - 1)Exit ForEnd IfIf i = Len(Expr) Thennumr = Mid(Expr, Where + 1, i - Where)Exit ForEnd IfNext iEnd Ifrightfind = numrEnd FunctionPrivate Sub jingdian_Click(Index As Integer)Frame1.BackColor = &H8080FFFrame2.BackColor = &H80FF80Frame3.BackColor = &HFF80FFText2.BackColor = &H80FF80For i = 0 To 11Label1(i).BackColor = &HFF80FFNext ijingdian(0).Enabled = Falsechuantong(1).Enabled = Truepinhong(2).Enabled = TrueEnd SubPrivate Sub chuantong_Click(Index As Integer)Frame1.BackColor = &H8000000FFrame2.BackColor = &H8000000FFrame3.BackColor = &H8000000FText2.BackColor = &H8000000FFor i = 0 To 11Label1(i).BackColor = &H8000000FNext ijingdian(0).Enabled = Truechuantong(1).Enabled = Falsepinhong(2).Enabled = TrueEnd SubPrivate Sub pinhong_Click(Index As Integer)Frame1.BackColor = &HFF80FFFrame2.BackColor = &HFF80FFFrame3.BackColor = &HFF80FFText2.BackColor = &HFF80FFFor i = 0 To 11Label1(i).BackColor = &HFF80FFNext ijingdian(0).Enabled = Truechuantong(1).Enabled = Truepinhong(2).Enabled = FalseEnd SubPrivate Sub Form_Load()A = "0":B = "0": D = "0"Sto = False: Bo = FalseText1.Text = "0"Text2.Text = "青春风铃欢迎您的使用!"jingdian(0).Enabled = FalseEnd Sub'-------------------------------------------------状态栏代码--------------------------------------------------------Private Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) StatusBar1.Panels(2).Text = "数字键"End SubPrivate Sub Frame2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) StatusBar1.Panels(2).Text = "运算符"End SubPrivate Sub Frame3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) StatusBar1.Panels(2).Text = "功能区,选中Shift时执行附加功能"End SubPrivate Sub Command4_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)Select Case IndexCase 0StatusBar1.Panels(2).Text = "退格"Case 1StatusBar1.Panels(2).Text = "清除"Case 2StatusBar1.Panels(2).Text = "左括号"Case 3StatusBar1.Panels(2).Text = "右括号"Case 4StatusBar1.Panels(2).Text = "等于号"End SelectEnd SubPrivate Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) StatusBar1.Panels(2).Text = "风铃计算表达式"End SubPrivate Sub Text2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) StatusBar1.Panels(2).Text = "风铃计算结果"End SubPrivate Sub Check1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) StatusBar1.Panels(2).Text = "功能转换键"End SubPrivate Sub Check2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) StatusBar1.Panels(2).Text = "选中为角度模式,否则为弧度模式"End Sub'---------------------数字键的输入----------------------------Private Sub Command1_Click(Index As Integer)If Time <> 1 ThenText1.Text = "" '清空表达式Time = 1End IfIf Index <= 9 ThenText1.Text = Text1.Text & IndexElseIf Index = 10 ThenText1.Text = Text1.Text & "."ElseText1.Text = Text1.Text & "pi"End IfEnd Sub'---------------------运算符的输入----------------------------Private Sub Command2_Click(Index As Integer)If Time = 0 ThenText1.Text = ""ElseIf Time = 2 ThenText1.Text = "Ans"End IfTime = 1Select Case IndexCase 0Text1.Text = Text1.Text & "+"Case 1Text1.Text = Text1.Text & "-"Case 2Text1.Text = Text1.Text & "*"Case 3Text1.Text = Text1.Text & "/"End SelectEnd Sub'---------------------函数功能的输入----------------------------Private Sub Command3_Click(Index As Integer)'------前处理-------If Index <= 2 Or (Index <= 11 And Index >= 8 And Check1.V alue = 0) Then If Time = 2 ThenText1.Text = "Ans" '引用结果End IfElseIf Time <> 1 ThenText1.Text = "" '清空表达式End IfEnd If'------附加功能-------If Check1.V alue = 0 ThenSelect Case IndexCase 8 '1/xText1.Text = Text1.Text & "^-1"Case 9 'ncrText1.Text = Text1.Text & "C"Case 10 'nprText1.Text = Text1.Text & "P"Case 11 'x!Text1.Text = Text1.Text & "!"End SelectElseIf Check1.V alue = 1 And Sto = False Then If Time <> 1 And Index = 11 ThenText1.Text = "Ans"End IfSelect Case IndexCase 8If Time <> 1 ThenText1.Text = "A="Text2.Text = AElseText1.Text = Text1.Text & "A"End IfCase 9If Time <> 1 ThenText1.Text = "B="Text2.Text = BElseText1.Text = Text1.Text & "B"End IfCase 10If Time <> 1 ThenText1.Text = "D="Text2.Text = DElseText1.Text = Text1.Text & "D"End IfCase 11If Time <> 1 ThenText1.Text = "Ans→"ElseText1.Text = Text1.Text & "→"End IfSto = TrueEnd SelectElse 'check1.value=1 and sto=1Select Case IndexCase 8Text1.Text = Text1.Text & "A"Case 9Text1.Text = Text1.Text & "B"Case 10Text1.Text = Text1.Text & "D"End SelectBo = TrueEnd IfIf Bo = True ThenBo = FalseCommand4_Click (4)End If'------基本功能输入-------If Check1.V alue = 0 ThenSelect Case IndexCase 0 '幂运算Text1.Text = Text1.Text & "^"Case 1 '平方Text1.Text = Text1.Text & "^2"Case 2 '立方Text1.Text = Text1.Text & "^3"Case 3 'logText1.Text = Text1.Text & "ln("Case 4 'sinText1.Text = Text1.Text & "sin("Case 5 'cosText1.Text = Text1.Text & "cos("Case 6 'tanText1.Text = Text1.Text & "tan("Case 7 'lgText1.Text = Text1.Text & "lg("End SelectElseSelect Case IndexCase 0 '根式运算Text1.Text = Text1.Text & "Rn("Case 1 '平方根Text1.Text = Text1.Text & "^(1/2)"Case 2 '立方根Text1.Text = Text1.Text & "^(1/3)"Case 3 'e^xText1.Text = Text1.Text & "e^("Case 4 'asinText1.Text = Text1.Text & "asin("Case 5 'acosText1.Text = Text1.Text & "acos("Case 6 'tanText1.Text = Text1.Text & "atn("Case 7 'lnText1.Text = Text1.Text & "10^("End SelectEnd IfTime = 1End Sub'---------------------常用按钮及等号的代码---------------------------- Private Sub Command4_Click(Index As Integer)Dim Where As LongDim numl, numr, str As StringDim n, r As DoubleDim i, j, lbracket, rbracket As IntegerSelect Case IndexCase 0 '<-- 退格If Len(Text1.Text) >= 2 ThenText1.Text = Left(Text1.Text, Len(Text1.Text) - 1)Time = 1ElseText1.Text = "0"Time = 0End IfCase 1 'AC 清零Text1.Text = "0"Text2.Text = "0"Time = 0sum = 0Case 2 '( 号If Time <> 1 ThenText1.Text = "" '清空表达式Time = 1End IfText1.Text = Text1.Text & "("Case 3 ') 号If Time = 0 ThenText1.Text = "" '清空表达式Time = 1End IfText1.Text = Text1.Text & ")"Case 4 '= 号Expr = Replace(Text1.Text, "pi", "3.14159265358979323846264338327950288419716939937510")Expr = Replace(Expr, "Ans", Text2.Text)Expr = Replace(Expr, " ", "")Expr = Replace(Expr, "=", "")Where = InStr(Expr, "→")If Where <> 0 ThenCha = Right(Expr, 1)Expr = Left(Expr, Len(Expr) - 2)End IfExpr = Replace(Expr, "A", A)Expr = Replace(Expr, "B", B)Expr = Replace(Expr, "D", D)'-------处理括号不足问题----------For i = 1 To Len(Expr)If Mid(Expr, i, 1) = ")" Thenrbracket = rbracket + 1ElseIf Mid(Expr, i, 1) = "(" Thenlbracket = lbracket + 1End IfNext iIf lbracket < rbracket ThenExpr = String(rbracket - lbracket, "(") & ExprElseIf lbracket > rbracket ThenExpr = Expr & String(lbracket - rbracket, ")")End IfSet Sc = CreateObject("ScriptControl")nguage = "VBScript"'---------------------处理acos----------------------------For j = 1 To Len(Expr)Where = InStr(Expr, "acos")If Where <> 0 ThenWhere = Where + 3numr = rightfind(Expr, Where)str = "acos" & numrOn Error GoTo eh1r = CDbl(Sc.Eval(numr))If Check2.V alue = 1 Thenr = (Atn(-r / Sqr(-r * r + 1)) + 2 * Atn(1)) * 45 / Atn(1)ElseIf Check2.V alue = 0 Thenr = Atn(-r / Sqr(-r * r + 1)) + 2 * Atn(1)End IfExpr = Replace(Expr, str, CStr(r))i = 0: numl = "": n = 0: r = 0: Where = 0: str = ""ElseExit ForEnd IfNext j'---------------------处理asin----------------------------For j = 1 To Len(Expr)Where = InStr(Expr, "asin")If Where <> 0 ThenWhere = Where + 3numr = rightfind(Expr, Where)str = "asin" & numrOn Error GoTo eh1r = CDbl(Sc.Eval(numr))If Check2.V alue = 1 Thenr = Atn(r / Sqr(-r * r + 1)) * 45 / Atn(1)ElseIf Check2.V alue = 0 Thenr = Atn(r / Sqr(-r * r + 1))End IfExpr = Replace(Expr, str, CStr(r))i = 0: numl = "": n = 0: r = 0: Where = 0: str = ""ElseExit ForEnd IfNext j'----------------------处理阶乘!--------------------------------------For j = 1 To Len(Expr)Where = InStr(Expr, "!")If Where <> 0 Then '-------------有阶乘numl = leftfind(Expr, Where)str = numl & "!"On Error GoTo eh1n = CDbl(Sc.Eval(numl))n = Fact(Fix(n))Expr = Replace(Expr, str, CStr(n))i = 0: numl = "": n = 0: r = 0: Where = 0: str = ""ElseExit ForEnd IfNext j'----------------------处理排列--------------------------------------For j = 1 To Len(Expr)Where = InStr(Expr, "P")If Where <> 0 Then '-------------有排列numl = leftfind(Expr, Where)numr = rightfind(Expr, Where)str = numl & "P" & numrOn Error GoTo eh1n = CDbl(Sc.Eval(numl))r = CDbl(Sc.Eval(numr))If r > n ThenGoTo eh1End Ifn = Fact(Fix(n)) / Fact(Fix(n - r))Expr = Replace(Expr, str, CStr(n))i = 0: numl = "": n = 0: r = 0: Where = 0: str = ""ElseExit ForEnd IfNext j'----------------------处理组合--------------------------------------For j = 1 To Len(Expr)Where = InStr(Expr, "C")If Where <> 0 Then '-------------有组合numl = leftfind(Expr, Where)numr = rightfind(Expr, Where)str = numl & "C" & numrOn Error GoTo eh1n = CDbl(Sc.Eval(numl))r = CDbl(Sc.Eval(numr))If r > n ThenGoTo eh1End Ifn = Fact(Fix(n)) / Fact(Fix(r)) / Fact(Fix(n - r))Expr = Replace(Expr, str, CStr(n))i = 0: numl = "": n = 0: r = 0: Where = 0: str = ""ElseExit ForEnd IfNext j'----------------------处理其他情况--------------------------------------Expr = Replace(Expr, "Rn(", "^(1/")If Check2.V alue = 1 ThenExpr = Replace(Expr, "atn(", "1/atn(1)*45*atn(")Expr = Replace(Expr, "sin(", "sin(atn(1)/45*")Expr = Replace(Expr, "cos(", "cos(atn(1)/45*")Expr = Replace(Expr, "tan(", "tan(atn(1)/45*")End IfExpr = Replace(Expr, "e^(", "exp(1)^(")Expr = Replace(Expr, "ln(", "log(")Expr = Replace(Expr, "lg(", "1/log(10)*log(")On Error GoTo eh1sum = Sc.Eval(Expr)If Sto = True ThenSelect Case ChaCase "A"A = CDbl(sum)Case "B"B = CDbl(sum)Case "D"D = CDbl(sum)Case "B"End SelectSto = FalseEnd IfText2.Text = sumTime = 2End Select '对应=Exit Subeh1:Text1.Text = "^_^:运行错误,风铃计算表达式不合语法规则!" End Sub。
简单科学计算器vb程序
’//本人写的原始程序'注意没法实现如下功能:10+===然后输入10再=。
此程序会结果出错Dim denghao, fenghao As Boolean 'denghao判断是否按下“=”,fenghao判断是否按下“1/X”Dim xiaoshu, biaoji As Boolean 'xiaoshu判断是否已按“.”,biaoji第一次判断前面是否按过“+”“-”等运算符按钮Dim fuhao As Byte '运算符类型标号Dim leixin As Byte '进制转换类型Dim fistnumber, last As Double 'fistnumber第一个数据,最后一个数据Dim panduan, jinzhi As Boolean 'panduan判断前面是否连续按“+”“-”等运算符按钮Dim denglianxu As Boolean 'denglianxu判断前面是否连续安"="Dim m, n, i, sum As DoubleDim pi As Double 'sin,cosDim kuahao As Boolean '判断是否按下“(”Dim si As StringDim shilu, bajin As Boolean '十六进制下才能输入A-F;八进制下8-9不能输入Dim h, d, o, b As Integer '进制Dim se, s As DoubleDim ejin As Boolean '判断2-9,在二进制下不能输入Private Sub baifeng_Click() '1/X的程序If Not biaoji Thenfuhao = 7If Val(Text1.Text) = "0" ThenText1.Text = "除数不能为零"ElseCall jieguoEnd IfElseCall jieguofuhao = 7Call jieguoEnd Iffenghao = Truexiaoshu = FalseEnd SubPrivate Sub clear_Click()If clear.Value = 1 Then Text1.Text = "0"xiaoshu = Falseclear.Value = 0sum = 1biaoji = Falsepanduan = Falsedenghao = Falselast = 0fistnumber = 0denglianxu = FalseX = 0si = ""i = 0sum = 0shilu = Falsebajin = Falseejin = FalseEnd SubPrivate Sub Command11_Click() '+/-号Text1.Text = -1 * Val(Text1.Text)If Left(Val(Text1.Text), 1) = "." Then Text1.Text = "0" + Text1.Text If Left(Val(Text1.Text), 2) = "-." ThenText1.Text = -1 * Val(Text1.Text)Text1.Text = "-0" + Text1.TextEnd Ifpanduan = Truedenglianxu = Falsedenghao = TrueEnd SubPrivate Sub Command0_Click()If Text1.Text = "0" ThenText1.Text = 0ElseIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "0"ElseText1.Text = "0"denglianxu = Falsefenghao = Falsedenghao = Falsepanduan = FalseEnd IfEnd SubPrivate Sub Command1_Click()If Text1.Text = "0" Then Text1.Text = ""If Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "1" ElseText1.Text = "1"denglianxu = Falsefenghao = Falsedenghao = Falsepanduan = Falsekuahao = FalseEnd IfEnd SubPrivate Sub Command2_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "2" ElseText1.Text = "2"fenghao = Falsedenghao = Falsepanduan = Falsedenglianxu = Falsekuahao = FalseEnd IfEnd SubPrivate Sub Command3_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "3" ElseText1.Text = "3"fenghao = Falsedenghao = Falsepanduan = Falsedenglianxu = Falsekuahao = FalseEnd IfEnd SubPrivate Sub Command4_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "4" ElseText1.Text = "4"fenghao = Falsedenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command5_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "5" ElseText1.Text = "5"denghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command6_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "6" ElseText1.Text = "6"denghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command7_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "7" Elsedenghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command8_Click()If Text1.Text = "0" Then Text1.Text = ""If bajin ThenMsgBox "请输入八进制数"Text1.Text = 0Exit SubEnd IfIf ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "8" ElseText1.Text = "8"denghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command9_Click()If Text1.Text = "0" Then Text1.Text = ""If bajin ThenMsgBox "请输入八进制数"Text1.Text = 0Exit SubEnd IfIf ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "9" ElseText1.Text = "9"denghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command17_Click(Index As Integer) If shilu ThenSelect Case IndexCase 0If Text1.Text = "0" Then Text1.Text = ""If Not denghao And Not fenghao ThenText1.Text = Text1.Text + "A"ElseText1.Text = "A"denghao = Falsefenghao = Falsepanduan = FalseEnd IfCase 1If Text1.Text = "0" Then Text1.Text = ""If Not denghao And Not fenghao ThenText1.Text = Text1.Text + "B"ElseText1.Text = "B"denghao = Falsefenghao = Falsepanduan = FalseEnd IfCase 2If Text1.Text = "0" Then Text1.Text = ""If Not denghao And Not fenghao ThenText1.Text = Text1.Text + "C"ElseText1.Text = "C"denghao = Falsefenghao = Falsepanduan = FalseCase 3If Text1.Text = "0" Then Text1.Text = "" If Not denghao And Not fenghao Then Text1.Text = Text1.Text + "D"ElseText1.Text = "D"denghao = Falsefenghao = Falsepanduan = FalseEnd IfCase 4If Text1.Text = "0" Then Text1.Text = "" If Not denghao And Not fenghao Then Text1.Text = Text1.Text + "E"ElseText1.Text = "E"denghao = Falsefenghao = Falsepanduan = FalseEnd IfCase 5If Text1.Text = "0" Then Text1.Text = "" If Not denghao And Not fenghao Then Text1.Text = Text1.Text + "F"ElseText1.Text = "F"denghao = Falsefenghao = Falsepanduan = FalseEnd IfEnd SelectElseMsgBox "无效函数"End IfEnd SubPrivate Sub eee_Click() 'e为底的指数fuhao = 5Call jieguoxiaoshu = FalsePrivate Sub lne_Click() 'e为底的对数If Text1.Text > 0 Thenfuhao = 6Call jieguoElseMsgBox "函数输入无效", vbRetryCancel, "信息提示" End Ifxiaoshu = FalseEnd SubPrivate Sub exit_Click()EndEnd SubPrivate Sub Form_Load()biaoji = FalseText1.Text = 0sum = 1si = ""xiaoshu = Falsepaiduan = Falsedenghao = Falsedenglianxu = Falseerjin = Falsed = 1i = 0bajin = Falseejin = False'x = 0End SubPrivate Sub jiahao_Click()If Not biaoji Thenfistnumber = Val(Text1.Text)ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 1xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub jianhao_Click()If Not biaoji Thenfistnumber = Val(Text1.Text)ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 2xiaoshu = Falsedenghao = Truepanduan = Truebiaoji = Truedenglianxu = FalseEnd SubPrivate Sub chenghao_Click()If Not biaoji Then '没有按下运算符fistnumber = Val(Text1.Text)ElseIf Not panduan Then '没有连续按运算按钮Call jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 3xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub chuhao_Click()If Not biaoji Thenfistnumber = Val(Text1.Text)ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 4xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub Command10_Click() '加“(”括号m = fuhaon = fistnumberbiaoji = FalseText1.Text = "("kuahao = FalseEnd SubPrivate Sub Com_Click() '加“)”括号Call jieguofistnumber = nfuhao = mpanduan = Falsefenghao = Truexiaoshu = FalseEnd SubPrivate Sub result_Click()If panduan Then '有两个以上连续的运算符If Not denglianxu Then '只按了一个等号Text1.Text = Val(Text1.Text)Call jieguoElse '按两个以上的等号Call jianchuEnd IfElse '没有连续运算符(运算符在两个数中间)'Call xxxdenglianxu = FalseCall jieguoEnd IfEnd SubPrivate Sub point_Click()If Not denghao And Not fenghao ThenIf Not kuahao ThenIf Text1.Text = "." Then Text1.Text = "0."End IfIf Not xiaoshu ThenText1.Text = Text1.Text + "."xiaoshu = TrueEnd IfElseText1.Text = "0."denghao = Falsefenghao = FalseEnd IfEnd SubPublic Sub jianchu() '多个等号连续时调用last = Val(Text1.Text)Text1.Text = fistnumberIf fuhao = 1 Then Text1.Text = last + Text1.TextIf fuhao = 2 Then Text1.Text = last - Text1.TextIf fuhao = 3 Then Text1.Text = last * Text1.TextIf fuhao = 4 ThenIf Val(Text1.Text) = "0" ThenText1.Text = "除数不能为零"ElseText1.Text = last / Val(Text1.Text)End IfEnd IfIf Left(Val(Text1.Text), 1) = "." Then Text1.Text = "0" + Text1.TextEnd SubPrivate Sub jiecheng_Click() '阶乘Dim n As Integer, Y As Double, i As Integer 'double和variant变量最多算到170!long最多算到12!If Val(Text1.Text) < 0 ThenText1.Text = "函数输入无效"ElseIf Val(Text1.Text) >= 171 ThenText1.Text = "超出本计算器计算范围"Elsen = Val(Text1.Text)Y = 1For i = 1 To nY = Y * iNext iText1.Text = Str(Y)End IfEnd SubPrivate Sub duishu_Click() '对数If Val(Text1.Text) <= 0 Or V al(Text1.Text) = 1 ThenText1.Text = "函数输入无效"ElseIf Not biaoji Thenfistnumber = Val(Text1.Text)ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 9xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub zhishu_Click() '指数If Not biaoji Thenfistnumber = Val(Text1.Text) ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 8xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub yuxuan_Click() '余弦fuhao = 10Call jieguoEnd SubPrivate Sub zhengxuan_Click() '正弦fuhao = 11Call jieguoEnd SubPrivate Sub Option1_Click() '16 leixin = 1shilu = Truebajin = Falseejin = FalseCall zhuanhuand = 0o = 0b = 0denghao = TrueEnd SubPrivate Sub Option2_Click() '10 leixin = 2shilu = Falsebajin = Falseejin = FalseCall zhuanhuand = 1h = 0o = 0b = 0denghao = TrueEnd SubPrivate Sub Option3_Click() '8 bajin = Trueleixin = 3shilu = Falseejin = FalseCall zhuanhuano = 1h = 0d = 0b = 0denghao = TrueEnd SubPrivate Sub Option4_Click() '2 leixin = 4ejin = Trueshilu = Falsebajin = FalseCall zhuanhuanb = 1h = 0o = 0denghao = TrueEnd SubPublic Sub zhuanhuan() '进制转换If leixin = 1 ThenIf d = 1 Then Text1.Text = Hex(Text1.Text) '十进制转换成十六进制If o = 1 Then Text1.Text = Hex("&o" & Text1.Text) '八进制转换成十六进制If b = 1 ThenCall ezsText1.Text = Hex(Text1.Text) '二进制转换成十六进制End IfEnd IfIf leixin = 2 ThenIf h = 1 Then Text1.Text = CLng("&h" & Text1.Text) '十六进制转换成十进制If o = 1 Then Text1.Text = CLng("&o" & Text1.Text) '八进制转换成十进制If b = 1 Then Call ezs '二进制转换成十进制End IfIf leixin = 3 Then'If Val(Text1.Text) > 7 Then'MsgBox "请输入八进制数"'Text1.Text = 0'Exit Sub'End If'If Val(Text1.Text) >= 0 And Val(Text1.Text) <= 32767 ThenIf h = 1 Then Text1.Text = Oct("&h" & Text1.Text) '十六进制转换成八进制If d = 1 Then Text1.Text = Oct$(Text1.Text) '十进制转换成八进制If b = 1 ThenCall ezsText1.Text = Oct$(Text1.Text) '二进制转换成八进制End If'Else'MsgBox "请输Integer类型的正数"'Text1.Text = 0'End IfEnd IfIf leixin = 4 ThenIf h = 1 Then '十六进制转换成二进制Text1.Text = CLng("&h" & Text1.Text)Call szeEnd IfIf d = 1 Then Call sze '十进制转换成二进制If o = 1 Then '八进制转换成二进制Text1.Text = CLng("&o" & Text1.Text)Call szeEnd IfIf b = 1 Then '二进制End IfEnd IfEnd SubPublic Sub jieguo() '计算过程和结果If fuhao = 1 ThenText1.Text = fistnumber + V al(Text1.Text)End IfIf fuhao = 2 ThenText1.Text = fistnumber - Val(Text1.Text)End IfIf fuhao = 3 ThenText1.Text = fistnumber * Val(Text1.Text)End IfIf fuhao = 4 ThenIf Val(Text1.Text) = "0" ThenText1.Text = "除数不能为零"ElseText1.Text = fistnumber / Val(Text1.Text)End IfEnd IfIf fuhao = 5 Then Text1.Text = Exp(Val(Text1.Text))If fuhao = 6 Then Text1.Text = Str(Log(Val(Text1.Text))) If fuhao = 7 Then Text1.Text = 1 / Val(Text1.Text)If fuhao = 8 Then '指数Text1.Text = fistnumber ^ Val(Text1.Text)End IfIf fuhao = 9 Then '对数If Val(Text1.Text) = 1 ThenText1.Text = 0Elsesum = Log(Val(Text1.Text)) / Log(fistnumber)Text1.Text = sumEnd IfEnd IfIf fuhao = 10 Thenpi = Val(Text1.Text) / 90If Val(Text1.Text) Mod 90 = 0 And pi Mod 2 <> 0 Then '判断输入值是否为90的奇数倍数,使cos90直接赋为0Text1.Text = 0ElseText1.Text = Cos(Val(Text1.Text) * 3.14159265368979 / 180)End IfEnd IfIf fuhao = 11 Thenpi = Val(Text1.Text) / 90If Val(Text1.Text) Mod 90 = 0 And pi Mod 2 = 0 ThenText1.Text = 0ElseText1.Text = Sin(Val(Text1.Text) * 3.14159265368979 / 180)End IfEnd IfIf Left(Val(Text1.Text), 1) = "." Then Text1.Text = "0" + Text1.TextIf Left(Val(Text1.Text), 2) = "-." ThenText1.Text = -1 * Val(Text1.Text)Text1.Text = "-0" + Text1.TextEnd Ifdenghao = Truexiaoshu = Falsebiaoji = Falsedenglianxu = TrueEnd SubPublic Sub sze() '十进制转换成二进制si = "" '不初始化将出现错误Do Until Val(Text1.Text) = 0s = Val(Text1.Text) Mod 2Text1.Text = Val(Text1.Text) \ 2si = si + Str$(s) 'str$()数值转换成字符串LoopText1.Text = StrReverse(si) '将字符串反序End SubPublic Sub ezs() '二进制转换成十进制sum = 0i = 0 '不赋为零,会出现错误Do Until Val(Text1.Text) = 0se = Val(Text1.Text) Mod 10Text1.Text = Val(Text1.Text) \ 10i = i + 1sum = sum + se * 2 ^ (i - 1)LoopText1.Text = sumEnd Sub。
用VB编写一个简单计算器
用VB编写一个简单计算器一、功能:实现简单的加减乘除功能,C归零,CE取消输入,%计算并显示第一个操作数的百分比。
二、控件:1个label,20个commandbutton。
三、计算器运行界面:四、详细代码:Option ExplicitDim Op1, Op2 '前面输入的操作数Dim DecimalFlag As Integer '小数点仍然存在吗?Dim NumOps As Integer '操作数个数Dim LastInput '指示上一次按键事件的类型Dim OpFlag '指示未完成的操作Dim TempReadout' C (取消) 按钮的Click 事件过程' 重新设置显示并初始化变量Private Sub Cancel_Click()Readout = Format(0, "0.")Op1 = 0Op2 = 0Form_LoadEnd Sub' CE (取消输入) 按钮的Click 事件过程Private Sub CancelEntry_Click()Readout = Format(0, "0.")DecimalFlag = FalseLastInput = "CE"End Sub' 小数点(.) 按钮的Click 事件过程' 如果上一次按键为运算符,初始化readout 为"0.";' 否则显示时追加一个小数点Private Sub Decimal_Click()If LastInput = "NEG" ThenReadout = Format(0, "-0.")ElseIf LastInput <> "NUMS" ThenReadout = Format(0, "0.")End IfDecimalFlag = TrueLastInput = "NUMS"End Sub' 窗体的初始化过程' 设置所有变量为其初始值Private Sub Form_Load()DecimalFlag = FalseNumOps = 0LastInput = "NONE"OpFlag = " "Readout = Format(0, "0.")'Decimal.Caption = Format(0, ".")End Sub' 数字键(0-9) 的Click 事件过程' 向显示中的数追加新数Private Sub Number_Click(Index As Integer)If LastInput <> "NUMS" ThenReadout = Format(0, ".")DecimalFlag = FalseEnd IfIf DecimalFlag ThenReadout = Readout + Number(Index).CaptionElseReadout = Left(Readout, InStr(Readout, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")End IfIf LastInput = "NEG" Then Readout = "-" & ReadoutLastInput = "NUMS"End Sub' 运算符(+, -, x, /, =) 的Click 事件过程' 如果接下来的按键是数字键,增加NumOps。
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制作计算器程序计算器程序是一种用于进行数学计算的工具。
最常见的计算器是电子计算器,它可以实现简单的加减乘除等基本计算。
而现在,我们可以使用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程序设计:计算器
2.3属性设置窗体和各控件的属性设置如下表所示2.4 系统功能本系统的主要功能及任务是1.简单计算2.科学计算2.5 系统功能模块图一.界面设计。
对象属性设置第三章详细设计3.1窗体3.2程序代码Public sum As DoublePublic k As StringPublic pi As DoublePublic c As DoublePublic d As DoublePublic n As DoubleFunction Log10(X)Log10 = Log(X) / Log(10)End FunctionFunction Logn(X)Logn = Log(X) / Log(n)End FunctionPrivate Sub check_Click()Shell "C:\WINDOWS\explorer.exe /263885058/blog/1322900561" End SubPrivate Sub Command1_Click(Index As Integer)Select Case IndexCase 1Text1.Text = Text1.Text & 1Case 2Text1.Text = Text1.Text & 2Case 3Text1.Text = Text1.Text & 3Case 4Text1.Text = Text1.Text & 4Case 5Text1.Text = Text1.Text & 5Case 6Text1.Text = Text1.Text & 6Case 7Text1.Text = Text1.Text & 7Case 8Text1.Text = Text1.Text & 8Case 9Text1.Text = Text1.Text & 9Case 0Text1.Text = Text1.Text & 0Case 10Text1.Text = Text1.Text &"."End SelectEnd SubPrivate Sub Command2_Click(Index As Integer)Select Case IndexCase 0sum = Text1.TextText1.Text = ""k = "+"Case 1sum = Text1.TextText1.Text = ""k = "-"Case 2sum = Text1.TextText1.Text = ""k = "*"Case 3sum = Text1.TextText1.Text = ""k = "/"End SelectEnd SubPrivate Sub Command3_Click()Dim a As Doublea = Text1.TextIf k = "+" Thensum = sum + aText2.Text = sumElseIf k = "-" Thensum = sum - aText2.Text = sumElseIf k = "*" Thensum = sum * aText2.Text = sumElseIf k = "/" Thensum = sum / aText2.Text = sumElseIf k = "sin" Then'等号的三角计算sum = Sin(a * pi / 180)Text2.Text = sumElseIf k = "cos" Thensum = Cos(a * pi / 180)Text2.Text = sumElseIf k = "tan" Thensum = Tan(a * pi / 180)Text2.Text = sumElseIf k = "cot" Thensum = 1 / (Tan(a * pi / 180))Text2.Text = sumElseIf k = "lg" Then'等号的lg计算sum = Log(Val(Text1.Text))Text2.Text = sumElseIf k = "ln" Then'等号的ln计算sum = Log10(Val(Text1.Text))Text2.Text = sumElseIf k = "logn" Then'等号的log n a计算sum = Logn(Val(Text1.Text))Text2.Text = sumElseIf k = "2" Then'等号的幂函数计算sum = (Val(Text1.Text)) ^ 2Text2.Text = sumElseIf k = "c" Thensum = Val(Text1.Text) ^ cText2.Text = sumElseIf k = "0.5" Then'等号的开方运算sum = (Val(Text1.Text)) ^ 0.5Text2.Text = sumElseIf k = "d" Thensum = (Val(Text1.Text)) ^ (1 / d)Text2.Text = sumEnd IfEnd SubPrivate Sub Command4_Click(Index As Integer)Dim b As Integerb = Len(Text1.Text)If b > 1 ThenText1.Text = Val(Str(Left(Text1.Text, Len(Text1.Text) - 1))) ElseText1.Text = ""End IfEnd SubPrivate Sub Command5_Click()Text1.Text = ""Text2.Text = ""Label2.Caption = ""Label3.Caption = ""a = 0b = 0k = ""End SubPrivate Sub Command6_Click(Index As Integer)Select Case IndexCase 0Label2.Caption = "sin"k = "sin"Case 1Label2.Caption = "cos"k = "cos"Case 2Label2.Caption = "tan"k = "tan"Case 3Label2.Caption = "cot"k = "cot"Case 4'对数计算Label2.Caption = "lg"k = "lg"Case 5Label2.Caption = "ln"k = "ln"Case 6n = Val(InputBox("请输入对数运算的底数", 请输入数字)) Label2.Caption = "log" '普通对数计算Label4.Caption = nk = "logn"Case 7'幂运算Label3.Caption = "2"k = "2"Case 8c = Val(InputBox("请输入运算幂指数", 输入数字))Label3.Caption = ck = "c"Case 9'幂运算Label2.Caption = "√"k = "0.5"Case 10'开方运算d = Val(InputBox("请输入需要开多少次方", 输入数字))Label2.Caption = d &"√"k = "d"End SelectEnd SubPrivate Sub Command7_Click()Shell "C:\WINDOWS\explorer.exe " End SubPrivate Sub Command8_Click()Text1.Text = sumEnd SubPrivate Sub Command9_Click()EndEnd SubPrivate Sub end_Click()EndEnd SubPrivate Sub explain_Click()End SubPrivate Sub Form_Load()pi = 4 * Atn(1)End SubPrivate Sub help_Click()End SubPrivate Sub Text1_Change()End Sub。
VB计算器程序代码
VB计算器程序代码下面是一个简单的VB计算器程序代码,可以进行基本的四则运算:```VBImports System.MathPublic Class Form1Dim num1, num2, result As DoubleDim operatorType As String = ""Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.LoadEnd SubPrivate Sub Button_Click(sender As Object, e As EventArgs) Handles btn0.Click, btn1.Click, btn2.Click, btn3.Click,btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click, btnDot.ClickDim button As Button = CType(sender, Button)If button.Text = "." ThenIf Not txtDisplay.Text.Contains(".") ThentxtDisplay.Text += button.TextEnd IfElsetxtDisplay.Text += button.TextEnd IfEnd SubPrivate Sub Operator_Click(sender As Object, e As EventArgs) Handles btnAdd.Click, btnSubtract.Click, btnMultiply.Click, btnDivide.ClickDim button As Button = CType(sender, Button)num1 = CDbl(txtDisplay.Text)operatorType = button.TexttxtDisplay.ClearEnd SubPrivate Sub btnEquals_Click(sender As Object, e As EventArgs) Handles btnEquals.Clicknum2 = CDbl(txtDisplay.Text)Select Case operatorTypeCase "+"result = num1 + num2Case "-"result = num1 - num2Case "*"result = num1 * num2Case "/"If num2 <> 0 Thenresult = num1 / num2ElseMessageBox.Show("除数不能为零!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)End IfEnd SelecttxtDisplay.Text = result.ToStringEnd SubPrivate Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.ClicktxtDisplay.ClearEnd SubPrivate Sub btnSqrt_Click(sender As Object, e As EventArgs) Handles btnSqrt.ClickIf txtDisplay.Text = "" ThenMessageBox.Show("请输入一个数字!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)Elsenum1 = CDbl(txtDisplay.Text)result = Sqrt(num1)txtDisplay.Text = result.ToStringEnd IfEnd SubPrivate Sub btnPower_Click(sender As Object, e As EventArgs) Handles btnPower.ClickIf txtDisplay.Text = "" ThenMessageBox.Show("请输入一个数字!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error)Elsenum1 = CDbl(txtDisplay.Text)result = num1 ^ 2txtDisplay.Text = result.ToStringEnd IfEnd SubPrivate Sub btnBackspace_Click(sender As Object, e As EventArgs) Handles btnBackspace.ClickIf txtDisplay.Text.Length > 0 ThentxtDisplay.Text = txtDisplay.Text.Substring(0, txtDisplay.Text.Length - 1)End IfEnd SubPrivate Sub btnNegative_Click(sender As Object, e As EventArgs) Handles btnNegative.ClickIf txtDisplay.Text.Length > 0 ThenIf txtDisplay.Text.Substring(0, 1) = "-" ThentxtDisplay.Text = txtDisplay.Text.Substring(1, txtDisplay.Text.Length - 1)ElsetxtDisplay.Text = "-" + txtDisplay.TextEnd IfEnd IfEnd SubEnd Class```这个计算器程序具有以下功能:1.支持0-9的数字输入和小数点的输入。
科学计算器vb代码
Width = 630
End
Begin mandButton Cmd_Ln
Caption = "Ln"
Height = 390
Left = 1575
TabIndex = 35
Top = 960
Width = 630
End
Begin mandButton Cmd_Square
Caption = "C"
Height = 405
Left = 4785
TabIndex = 15
Top = 405
Width = 750
End
Begin mandButton Cmd_CE
Caption = "CE"
Height = 405
Left = 3975
TabIndex = 14
Caption = "Tan"
Height = 390
Left = 120
TabIndex = 28
Top = 1935
Width = 630
End
Begin mandButton Cmd_Atan
Caption = "Atan"
Height = 390
Left = 120
TabIndex = 27
TabIndex = 17
Top = 1935
Width = 510
End
Begin mandButton Cmd_sqrt
Caption = "Sqrt"
Height = 390
Left = 5025
TabIndex = 16
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
’//本人写的原始程序'注意没法实现如下功能:10+===然后输入10再=。
此程序会结果出错Dim denghao, fenghao As Boolean 'denghao判断是否按下“=”,fenghao判断是否按下“1/X”Dim xiaoshu, biaoji As Boolean 'xiaoshu判断是否已按“.”,biaoji第一次判断前面是否按过“+”“-”等运算符按钮Dim fuhao As Byte '运算符类型标号Dim leixin As Byte '进制转换类型Dim fistnumber, last As Double 'fistnumber第一个数据,最后一个数据Dim panduan, jinzhi As Boolean 'panduan判断前面是否连续按“+”“-”等运算符按钮Dim denglianxu As Boolean 'denglianxu判断前面是否连续安"="Dim m, n, i, sum As DoubleDim pi As Double 'sin,cosDim kuahao As Boolean '判断是否按下“(”Dim si As StringDim shilu, bajin As Boolean '十六进制下才能输入A-F;八进制下8-9不能输入Dim h, d, o, b As Integer '进制Dim se, s As DoubleDim ejin As Boolean '判断2-9,在二进制下不能输入Private Sub baifeng_Click() '1/X的程序If Not biaoji Thenfuhao = 7If Val(Text1.Text) = "0" ThenText1.Text = "除数不能为零"ElseCall jieguoEnd IfElseCall jieguofuhao = 7Call jieguoEnd Iffenghao = Truexiaoshu = FalseEnd SubPrivate Sub clear_Click()If clear.Value = 1 Then Text1.Text = "0"xiaoshu = Falseclear.Value = 0sum = 1biaoji = Falsepanduan = Falsedenghao = Falselast = 0fistnumber = 0denglianxu = FalseX = 0si = ""i = 0sum = 0shilu = Falsebajin = Falseejin = FalseEnd SubPrivate Sub Command11_Click() '+/-号Text1.Text = -1 * Val(Text1.Text)If Left(Val(Text1.Text), 1) = "." Then Text1.Text = "0" + Text1.Text If Left(Val(Text1.Text), 2) = "-." ThenText1.Text = -1 * Val(Text1.Text)Text1.Text = "-0" + Text1.TextEnd Ifpanduan = Truedenglianxu = Falsedenghao = TrueEnd SubPrivate Sub Command0_Click()If Text1.Text = "0" ThenText1.Text = 0ElseIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "0"ElseText1.Text = "0"denglianxu = Falsefenghao = Falsedenghao = Falsepanduan = FalseEnd IfEnd SubPrivate Sub Command1_Click()If Text1.Text = "0" Then Text1.Text = ""If Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "1" ElseText1.Text = "1"denglianxu = Falsefenghao = Falsedenghao = Falsepanduan = Falsekuahao = FalseEnd IfEnd SubPrivate Sub Command2_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "2" ElseText1.Text = "2"fenghao = Falsedenghao = Falsepanduan = Falsedenglianxu = Falsekuahao = FalseEnd IfEnd SubPrivate Sub Command3_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "3" ElseText1.Text = "3"fenghao = Falsedenghao = Falsepanduan = Falsedenglianxu = Falsekuahao = FalseEnd IfEnd SubPrivate Sub Command4_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "4" ElseText1.Text = "4"fenghao = Falsedenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command5_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "5" ElseText1.Text = "5"denghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command6_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "6" ElseText1.Text = "6"denghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command7_Click()If Text1.Text = "0" Then Text1.Text = ""If ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "7" Elsedenghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command8_Click()If Text1.Text = "0" Then Text1.Text = ""If bajin ThenMsgBox "请输入八进制数"Text1.Text = 0Exit SubEnd IfIf ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubEnd IfIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "8" ElseText1.Text = "8"denghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command9_Click()If Text1.Text = "0" Then Text1.Text = ""If bajin ThenMsgBox "请输入八进制数"Text1.Text = 0Exit SubEnd IfIf ejin ThenMsgBox "请输入二进制数"Text1.Text = 0Exit SubIf Not denghao And Not fenghao ThenIf Not kuahao Then Text1.Text = Text1.Text + "9" ElseText1.Text = "9"denghao = Falsefenghao = Falsepanduan = Falsekuahao = FalseEnd Ifdenglianxu = FalseEnd SubPrivate Sub Command17_Click(Index As Integer) If shilu ThenSelect Case IndexCase 0If Text1.Text = "0" Then Text1.Text = ""If Not denghao And Not fenghao ThenText1.Text = Text1.Text + "A"ElseText1.Text = "A"denghao = Falsefenghao = Falsepanduan = FalseEnd IfCase 1If Text1.Text = "0" Then Text1.Text = ""If Not denghao And Not fenghao ThenText1.Text = Text1.Text + "B"ElseText1.Text = "B"denghao = Falsefenghao = Falsepanduan = FalseEnd IfCase 2If Text1.Text = "0" Then Text1.Text = ""If Not denghao And Not fenghao ThenText1.Text = Text1.Text + "C"ElseText1.Text = "C"denghao = Falsefenghao = Falsepanduan = FalseCase 3If Text1.Text = "0" Then Text1.Text = "" If Not denghao And Not fenghao Then Text1.Text = Text1.Text + "D"ElseText1.Text = "D"denghao = Falsefenghao = Falsepanduan = FalseEnd IfCase 4If Text1.Text = "0" Then Text1.Text = "" If Not denghao And Not fenghao Then Text1.Text = Text1.Text + "E"ElseText1.Text = "E"denghao = Falsefenghao = Falsepanduan = FalseEnd IfCase 5If Text1.Text = "0" Then Text1.Text = "" If Not denghao And Not fenghao Then Text1.Text = Text1.Text + "F"ElseText1.Text = "F"denghao = Falsefenghao = Falsepanduan = FalseEnd IfEnd SelectElseMsgBox "无效函数"End IfEnd SubPrivate Sub eee_Click() 'e为底的指数fuhao = 5Call jieguoxiaoshu = FalsePrivate Sub lne_Click() 'e为底的对数If Text1.Text > 0 Thenfuhao = 6Call jieguoElseMsgBox "函数输入无效", vbRetryCancel, "信息提示" End Ifxiaoshu = FalseEnd SubPrivate Sub exit_Click()EndEnd SubPrivate Sub Form_Load()biaoji = FalseText1.Text = 0sum = 1si = ""xiaoshu = Falsepaiduan = Falsedenghao = Falsedenglianxu = Falseerjin = Falsed = 1i = 0bajin = Falseejin = False'x = 0End SubPrivate Sub jiahao_Click()If Not biaoji Thenfistnumber = Val(Text1.Text)ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 1xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub jianhao_Click()If Not biaoji Thenfistnumber = Val(Text1.Text)ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 2xiaoshu = Falsedenghao = Truepanduan = Truebiaoji = Truedenglianxu = FalseEnd SubPrivate Sub chenghao_Click()If Not biaoji Then '没有按下运算符fistnumber = Val(Text1.Text)ElseIf Not panduan Then '没有连续按运算按钮Call jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 3xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub chuhao_Click()If Not biaoji Thenfistnumber = Val(Text1.Text)ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 4xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub Command10_Click() '加“(”括号m = fuhaon = fistnumberbiaoji = FalseText1.Text = "("kuahao = FalseEnd SubPrivate Sub Com_Click() '加“)”括号Call jieguofistnumber = nfuhao = mpanduan = Falsefenghao = Truexiaoshu = FalseEnd SubPrivate Sub result_Click()If panduan Then '有两个以上连续的运算符If Not denglianxu Then '只按了一个等号Text1.Text = Val(Text1.Text)Call jieguoElse '按两个以上的等号Call jianchuEnd IfElse '没有连续运算符(运算符在两个数中间)'Call xxxdenglianxu = FalseCall jieguoEnd IfEnd SubPrivate Sub point_Click()If Not denghao And Not fenghao ThenIf Not kuahao ThenIf Text1.Text = "." Then Text1.Text = "0."End IfIf Not xiaoshu ThenText1.Text = Text1.Text + "."xiaoshu = TrueEnd IfElseText1.Text = "0."denghao = Falsefenghao = FalseEnd IfEnd SubPublic Sub jianchu() '多个等号连续时调用last = Val(Text1.Text)Text1.Text = fistnumberIf fuhao = 1 Then Text1.Text = last + Text1.TextIf fuhao = 2 Then Text1.Text = last - Text1.TextIf fuhao = 3 Then Text1.Text = last * Text1.TextIf fuhao = 4 ThenIf Val(Text1.Text) = "0" ThenText1.Text = "除数不能为零"ElseText1.Text = last / Val(Text1.Text)End IfEnd IfIf Left(Val(Text1.Text), 1) = "." Then Text1.Text = "0" + Text1.TextEnd SubPrivate Sub jiecheng_Click() '阶乘Dim n As Integer, Y As Double, i As Integer 'double和variant变量最多算到170!long最多算到12!If Val(Text1.Text) < 0 ThenText1.Text = "函数输入无效"ElseIf Val(Text1.Text) >= 171 ThenText1.Text = "超出本计算器计算范围"Elsen = Val(Text1.Text)Y = 1For i = 1 To nY = Y * iNext iText1.Text = Str(Y)End IfEnd SubPrivate Sub duishu_Click() '对数If Val(Text1.Text) <= 0 Or V al(Text1.Text) = 1 ThenText1.Text = "函数输入无效"ElseIf Not biaoji Thenfistnumber = Val(Text1.Text)ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 9xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub zhishu_Click() '指数If Not biaoji Thenfistnumber = Val(Text1.Text) ElseIf Not panduan ThenCall jieguofistnumber = Val(Text1.Text)ElseText1.Text = Val(Text1.Text)End Iffuhao = 8xiaoshu = Falsebiaoji = Truedenghao = Truepanduan = Truedenglianxu = FalseEnd SubPrivate Sub yuxuan_Click() '余弦fuhao = 10Call jieguoEnd SubPrivate Sub zhengxuan_Click() '正弦fuhao = 11Call jieguoEnd SubPrivate Sub Option1_Click() '16 leixin = 1shilu = Truebajin = Falseejin = FalseCall zhuanhuand = 0o = 0b = 0denghao = TrueEnd SubPrivate Sub Option2_Click() '10 leixin = 2shilu = Falsebajin = Falseejin = FalseCall zhuanhuand = 1h = 0o = 0b = 0denghao = TrueEnd SubPrivate Sub Option3_Click() '8 bajin = Trueleixin = 3shilu = Falseejin = FalseCall zhuanhuano = 1h = 0d = 0b = 0denghao = TrueEnd SubPrivate Sub Option4_Click() '2 leixin = 4ejin = Trueshilu = Falsebajin = FalseCall zhuanhuanb = 1h = 0o = 0denghao = TrueEnd SubPublic Sub zhuanhuan() '进制转换If leixin = 1 ThenIf d = 1 Then Text1.Text = Hex(Text1.Text) '十进制转换成十六进制If o = 1 Then Text1.Text = Hex("&o" & Text1.Text) '八进制转换成十六进制If b = 1 ThenCall ezsText1.Text = Hex(Text1.Text) '二进制转换成十六进制End IfEnd IfIf leixin = 2 ThenIf h = 1 Then Text1.Text = CLng("&h" & Text1.Text) '十六进制转换成十进制If o = 1 Then Text1.Text = CLng("&o" & Text1.Text) '八进制转换成十进制If b = 1 Then Call ezs '二进制转换成十进制End IfIf leixin = 3 Then'If Val(Text1.Text) > 7 Then'MsgBox "请输入八进制数"'Text1.Text = 0'Exit Sub'End If'If Val(Text1.Text) >= 0 And Val(Text1.Text) <= 32767 ThenIf h = 1 Then Text1.Text = Oct("&h" & Text1.Text) '十六进制转换成八进制If d = 1 Then Text1.Text = Oct$(Text1.Text) '十进制转换成八进制If b = 1 ThenCall ezsText1.Text = Oct$(Text1.Text) '二进制转换成八进制End If'Else'MsgBox "请输Integer类型的正数"'Text1.Text = 0'End IfEnd IfIf leixin = 4 ThenIf h = 1 Then '十六进制转换成二进制Text1.Text = CLng("&h" & Text1.Text)Call szeEnd IfIf d = 1 Then Call sze '十进制转换成二进制If o = 1 Then '八进制转换成二进制Text1.Text = CLng("&o" & Text1.Text)Call szeEnd IfIf b = 1 Then '二进制End IfEnd IfEnd SubPublic Sub jieguo() '计算过程和结果If fuhao = 1 ThenText1.Text = fistnumber + V al(Text1.Text)End IfIf fuhao = 2 ThenText1.Text = fistnumber - Val(Text1.Text)End IfIf fuhao = 3 ThenText1.Text = fistnumber * Val(Text1.Text)End IfIf fuhao = 4 ThenIf Val(Text1.Text) = "0" ThenText1.Text = "除数不能为零"ElseText1.Text = fistnumber / Val(Text1.Text)End IfEnd IfIf fuhao = 5 Then Text1.Text = Exp(Val(Text1.Text))If fuhao = 6 Then Text1.Text = Str(Log(Val(Text1.Text))) If fuhao = 7 Then Text1.Text = 1 / Val(Text1.Text)If fuhao = 8 Then '指数Text1.Text = fistnumber ^ Val(Text1.Text)End IfIf fuhao = 9 Then '对数If Val(Text1.Text) = 1 ThenText1.Text = 0Elsesum = Log(Val(Text1.Text)) / Log(fistnumber)Text1.Text = sumEnd IfEnd IfIf fuhao = 10 Thenpi = Val(Text1.Text) / 90If Val(Text1.Text) Mod 90 = 0 And pi Mod 2 <> 0 Then '判断输入值是否为90的奇数倍数,使cos90直接赋为0Text1.Text = 0ElseText1.Text = Cos(Val(Text1.Text) * 3.14159265368979 / 180)End IfEnd IfIf fuhao = 11 Thenpi = Val(Text1.Text) / 90If Val(Text1.Text) Mod 90 = 0 And pi Mod 2 = 0 ThenText1.Text = 0ElseText1.Text = Sin(Val(Text1.Text) * 3.14159265368979 / 180)End IfEnd IfIf Left(Val(Text1.Text), 1) = "." Then Text1.Text = "0" + Text1.TextIf Left(Val(Text1.Text), 2) = "-." ThenText1.Text = -1 * Val(Text1.Text)Text1.Text = "-0" + Text1.TextEnd Ifdenghao = Truexiaoshu = Falsebiaoji = Falsedenglianxu = TrueEnd SubPublic Sub sze() '十进制转换成二进制si = "" '不初始化将出现错误Do Until Val(Text1.Text) = 0s = Val(Text1.Text) Mod 2Text1.Text = Val(Text1.Text) \ 2si = si + Str$(s) 'str$()数值转换成字符串LoopText1.Text = StrReverse(si) '将字符串反序End SubPublic Sub ezs() '二进制转换成十进制sum = 0i = 0 '不赋为零,会出现错误Do Until Val(Text1.Text) = 0se = Val(Text1.Text) Mod 10Text1.Text = Val(Text1.Text) \ 10i = i + 1sum = sum + se * 2 ^ (i - 1)LoopText1.Text = sumEnd Sub。