计算器vb源代码
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简单的计算机源代码
vb简单的计算机源代码.txt如果xx的时光在闲散中度过,那么回忆岁月将是一场凄凉的悲剧。
杂草多的地方庄稼少,空话多的地方xx少。
即使路上没有花朵,我仍可以欣赏荒芜。
Private Sub Command1_Click()Form1.Caption = "欢迎使用智能计算器"'载入默认正常显示If Check1.Value = "0" Then'1类分歧ElseIf Text1.Text = "" Or Text2.Text = "" Then'2类分歧Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then'2类分歧Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"Else'2类分歧Dim a, b, c As Doublea = Val(Text1.Text)b = Val(Text2.Text)c = a + bText3.Text = cText1.Text = ""Text2.Text = ""End IfIf Check1.Value = "1" Then'1类分歧ElseIf Text1.Text = "" Or Text2.Text = "" Then'2类分歧Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then'2类分歧Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"Else'2类分歧Dim d, e, f As Doubled = Val(Text1.Text)e = Val(Text2.Text)f = d + eText3.Text = fEnd IfEnd SubPrivate Sub Command2_Click()Form1.Caption = "欢迎使用智能计算器"If Check1.Value = "1" ThenElseIf Text1.Text = "" Or Text2.Text = "" ThenForm1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" ThenForm1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseDim d, e, f As Doubled = Val(Text1.Text)e = Val(Text2.Text)f = d - eText3.Text = fEnd IfIf Check1.Value = "0" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseDim a, b, c As Doublea = Val(Text1.Text)b = Val(Text2.Text)c = a - bText3.Text = cText1.Text = ""Text2.Text = ""End IfEnd SubPrivate Sub Command3_Click()Form1.Caption = "欢迎使用智能计算器"If Check1.Value = "1" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseDim d, e, f As Doubled = Val(Text1.Text)e = Val(Text2.Text)f = d * eText3.Text = fEnd IfIf Check1.Value = "0" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseDim a, b, c As Doublea = Val(Text1.Text)b = Val(Text2.Text)c = a * bText3.Text = cText1.Text = ""Text2.Text = ""End IfEnd SubPrivate Sub Command4_Click()Form1.Caption = "欢迎使用智能计算器"If Check1.Value = "0" ThenElseIf Text1.Text = "" Or Text2.Text = "" ThenForm1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Val(Text2.Text) = "0" ThenForm1.Caption = "xataliq kuruldi"Text3.Text = "分数的分子不能为零"ElseDim a, b, c As Doublea = Val(Text1.Text)b = Val(Text2.Text)c = a / bText3.Text = cText1.Text = ""Text2.Text = ""End IfIf Check1.Value = "1" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Val(Text2.Text) = "0" ThenForm1.Caption = "xataliq kuruldi"Text3.Text = "分数的分子不能为零"ElseDim d, e, f As Doubled = Val(Text1.Text)e = Val(Text2.Text)f = d / eText3.Text = fEnd IfEnd SubPrivate Sub Command5_Click()Form1.Caption = "欢迎使用智能计算器" Text1.Text = ""Text2.Text = ""Text3.Text = ""End SubPrivate Sub Command6_Click()Form1.HideForm3.ShowEnd SubPrivate Sub Command7_Click()EndEnd SubPrivate Sub Command8_Click()Form1.Caption = "欢迎使用智能计算器" If Text3.Text <> "" ThenText1.Text = Text3.TextText2.Text = ""Text3.Text = ""ElseForm1.Caption = "xataliq kuruldi"Text3.Text = "没有结果无法继续"End IfEnd SubPrivate Sub Text2_Change()End SubPrivate Sub 乘_Click()If Check1.Value = "1" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseDim d, e, f As Doubled = Val(Text1.Text)e = Val(Text2.Text)f = d * eText3.Text = fEnd IfIf Check1.Value = "0" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseDim a, b, c As Doublea = Val(Text1.Text)b = Val(Text2.Text)c = a * bText3.Text = cText1.Text = ""Text2.Text = ""End IfEnd SubPrivate Sub 除_Click()Form1.Caption = "欢迎使用智能计算器"If Check1.Value = "0" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Val(Text2.Text) = "0" ThenForm1.Caption = "xataliq kuruldi"Text3.Text = "分数的分子不能为零"ElseDim a, b, c As Doublea = Val(Text1.Text)b = Val(Text2.Text)c = a / bText3.Text = cText1.Text = ""Text2.Text = ""End IfIf Check1.Value = "1" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "错误"Text3.Text = "运算数值不能为空"ElseIf Val(Text2.Text) = "0" ThenForm1.Caption = "错误"Text3.Text = "分数的分子不能为零"ElseDim d, e, f As Doubled = Val(Text1.Text)e = Val(Text2.Text)f = d / eText3.Text = fEnd IfEnd SubPrivate Sub munasiwetlik_Click()Form1.Caption = "欢迎使用智能计算器" Form1.HideForm3.ShowEnd SubPrivate Sub 继续_Click()Form1.Caption = "欢迎使用智能计算器" If Text3.Text <> "" ThenText1.Text = Text3.TextText2.Text = ""Text3.Text = ""ElseForm1.Caption = "xataliq"Text3.Text = "没有结果无法继续"End IfEnd SubPrivate Sub 加_Click()Form1.Caption = "欢迎使用智能计算器"If Check1.Value = "0" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "错误"Text3.Text = "运算数值不能为空"ElseDim a, b, c As Doublea = Val(Text1.Text)b = Val(Text2.Text)c = a + bText3.Text = cText1.Text = ""Text2.Text = ""End IfIf Check1.Value = "1" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseDim d, e, f As Doubled = Val(Text1.Text)e = Val(Text2.Text)f = d + eText3.Text = fEnd IfEnd SubPrivate Sub 减_Click()Form1.Caption = "欢迎使用智能计算器"If Check1.Value = "1" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "xataliq kuruldi"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "错误"Text3.Text = "运算数值不能为空"ElseDim d, e, f As Doubled = Val(Text1.Text)e = Val(Text2.Text)f = d - eText3.Text = fEnd IfIf Check1.Value = "0" ThenElseIf Text1.Text = "" Or Text2.Text = "" Then Form1.Caption = "错误"Text3.Text = "运算数值不能为空"ElseIf Text1.Text = "" And Text2.Text = "" Then Form1.Caption = "错误"Text3.Text = "运算数值不能为空"ElseDim a, b, c As Doublea = Val(Text1.Text)b = Val(Text2.Text)Text3.Text = cText1.Text = ""Text2.Text = ""End IfEnd SubPrivate Sub 清空_Click()Form1.Caption = "欢迎使用智能计算器" Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub----------------------------------------------form2Private Sub Command1_Click()Form3.HideForm1.ShowForm1.Text3.Text = ""End SubPrivate Sub Command2_Click()End。
vb简易计算器源码
vb简易计算器源码代码如下:复制代码代码如下:/***Author:乌鸟heart*Version:1.0*/Dim IntX As Double '全局变量,⽤于存储计算的数值Dim IntOperation As Double '标记运算类型Dim isBegin As Boolean '标记是否已经给IntX赋值Public Sub Clear() '清空命令函数screen.Caption = ""End SubPublic Sub SavaToIntX()Select Case IntOperationCase 1 '加法If isBegin = False ThenIntX = Val(screen.Caption)isBegin = TrueElseIntX = IntX + Val(screen.Caption)End IfCase 2 '减法If isBegin = False ThenIntX = Val(screen.Caption)isBegin = TrueElseIntX = IntX - Val(screen.Caption)End IfCase 3 '乘法If isBegin = False ThenIntX = Val(screen.Caption)isBegin = TrueElseIntX = IntX * Val(screen.Caption)'screen.Caption = IntXEnd IfCase 4 '除法If isBegin = False ThenIntX = Val(screen.Caption)isBegin = TrueElseIntX = IntX / Val(screen.Caption)End IfEnd SelectEnd SubPrivate Sub Command0_Click()screen.Caption = screen.Caption & 0End SubPrivate Sub Command1_Click()screen.Caption = screen.Caption & 1End SubPrivate Sub Command2_Click()screen.Caption = screen.Caption & 2End SubPrivate Sub Command3_Click()screen.Caption = screen.Caption & 3End SubPrivate Sub Command4_Click()screen.Caption = screen.Caption & 4End SubPrivate Sub Command5_Click()screen.Caption = screen.Caption & 5End SubPrivate Sub Command6_Click()screen.Caption = screen.Caption & 6End SubPrivate Sub Command7_Click()screen.Caption = screen.Caption & 7End SubPrivate Sub Command8_Click()screen.Caption = screen.Caption & 8End SubPrivate Sub Command9_Click()screen.Caption = screen.Caption & 9End SubPrivate Sub CommandClear_Click() '清空命令isBegin = FalseIntOperation = 0IntX = 0screen.Caption = ""End SubPrivate Sub CommandEqual_Click() '等号运算If IntOperation <> 0 Then '有运算标记的情况Call SavaToIntXIntOperation = 0isBegin = Falsescreen.Caption = IntXEnd IfEnd SubPrivate Sub CommandMinus_Click() '减法运算If IntOperation <> 0 Then '有运算标记的情况Call SavaToIntXIntOperation = 2Call ClearElseIntOperation = 2Call SavaToIntXCall ClearEnd IfEnd SubPrivate Sub CommandMultiple_Click() '乘法运算If IntOperation <> 0 Then '有运算标记的情况Call SavaToIntXIntOperation = 3Call ClearElseIntOperation = 3Call SavaToIntXCall ClearEnd IfEnd SubPrivate Sub CommandPlus_Click() '加法运算If IntOperation <> 0 Then '有运算标记的情况Call SavaToIntXIntOperation = 1Call ClearElseIntOperation = 1Call SavaToIntXCall ClearEnd IfEnd SubPrivate Sub CommandSlash_Click() '除法运算If IntOperation <> 0 Then '有运算标记的情况Call SavaToIntXIntOperation = 4Call ClearElseIntOperation = 4Call SavaToIntXCall ClearEnd IfEnd Sub。
VB计算器源代码
VB计算器源代码Private Data As DoublePrivate lOperation As LongPrivate fClear As BooleanPrivate Sub Command1_Click(Index As Integer)If fClear = True Then Text1.Text = "": fClear = FalseText1.Text = Text1.Text & IndexEnd SubPrivate Sub Command2_Click()If InStr(1, Text1.Text, ".") <= 0 Then Text1.Text = Text1.Text & "."End SubPrivate Sub Command3_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 0End SubPrivate Sub Command4_Click()If Len(Text1.Text) > 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)End SubPrivate Sub Command5_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 1End SubPrivate Sub Command6_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 2End SubPrivate Sub Command7_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 3End SubPrivate Sub Command8_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 4End SubPrivate Sub Command9_Click()Text1.Text = ""lOperation = 0End Sub。
计算器(用vb)代码
计算器(用vb)代码Dim dflag As IntegerDim I As IntegerDim opnre As IntegerDim prev As DoubleDim oflag As IntegerDim ind As IntegerDim soundbz As BooleanDim ProgramPath As StringPrivate Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal Cx As Long, ByVal Cy As Long, ByVal wFlags As Long) As LongPublic Sub SetOnTop(ByVal IsOnTop As Integer)Dim rtn As LongIf IsOnTop = 1 Then'将窗口置于最上面rtn = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)Elsertn = SetWindowPos(Me.hwnd, -2, 0, 0, 0, 0, 3)End IfEnd SubPrivate Sub Check1_Click()If Check1.Value = 1 ThenSetOnTop 1ElseSetOnTop 0End IfEnd SubPrivate Sub Command1_Click(Index As Integer)text1 = Trim(text1)If Len(text1) > 20 ThenBeepExit SubEnd Ifsoundbz = Falsemand = "Close"MMControl1.FileName = ProgramPath & "/声音文件/" & Index & ".wav"mand = "Open"mand = "Play"If ind = 4 Thenprev = 0text1.Caption = " "ind = 0End Ifopnre = 0If oflag = 0 Thentext1.Caption = " "End Ifoflag = 1If Command1(Index).Caption <> "." ThenIf text1.Caption <> " 0" Thentext1.Caption = text1.Caption & Command1(Index).CaptionText = Mid(text1, 1, 1)If Text = "." Thentext1 = "0" & text1End IfElsetext1.Caption = " " & Command1(Index).CaptionEnd IfElseIf dflag = 0 Thentext1.Caption = text1.Caption & "."dflag = 1ElseCommand6.SetFocusExit SubEnd IfEnd IfCommand6.SetFocusEnd SubPrivate Sub Command1_KeyPress(Index As Integer, KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0End SubPrivate Sub Command2_Click(Index As Integer)soundbz = Falsemand = "Close"If Index = 0 Then MMControl1.FileName = ProgramPath & "/声音文件/加.wav"If Index = 1 Then MMControl1.FileName = ProgramPath & "/声音文件/减.wav"If Index = 3 Then MMControl1.FileName = ProgramPath & "/声音文件/乘.wav"If Index = 2 Then MMControl1.FileName = ProgramPath & "/声音文件/除.wav"If Index = 4 ThenMMControl1.FileName = ProgramPath & "/声音文件/等于.wav"soundbz = TrueEnd Ifmand = "Open"mand = "Play"If opnre = 0 Or Index = 4 ThenIf ind = 0 Thenprev = prev + Val(text1.Caption)ElseIf ind = 1 Thenprev = prev - Val(text1.Caption)ElseIf ind = 2 ThenIf Val(text1.Caption) = 0 Thentext1 = "错误!"BeepCommand6.SetFocusExit SubElseprev = prev / Val(text1.Caption)End IfElseIf ind = 3 Thenprev = prev * Val(text1.Caption)End Iftext1.Caption = Str(prev)oflag = 0End Ifopnre = 1ind = Indexdflag = 0Command6.SetFocusIf Index = 4 ThenIf Option1.Value = True Then text1 = Trim(Round(text1, 2))If Option2.Value = True Then text1 = Trim(Round(text1, 3))If Option3.Value = True Then text1 = Trim(Round(text1, 4))If Option4.Value = True Then text1 = Trim(text1)If text1 <> 0 ThenText = Mid(text1, 1, 1)If Text = "." Thentext1 = "0" & text1End IfEnd Ifls = Len(text1)If ls <> 0 ThenFor I = 1 To lst = Mid(text1, I, 1)DoEventsDo While (MMControl1.Mode <> 525) And soundbzDoEventsLoopmand = "Close"If t <> "." ThenIf t = "-" ThenMMControl1.FileName = ProgramPath & "/声音文件/负.wav"ElseMMControl1.FileName = ProgramPath & "/声音文件/" & t & ".wav"End IfElseMMControl1.FileName = ProgramPath & "/声音文件/10.wav"End Ifmand = "Open"mand = "Play"Next IEnd IfEnd IfEnd SubPrivate Sub Command2_KeyPress(Index As Integer, KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0End SubPrivate Sub Command3_Click()soundbz = Falsemand = "Close"MMControl1.FileName = ProgramPath & "/声音文件/归零.wav"mand = "Open"mand = "Play"text1.Caption = " 0"Command6.SetFocusEnd SubPrivate Sub Command3_KeyPress(KeyAscii As Integer)If KeyAscii = 13 Then KeyAscii = 0End SubPrivate Sub Command4_Click()soundbz = Falsemand = "Close"MMControl1.FileName = ProgramPath & "/声音文件/清除.wav"mand = "Open"mand = "Play"dflag = 0prev = 0oflag = 0ind = 0opnre = 0text1.Caption = " 0"Command6.SetFocusEnd SubPrivate Sub Command4_KeyPress(KeyAscii As Integer)If KeyAscii = 13 Then KeyAscii = 0End SubPrivate Sub Command5_Click()soundbz = FalseSaveSetting App.EXEName, "保留", "n1", Option1.Value SaveSetting App.EXEName, "保留", "n2", Option2.Value SaveSetting App.EXEName, "保留", "n3", Option3.Value SaveSetting App.EXEName, "保留", "n4", Option4.Value SaveSetting App.EXEName, "置顶", "yorn", Check1.Value ' mand = "Close"Unload MeEnd SubPrivate Sub Command5_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then KeyAscii = 0End SubPrivate Sub Command6_Click()Command2_Click (4)End SubPrivate Sub Form_KeyPress(KeyAscii As Integer)If text1 = "错误!" ThenCommand4_ClickEnd IfIf KeyAscii = Asc(".") ThenI = 10Command1_Click (I)ElseIf KeyAscii = Asc("0") ThenI = 0Command1_Click (I)ElseIf KeyAscii = Asc("1") ThenI = 1Command1_Click (I)ElseIf KeyAscii = Asc("2") ThenI = 2Command1_Click (I)ElseIf KeyAscii = Asc("3") ThenI = 3Command1_Click (I)ElseIf KeyAscii = Asc("4") ThenI = 4Command1_Click (I)ElseIf KeyAscii = Asc("5") ThenI = 5Command1_Click (I)ElseIf KeyAscii = Asc("6") ThenI = 6Command1_Click (I)ElseIf KeyAscii = Asc("7") ThenI = 7Command1_Click (I)ElseIf KeyAscii = Asc("8") ThenI = 8Command1_Click (I)ElseIf KeyAscii = Asc("9") ThenI = 9Command1_Click (I)ElseIf KeyAscii = Asc("0") ThenI = 0Command1_Click (I)ElseIf KeyAscii = Asc("+") ThenI = 0Command2_Click (I) ElseIf KeyAscii = Asc("+") ThenCommand2_Click (I)ElseIf KeyAscii = Asc("-") ThenI = 1Command2_Click (I)ElseIf KeyAscii = Asc("/") ThenI = 2Command2_Click (I)ElseIf KeyAscii = Asc("*") ThenI = 3Command2_Click (I)ElseIf KeyAscii = Asc("=") Or KeyAscii = 13 ThenI = 4Command2_Click (I)ElseIf KeyAscii = Asc("c") Or KeyAscii = Asc("C") Or KeyAscii = 27 Then Command4_ClickElseIf KeyAscii = Asc("d") Or KeyAscii = Asc("D") ThenCommand3_ClickEnd IfEnd SubPrivate Sub Form_Load()If App.PrevInstance = True ThenUnload MeMsgBox "程序正在运行,不可重复运行多个!", 64, "系统提示"EndEnd Ifsoundbz = Truedflag = 0prev = 0oflag = 0ind = 0Clipboard.ClearMMControl1.DeviceType = "WaveAudio"ProgramPath = App.PathOption1.Value = GetSetting(App.EXEName, "保留", "n1", True) Option2.Value = GetSetting(App.EXEName, "保留", "n2", False) Option3.Value = GetSetting(App.EXEName, "保留", "n3", False) Option4.Value = GetSetting(App.EXEName, "保留", "n4", False) Check1.Value = GetSetting(App.EXEName, "置顶", "yorn", 0)End SubPrivate Sub Form_Unload(Cancel As Integer)mand = "Close"EndEnd SubPrivate Sub text1_Click()End Sub。
科学计算器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计算器源代码
Private Sub txtDisplay_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyNumpad0
cmdNumber_Click 0
Case vbKeyNumpad1
' 显示小数点
Private Sub cmdDecimal_Click()
If InStr(txtDisplay.Text, ".") Then
Beep
Else
If NewEntry Then
txtDisplay.Text = "."
NewEntry = False
Else
txtDisplay.Text = txtDisplay.Text & "."
End If
End If
End Sub
'计算上一操作符的运算结果
Private Sub cmdEquals_Click()
Case vbKeyBack, vbKeyDelete
DeleteCharacter
End Select
KeyCode = 0
End Sub
cmdNumber_Click 4
Case vbKeyNumpad5
cmdNumber_Click 5
Case vbKeyNumpad6
cmdNumber_Click 6
Case vbKeyNumpad7
Case vbKeySubtract
cmdOperator_Click opSubtract
计算器VB代码
End If
w = InStr(1, m(i), "sin[")
If w Then
a1 = Val(Mid(m(i), 5, Len(m(i)) - 5))
End If
add = add + check
If i = d, 1, 1) = "M" Then
add = "-" & Mid(add, 2, Len(add) - 1)
End If
End If
Loop
'===============过滤了符号下一处理是式子里没有括号=======================================
'=========================将字符和运算符号分离==========================================
If w Then
a1 = Val(Mid(m(i), 1, w - 1)) '高级用方括号填写参数,避免和小括号处理冲突
a2 = Val(Mid(m(i), w + 1, Len(m(i)) - w))
For i = 1 To Len(s) '把符号和数字分开呈数组
Dim check As String
check = Mid(s, i, 1)
If check = "*" Or check = "/" Or check = "-" Or check = "+" Or check = "$" Or check = "\" Or check = "&" Then '在四则运算中判断符号
VB简单计算器编程代码(附图)
课程设计说明书正文一、题目:计算器的创作和相应程序的编写二、本题的主要功能:通过计算器的创作熟悉各控件的属性和练习程序的编写。
三、程序截图:四、源程序清单:Begin VB.Form Form1Caption = "计算器"ClientHeight = 3765ClientLeft = 165ClientTop = 855ClientWidth = 5355Icon = "Form1.frx":0000LinkTopic = "Form1"LockControls = -1 'TrueScaleHeight = 3765ScaleWidth = 5355StartUpPosition = 3 '窗口缺省Begin mandButton Command4Caption = "="Height = 495Left = 4470TabIndex = 28Top = 3060Width = 735EndBegin mandButton Command3 Caption = "1/x"Height = 495Left = 4470TabIndex = 27Top = 2520Width = 735EndBegin mandButton Command2 Caption = "%"Height = 495Left = 4470TabIndex = 26Top = 1980Width = 735EndBegin mandButton Command1 Caption = "sqrt"Height = 495Left = 4470TabIndex = 25Top = 1440Width = 735EndBegin mandButton cmbDOT Caption = "."Height = 495Left = 2910TabIndex = 24Top = 3060Width = 735EndBegin mandButton cmbZF Caption = "+/-"Height = 495Left = 2130TabIndex = 23Top = 3060Width = 735 EndBegin mandButton cmbSign Caption = "+"Height = 495Index = 3Left = 3690TabIndex = 22Top = 3060Width = 735 EndBegin mandButton cmbSign Caption = "-"Height = 495Index = 2Left = 3690TabIndex = 21Top = 2520Width = 735 EndBegin mandButton cmbSign Caption = "*"Height = 495Index = 1Left = 3690TabIndex = 20Top = 1980Width = 735EndBegin mandButton cmbSign Caption = "/"Height = 495Index = 0Left = 3690TabIndex = 19Top = 1440Width = 735EndBegin mandButton cmbNUM Caption = "9"Height = 495Index = 9Left = 2910TabIndex = 18Top = 1440Width = 735EndBegin mandButton cmbNUM Caption = "8"Height = 495Index = 8Left = 2130TabIndex = 17Top = 1440Width = 735EndBegin mandButton cmbNUM Caption = "7"Height = 495Index = 7Left = 1350TabIndex = 16Width = 735EndBegin mandButton cmbNUM Caption = "6"Height = 495Index = 6Left = 2910TabIndex = 15Top = 1980Width = 735EndBegin mandButton cmbNUM Caption = "5"Height = 495Index = 5Left = 2130TabIndex = 14Top = 1980Width = 735EndBegin mandButton cmbNUM Caption = "4"Height = 495Index = 4Left = 1350TabIndex = 13Top = 1980Width = 735EndBegin mandButton cmbNUM Caption = "3"Height = 495Index = 3TabIndex = 12Top = 2520Width = 735EndBegin mandButton cmbNUM Caption = "2"Height = 495Index = 2Left = 2130TabIndex = 11Top = 2520Width = 735EndBegin mandButton cmbNUM Caption = "1"Height = 495Index = 1Left = 1350TabIndex = 10Top = 2520Width = 735EndBegin mandButton cmbNUM Caption = "0"Height = 495Index = 0Left = 1350TabIndex = 9Top = 3060Width = 735EndBegin mandButton cmbMa Caption = "M+"Left = 150TabIndex = 8Top = 3060Width = 975 EndBegin mandButton cmbMS Caption = "MS"Height = 495Left = 150TabIndex = 7Top = 2520Width = 975 EndBegin mandButton cmbMR Caption = "MR"Height = 495Left = 150TabIndex = 6Top = 1980Width = 975 EndBegin mandButton cmbMC Caption = "MC"Height = 495Left = 150TabIndex = 5Top = 1440Width = 975 EndBegin mandButton cmbC Caption = "C"Height = 495Left = 4020Top = 690Width = 1155EndBegin mandButton cmbCECaption = "CE"Height = 495Left = 2670TabIndex = 3Top = 690Width = 1155EndBegin mandButton cmbbackspace Caption = "Backspace"Height = 495Left = 1380TabIndex = 2Top = 690Width = 1155EndBegin VB.TextBox Text1Alignment = 1 'Right Justify Height = 375Left = 210TabIndex = 0Text = "0."Top = 120Width = 4935EndBegin bel Label2Alignment = 2 'CenterHeight = 255Left = 360TabIndex = 29Top = 840Width = 375EndBegin bel Label1Alignment = 2 'CenterBorderStyle = 1 'Fixed SingleBeginProperty FontName = "宋体"Size = 14.25Charset = 134Weight = 400Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'False EndPropertyHeight = 495Left = 240TabIndex = 1Top = 690Width = 615EndBegin VB.Menu editCaption = "编辑(&E)"EndBegin VB.Menu lookCaption = "查看(&V)"EndBegin VB.Menu helpCaption = "帮助(&H)"EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption ExplicitPrivate Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long Dim dotflag As BooleanDim fuhao As StringDim first As DoubleDim second As DoubleDim isEqual As BooleanDim memory As Double '保存显示的数据Dim lianyong As Double '当连续按等号时使用该变量Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long Dim dotflag As BooleanDim fuhao As StringDim first As DoubleDim second As DoubleDim isEqual As BooleanDim memory As Double '保存显示的数据Dim lianyong As Double '当连续按等号时使用该变量Private Sub cmbDesign_Click(Index As Integer)End SubPrivate Sub cmbbackspace_Click()If Right(Trim(Text1.Text), 1) = "." ThenText1.Text = Mid(Text1.Text, 1, Len(Text1.Text) - 2) & "."ElseText1.Text = Mid(Text1.Text, 1, Len(Text1.Text) - 1)End IfIf Right(Text1.Text, 1) = "." Thendotflag = FalseEnd IfIf Len(Text1.Text) = 1 ThenText1.Text = "0."End IfEnd Sub 单击Backspace时删除文本框内最后一个字符Private Sub cmbC_Click()dotflag = FalseText1.Text = "0."first = 0second = 0End Sub 使文本框变成初始状态“0.”Private Sub cmbCE_Click()Text1.Text = "0."End Sub 删除文本框内的所有内容,使文本框变成初始状态“0.”Private Sub cmbDOT_Click()'标示点击了点“。
用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计算器程序代码
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
计算方法VB源代码
计算方法VB源代码以下是一个计算器的VB源代码,用于进行基本的四则运算:```vbImports System.GlobalizationPublic Class CalculatorFormPrivate operand1 As DoublePrivate operand2 As DoublePrivate operation As StringPrivate Sub CalculateButton_Click(sender As Object, e As EventArgs) Handles CalculateButton.ClickIf Double.TryParse(Operand1TextBox.Text, operand1) AndAlso Double.TryParse(Operand2TextBox.Text, operand2) Then Select Case operationCase "+"ResultTextBox.Text = (operand1 +operand2).ToString(CultureInfo.InvariantCulture)Case "-"ResultTextBox.Text = (operand1 -operand2).ToString(CultureInfo.InvariantCulture)Case "*"ResultTextBox.Text = (operand1 *operand2).ToString(CultureInfo.InvariantCulture)Case "/"If operand2 <> 0 ThenResultTextBox.Text = (operand1 /operand2).ToString(CultureInfo.InvariantCulture)ElseMessageBox.Show("Division by zero is not allowed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)End IfCase ElseMessageBox.Show("Invalid operation.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)End SelectElseMessageBox.Show("Invalid operands.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)End IfEnd SubPrivate Sub OperationButton_Click(sender As Object, e As EventArgs) Handles AdditionButton.Click, SubtractionButton.Click, MultiplicationButton.Click, DivisionButton.ClickDim button As Button = CType(sender, Button)operation = button.TextEnd SubEnd Class```这是一个简单的计算器窗体应用程序,由两个文本框(Operand1TextBox 和 Operand2TextBox) 用于输入操作数,一个结果文本框 (ResultTextBox) 用于显示结果,以及四个按钮 (AdditionButton、SubtractionButton、MultiplicationButton 和 DivisionButton) 用于选择四则运算操作。
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编写的计算器代码
Option ExplicitConst CC1 = 1E+28, CC2 = 0.000000000000001, CC3 = 100000000000000# Dim Op1, Op2 ' 预先输入操作数。
Dim DecFlag% ' 小数点存在吗?Dim Klast ' 指示上一次按键事件的类型。
Dim OpFlag ' 指示未完成的操作。
Dim Kedt% ' 指示键入状态,0-未操作,1-算过,2-改过Dim MemNum ' 存储器Dim Temp2'Function sqr28(a As V ariant) As V ariantDim c As Doublec = Sqr(a)If c > CC3 Or c < CC2 Thensqr28 = cElsesqr28 = CDec(Sqr(a))sqr28 = sqr28 - (sqr28 * sqr28 - a) / sqr28 * 0.5End IfEnd FunctionFunction cur28(a As V ariant) As V ariantDim t As V ariant, c As Doublec = Abs(a) ^ (1 / 3)If c > 1000000000# Or c < 0.000000001 Thencur28 = c * Sgn(a)Elsecur28 = CDec(c) * Sgn(a)t = cur28 * cur28cur28 = cur28 - (cur28 * t - a) / t / 3End IfEnd Function' 存入存储器Private Sub BtMS_Click()If Kedt = 2 Then GetOp1MemNum = Op1LabMem.Visible = MemNum <> 0Kedt = 1End Sub' 取出存储器数据Private Sub BtMr_Click()CancelEntry_ClickOp1 = MemNumDisp = Op1Kedt = 1End Sub' 清除存储器Private Sub BtMC_Click()MemNum = CDec(0)LabMem.Visible = FalseEnd SubPrivate Sub BtOff_Click()EndEnd SubPrivate Sub Form_KeyPress(KeyAscii As Integer) Dim K As StringK = Chr(KeyAscii)'Select Case KCase Chr(24): EndCase Chr(8): CancelEntry_ClickCase Chr(27): Cancel_ClickCase "0" To "9": Number_Click KeyAscii - 48 Case ".": Decimal_ClickCase "=": Equal_ClickCase "s": BtMS_ClickCase "c": BtMC_ClickCase "r": BtMr_ClickCase "%": Func_Click 4Case "^": Func_Click 1Case "+": Operator_Click 1Case "-": Operator_Click 3Case "*": Operator_Click 2Case "/": Operator_Click 0Case "i": Func_Click 2Case "'": Func_Click 3Case "]": Func_Click 5Case "\": Func_Click 0Case ";": negcmd_ClickEnd SelectEqual.SetFocusEnd Sub' 窗体的初始化过程' 设置所有变量为其初始值。
计算器的VB代码
Imports System.MathPublic Class Form1Public opera As String'记录所要执行的运算soper operatorPublic rdp As Boolean'记录用户是否已经输入小数点bdot radix pointPublic equ As Boolean'记录用户是否已经单击等号bequ equalmarkPublic benum As Double'被操作数dblaccPublic actnum As Double'操作数dbldesPublic result As Double'记录运算结果Private Sub subreset()opera = ""benum = 0actnum = 0rdp = Falseequ = FalseOutPut.Text = ""Pkey.Focus()End SubPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadDim bt(23) As ButtonDim i As Integerbt(1) = B1bt(2) = B2bt(3) = B3bt(4) = B4bt(5) = B5bt(6) = B6bt(7) = B7bt(8) = B8bt(9) = B9bt(10) = B0bt(11) = Babt(12) = Bjbt(13) = Bqbt(14) = Bmbt(15) = Bdbt(16) = Bebt(17) = BFbt(18) = Bsbt(19) = Bxbt(20) = Bcbt(21) = BackSpacebt(22) = CEbt(23) = CFor i = 1 To 23AddHandler bt(i).Click, New System.EventHandler(AddressOf Me.bt_Click) Nextsubreset()End SubPrivate Sub formmain_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.ActivatedPkey.Focus()End SubPrivate Sub bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim stext As StringDim bclick As Buttonbclick = senderstext = bclick.TextSelect Case stextCase"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"If equ ThenOutPut.Text = ""End Ifequ = FalseOutPut.Text = OutPut.Text + stextCase"."If Not rdp ThenOutPut.Text = OutPut.Text + stextEnd IfCase"+", "-", "*", "/", "%"If Not OutPut.Text.Equals("") Thenbenum = OutPut.TextOutPut.Text = ""opera = stextEnd IfCase"="rdp = FalseIf Not equ And Not OutPut.Text.Equals("") Thenactnum = OutPut.TextEnd Ifequ = TrueSelect Case operaCase"+"result = benum + actnumCase"-"result = benum - actnumCase"*"result = benum * actnumCase"/"If actnum=0 thenMsgBox”除数不能为零,请重新输入”End ifresult = benum / actnumCase"%"If actnum=0 thenMsgBox”求余数不能为零,请重新输入”End ifresult = benum Mod actnumEnd SelectOutPut.Text = resultCase"+/-"If OutPut.Text.Substring(0, 1) = "-"ThenOutPut.Text = OutPut.Text.Substring(1, OutPut.Text.Length - 1) ElseOutPut.Text = "-" + OutPut.TextEnd IfCase"C"subreset()Case"CE"OutPut.Text = ""Case"BackSpace"If OutPut.Text <> ""ThenIf OutPut.Text.Substring(OutPut.Text.Length - 1) = "."Thenrdp = FalseEnd IfOutPut.Text = OutPut.Text.Substring(0, OutPut.Text.Length - 1)End IfCase"Sqr"Dim m As Integer = OutPut.TextIf m >= 0 ThenOutPut.Text = Sqrt(m).ToStringEnd IfCase"1/X"Dim m As Integer = OutPut.TextIf m <> 0 ThenOutPut.Text = (1 / m).ToStringEnd IfEnd SelectEnd SubPrivate Sub Pkey_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pkey.ClickEnd SubEnd Class。
计算器VB代码
Public p As String Public f As DoublePublic s As DoubleDim XDim aDim bDim cDim dPrivate Sub cmdAbs_Click()If txtScreen.Text = "" ThenMsgBox "无数字,无法计算"ElseIf txtScreen.Text <> 0 Thenf = txtScreen.Texts = fs = Abs(s)txtScreen.Text = stxtScreen2.Text = sEnd IfEnd SubPrivate Sub cmdAtn_Click()If txtScreen.Text = "" Then MsgBox "无数字,无法计算"ElseIf txtScreen.Text <> "" Then f = txtScreen.Texts = fs = Atn(s)txtScreen.Text = stxtScreen2.Text = sEnd IfEnd SubPrivate Sub cmdClean_Click() txtScreen = ""f = 0s = 0End SubPrivate Sub cmdClear_Click() txtScreen.Text = ""f = 0s = 0txtScreen2.Text = ""txtGH.Text = ""cmdSpr.Enabled = True cmdXmY.Enabled = True cmdCos.Enabled = True cmdSin.Enabled = True cmdMi.Enabled = True cmdAbs.Enabled = True cmdds.Enabled = True cmdAtn.Enabled = True cmdeN.Enabled = True cmdLog.Enabled = TruecmdTan.Enabled = Truecmdspr2.Enabled = TruecmdGHH.Enabled = TrueEnd SubPrivate Sub cmdCos_Click()If txtScreen.Text = "" ThenMsgBox "无数字,无法计算"ElseIf txtScreen.Text <> "" Thenf = txtScreen.Texts = fs = Cos(s)txtScreen.Text = stxtScreen2.Text = sEnd IfEnd SubPrivate Sub cmdDigit_Click(Index As Integer)txtScreen.Text = txtScreen.Text & cmdDigit(Index).Captions = txtScreen.TextEnd SubPrivate Sub cmdDivide_Click(Index As Integer) If p = "" ThentxtScreen.Text = ""p = "/"f = ss = 0End IfEnd SubPrivate Sub cmdds_Click()If txtScreen.Text = "" ThenMsgBox "无数字,无法计算"ElseIf txtScreen.Text <> 0 Thenf = txtScreen.Texts = fs = 1 / ftxtScreen.Text = stxtScreen2.Text = sElseMsgBox "分子不能为零。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
计算器vb源代码.txt性格本身没有好坏,乐观和悲观对这个世界都有贡献,前者发明了飞机,后者发明了降落伞。
完全版的前后台代码...'请把下面的保存为form1.frmVERSION 5.00Begin VB.Form CalculatorBorderStyle = 1 'Fixed SingleCaption = "计算器"ClientHeight = 2970ClientLeft = 2580ClientTop = 1485ClientWidth = 3270ClipControls = 0 'FalseBeginProperty FontName = "System"Size = 9.75Charset = 0Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'FalseEndPropertyIcon = "CALC.frx":0000LinkMode = 1 'SourceLinkTopic = "Form1"MaxButton = 0 'FalsePaletteMode = 1 'UseZOrderScaleHeight = 2970ScaleWidth = 3270WhatsThisHelp = -1 'TrueBegin mandButton NumberCaption = "7"Height = 480Index = 7Left = 120TabIndex = 7Top = 600Width = 480EndBegin mandButton NumberCaption = "8"Height = 480Index = 8Left = 720TabIndex = 8Top = 600Width = 480 EndBegin mandButton NumberCaption = "9"Height = 480Index = 9Left = 1320TabIndex = 9Top = 600Width = 480 EndBegin mandButton CancelCaption = "C"Height = 480Left = 2040TabIndex = 10Top = 600Width = 480 EndBegin mandButton CancelEntryCaption = "CE"Height = 480Left = 2640TabIndex = 11Top = 600Width = 480 EndBegin mandButton NumberCaption = "4"Height = 480Index = 4Left = 120TabIndex = 4Top = 1200Width = 480 EndBegin mandButton NumberCaption = "5"Height = 480Index = 5Left = 720TabIndex = 5Top = 1200Width = 480EndBegin mandButton NumberCaption = "6"Height = 480Index = 6Left = 1320TabIndex = 6Top = 1200Width = 480 EndBegin mandButton OperatorCaption = "+"Height = 480Index = 1Left = 2040TabIndex = 12Top = 1200Width = 480 EndBegin mandButton OperatorCaption = "-"Height = 480Index = 3Left = 2640TabIndex = 13Top = 1200Width = 480 EndBegin mandButton NumberCaption = "1"Height = 480Index = 1Left = 120TabIndex = 1Top = 1800Width = 480 EndBegin mandButton NumberCaption = "2"Height = 480Index = 2Left = 720TabIndex = 2Top = 1800Width = 480 EndBegin mandButton NumberCaption = "3"Height = 480Index = 3Left = 1320TabIndex = 3Top = 1800Width = 480 EndBegin mandButton OperatorCaption = "X"Height = 480Index = 2Left = 2040TabIndex = 14Top = 1800Width = 480 EndBegin mandButton OperatorCaption = "/"Height = 480Index = 0Left = 2640TabIndex = 15Top = 1800Width = 480 EndBegin mandButton NumberCaption = "0"Height = 480Index = 0Left = 120TabIndex = 0Top = 2400Width = 1080 EndBegin mandButton DecimalCaption = "."Height = 480Left = 1320TabIndex = 18Top = 2400Width = 480 EndBegin mandButton OperatorCaption = "="Height = 480Index = 4Left = 2040TabIndex = 16Top = 2400Width = 480EndBegin mandButton PercentCaption = "%"Height = 480Left = 2640TabIndex = 17Top = 2400Width = 480EndBegin bel ReadoutAlignment = 1 'Right JustifyBackColor = &H0000FFFF&BorderStyle = 1 'Fixed SingleCaption = "0."BeginProperty FontName = "MS Sans Serif"Size = 12Charset = 0Weight = 700Underline = 0 'FalseItalic = 0 'FalseStrikethrough = 0 'FalseEndPropertyForeColor = &H00000000&Height = 375Left = 120TabIndex = 19Top = 105Width = 3000EndEndAttribute VB_Name = "Calculator"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = False' --------------------------------------------------------------------------' 版权所有(C) 1994 Microsoft Corporation'' 您可以免费以任何方式使用、修改、复制并分发您认为有用的' 示例应用程序文件(或任何修改过的版本)。
Microsoft 对任何' 示例应用程序文件不做任何保证,不负任何责任和义务。
' --------------------------------------------------------------------------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。