Vb simple calculator source code

Source: Internet
Author: User

The Code is as follows: Copy codeThe Code is as follows :/**
* Author: wuniao heart
* Version: 1.0
*/
Dim IntX As Double global variable, used to store the calculated value
Dim operation peration As double' mark Operation Type
Dim isBegin As Boolean 'indicates whether IntX has been assigned a value.
Public Sub Clear () 'clear command function

Screen. Caption = ""
End Sub
Public Sub SavaToIntX ()

Select Case when peration

Case 1 'addition
If isBegin = False Then
IntX = Val (screen. Caption)
IsBegin = True
Else
IntX = IntX + Val (screen. Caption)
End If

Case 2 'subtraction
If isBegin = False Then
IntX = Val (screen. Caption)
IsBegin = True
Else
IntX = IntX-Val (screen. Caption)
End If

Case 3 'multiplication
If isBegin = False Then
IntX = Val (screen. Caption)
IsBegin = True
Else
IntX = IntX * Val (screen. Caption)
'Screen. Caption = IntX
End If

Case 4 'division
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 commandementclick ()
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 () 'clear command
IsBegin = False
Operation peration = 0
IntX = 0
Screen. Caption = ""
End Sub

Private Sub CommandEqual_Click () 'equal sign operation

If operation peration <> 0 then' has operation mark
Call SavaToIntX
Operation peration = 0
IsBegin = False
Screen. Caption = IntX
End If

End Sub

Private Sub CommandMinus_Click () 'subtraction

If operation peration <> 0 then' has operation mark
Call SavaToIntX
Operation peration = 2
Call Clear

Else
Operation peration = 2
Call SavaToIntX
Call Clear

End If
End Sub

Private Sub CommandMultiple_Click () 'multiplication
If operation peration <> 0 then' has operation mark
Call SavaToIntX
Operation peration = 3
Call Clear

Else
Operation peration = 3
Call SavaToIntX
Call Clear

End If

End Sub

Private Sub CommandPlus_Click () 'addition operation

If operation peration <> 0 then' has operation mark
Call SavaToIntX
Operation peration = 1
Call Clear

Else
Operation peration = 1
Call SavaToIntX
Call Clear

End If

End Sub

Private Sub CommandSlash_Click () 'division operation

If operation peration <> 0 then' has operation mark
Call SavaToIntX
Operation peration = 4
Call Clear

Else
Operation peration = 4
Call SavaToIntX
Call Clear

End If
End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.