《VB计算器源代码》由会员分享,可在线阅读,更多相关《VB计算器源代码(3页珍藏版)》请在金锄头文库上搜索。
1、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 = Left(Text1
2、.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 Su
3、b 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 = D
4、ata * 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 +
5、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
6、()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