vb簡易計算器源碼
更新時間:2012年09月29日 22:34:56 作者:
本人一覺醒來閑得無聊,正在學習VB,便用VB寫個簡易的計算器吧!鞏固基礎(chǔ)
代碼如下:
/**
*Author:烏鳥heart
*Version:1.0
*/
Dim IntX As Double '全局變量,用于存儲計算的數(shù)值
Dim IntOperation As Double '標記運算類型
Dim isBegin As Boolean '標記是否已經(jīng)給IntX賦值
Public Sub Clear() '清空命令函數(shù)
screen.Caption = ""
End Sub
Public Sub SavaToIntX()
Select Case IntOperation
Case 1 '加法
If isBegin = False Then
IntX = Val(screen.Caption)
isBegin = True
Else
IntX = IntX + Val(screen.Caption)
End If
Case 2 '減法
If isBegin = False Then
IntX = Val(screen.Caption)
isBegin = True
Else
IntX = IntX - Val(screen.Caption)
End If
Case 3 '乘法
If isBegin = False Then
IntX = Val(screen.Caption)
isBegin = True
Else
IntX = IntX * Val(screen.Caption)
'screen.Caption = IntX
End If
Case 4 '除法
If isBegin = False Then
IntX = Val(screen.Caption)
isBegin = True
Else
IntX = IntX / Val(screen.Caption)
End If
End Select
End Sub
Private Sub Command0_Click()
screen.Caption = screen.Caption & 0
End Sub
Private Sub Command1_Click()
screen.Caption = screen.Caption & 1
End Sub
Private Sub Command2_Click()
screen.Caption = screen.Caption & 2
End Sub
Private Sub Command3_Click()
screen.Caption = screen.Caption & 3
End Sub
Private Sub Command4_Click()
screen.Caption = screen.Caption & 4
End Sub
Private Sub Command5_Click()
screen.Caption = screen.Caption & 5
End Sub
Private Sub Command6_Click()
screen.Caption = screen.Caption & 6
End Sub
Private Sub Command7_Click()
screen.Caption = screen.Caption & 7
End Sub
Private Sub Command8_Click()
screen.Caption = screen.Caption & 8
End Sub
Private Sub Command9_Click()
screen.Caption = screen.Caption & 9
End Sub
Private Sub CommandClear_Click() '清空命令
isBegin = False
IntOperation = 0
IntX = 0
screen.Caption = ""
End Sub
Private Sub CommandEqual_Click() '等號運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 0
isBegin = False
screen.Caption = IntX
End If
End Sub
Private Sub CommandMinus_Click() '減法運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 2
Call Clear
Else
IntOperation = 2
Call SavaToIntX
Call Clear
End If
End Sub
Private Sub CommandMultiple_Click() '乘法運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 3
Call Clear
Else
IntOperation = 3
Call SavaToIntX
Call Clear
End If
End Sub
Private Sub CommandPlus_Click() '加法運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 1
Call Clear
Else
IntOperation = 1
Call SavaToIntX
Call Clear
End If
End Sub
Private Sub CommandSlash_Click() '除法運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 4
Call Clear
Else
IntOperation = 4
Call SavaToIntX
Call Clear
End If
End Sub
復制代碼 代碼如下:
/**
*Author:烏鳥heart
*Version:1.0
*/
Dim IntX As Double '全局變量,用于存儲計算的數(shù)值
Dim IntOperation As Double '標記運算類型
Dim isBegin As Boolean '標記是否已經(jīng)給IntX賦值
Public Sub Clear() '清空命令函數(shù)
screen.Caption = ""
End Sub
Public Sub SavaToIntX()
Select Case IntOperation
Case 1 '加法
If isBegin = False Then
IntX = Val(screen.Caption)
isBegin = True
Else
IntX = IntX + Val(screen.Caption)
End If
Case 2 '減法
If isBegin = False Then
IntX = Val(screen.Caption)
isBegin = True
Else
IntX = IntX - Val(screen.Caption)
End If
Case 3 '乘法
If isBegin = False Then
IntX = Val(screen.Caption)
isBegin = True
Else
IntX = IntX * Val(screen.Caption)
'screen.Caption = IntX
End If
Case 4 '除法
If isBegin = False Then
IntX = Val(screen.Caption)
isBegin = True
Else
IntX = IntX / Val(screen.Caption)
End If
End Select
End Sub
Private Sub Command0_Click()
screen.Caption = screen.Caption & 0
End Sub
Private Sub Command1_Click()
screen.Caption = screen.Caption & 1
End Sub
Private Sub Command2_Click()
screen.Caption = screen.Caption & 2
End Sub
Private Sub Command3_Click()
screen.Caption = screen.Caption & 3
End Sub
Private Sub Command4_Click()
screen.Caption = screen.Caption & 4
End Sub
Private Sub Command5_Click()
screen.Caption = screen.Caption & 5
End Sub
Private Sub Command6_Click()
screen.Caption = screen.Caption & 6
End Sub
Private Sub Command7_Click()
screen.Caption = screen.Caption & 7
End Sub
Private Sub Command8_Click()
screen.Caption = screen.Caption & 8
End Sub
Private Sub Command9_Click()
screen.Caption = screen.Caption & 9
End Sub
Private Sub CommandClear_Click() '清空命令
isBegin = False
IntOperation = 0
IntX = 0
screen.Caption = ""
End Sub
Private Sub CommandEqual_Click() '等號運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 0
isBegin = False
screen.Caption = IntX
End If
End Sub
Private Sub CommandMinus_Click() '減法運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 2
Call Clear
Else
IntOperation = 2
Call SavaToIntX
Call Clear
End If
End Sub
Private Sub CommandMultiple_Click() '乘法運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 3
Call Clear
Else
IntOperation = 3
Call SavaToIntX
Call Clear
End If
End Sub
Private Sub CommandPlus_Click() '加法運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 1
Call Clear
Else
IntOperation = 1
Call SavaToIntX
Call Clear
End If
End Sub
Private Sub CommandSlash_Click() '除法運算
If IntOperation <> 0 Then '有運算標記的情況
Call SavaToIntX
IntOperation = 4
Call Clear
Else
IntOperation = 4
Call SavaToIntX
Call Clear
End If
End Sub
相關(guān)文章
VB實現(xiàn)屏蔽文本框右鍵菜單的復制、粘貼等功能的方法
這篇文章主要介紹了VB實現(xiàn)屏蔽文本框右鍵菜單的復制、粘貼等功能,是非常實用的一個功能,需要的朋友可以參考下2014-07-07在VB中遍歷文件并用正則表達式完成復制及vb實現(xiàn)重命名、拷貝文件夾的方法
這篇文章主要介紹了在VB中遍歷文件并用正則表達式完成復制及vb實現(xiàn)重命名、拷貝文件夾的方法,需要的朋友可以參考下2018-12-12