VB Simple Calculator Source code _VB

Source: Internet
Author: User
The code is as follows:
Copy Code code as follows:

/**
*author: Black Bird Heart
*version:1.0
*/
Dim IntX as Double global variable, for storing calculated values
Dim intoperation as Double ' tag operation type
Dim Isbegin as Boolean ' tag has been assigned to Intx
Public Sub Clear () Empty command function

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

Select Case Intoperation

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 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 () ' Empty command '
Isbegin = False
intoperation = 0
IntX = 0
Screen. Caption = ""
End Sub

Private Sub Commandequal_click () ' equal sign operation

If intoperation <> 0 Then ' There is an operational mark of the case
Call Savatointx
intoperation = 0
Isbegin = False
Screen. Caption = IntX
End If

End Sub

Private Sub Commandminus_click () ' subtraction operation

If intoperation <> 0 Then ' There is an operational mark of the case
Call Savatointx
Intoperation = 2
Call Clear

Else
Intoperation = 2
Call Savatointx
Call Clear

End If
End Sub

Private Sub Commandmultiple_click () ' multiplication operations
If intoperation <> 0 Then ' There is an operational mark of the case
Call Savatointx
Intoperation = 3
Call Clear

Else
Intoperation = 3
Call Savatointx
Call Clear

End If

End Sub

Private Sub Commandplus_click () ' addition operation

If intoperation <> 0 Then ' There is an operational mark of the case
Call Savatointx
Intoperation = 1
Call Clear

Else
Intoperation = 1
Call Savatointx
Call Clear

End If

End Sub

Private Sub Commandslash_click () ' Division operation

If intoperation <> 0 Then ' There is an operational mark of the case
Call Savatointx
Intoperation = 4
Call Clear

Else
Intoperation = 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.