Simple Visual Basic Calculator

Embed Size (px)

Citation preview

  • 7/31/2019 Simple Visual Basic Calculator

    1/9

    CODDING OF CALCULATORIN VISUAL BASIC

    STRUCTUAL ENGINEERING LAB

    Submited To:Dr Aun Bashir

    Submited By:

    Afzal Waseem2007-Civil-87

    Section B

    1

    University of Engineering and Technology Lahore Civil Engineering Department

  • 7/31/2019 Simple Visual Basic Calculator

    2/9

  • 7/31/2019 Simple Visual Basic Calculator

    3/9

    Private Sub Command1_Click()Text1.Text = Text1.Text + "1"End Sub

    Private Sub Command10_Click()Text1.Text = Text1.Text + "0"End Sub

    Private Sub Command11_Click()If Not IsNumeric(Text1.Text) Then

    MsgBox "Please enter numbers.", vbInformation'you may also consider erasing itText1.Text = ""

    End Ifa = Val(Text1.Text)

    Text1.Text = ""End Sub

    Private Sub Command12_Click()If Not IsNumeric(Text1.Text) Then

    MsgBox "Please enter numbers.", vbInformation'you may also consider erasing itText1.Text = ""

    End Ifa = Val(Text1.Text)Text1.Text = ""End Sub

    Private Sub Command13_Click()If Not IsNumeric(Text1.Text) Then

    MsgBox "Please enter numbers.", vbInformation'you may also consider erasing itText1.Text = ""

    End Ifa = Val(Text1.Text)Text1.Text = ""End Sub

    Private Sub Command14_Click()If Not IsNumeric(Text1.Text) Then

    MsgBox "Please enter numbers.", vbInformation'you may also consider erasing itText1.Text = ""

    End Ifa = Val(Text1.Text)

    3

    University of Engineering and Technology Lahore Civil Engineering Department

  • 7/31/2019 Simple Visual Basic Calculator

    4/9

    Text1.Text = ""End Sub

    Private Sub Command15_Click()If Command11.Value = True Then

    b = Val(Text1.Text)c = a + bText3.Text = cElseIf Command12.Value = True Thenb = Val(Text1.Text)c = a - bText1.Text = cElseIf Command13.Value = True Thenb = Val(Text1.Text)

    c = a * bText1.Text = cElseIf Command14.Value = True Thenb = Val(Text1.Text)c = a / bText1.Text = cEnd IfEnd IfEnd IfEnd IfEnd Sub

    Private Sub Command16_Click()Text1.Text = ""End Sub

    Private Sub Command2_Click()Text1.Text = Text1.Text + "2"End Sub

    Private Sub Command3_Click()Text1.Text = Text1.Text + "3"End Sub

    Private Sub Command4_Click()Text1.Text = Text1.Text + "4"End Sub

    Private Sub Command5_Click()

    4

    University of Engineering and Technology Lahore Civil Engineering Department

  • 7/31/2019 Simple Visual Basic Calculator

    5/9

    Text1.Text = Text1.Text + "5"End Sub

    Private Sub Command6_Click()Text1.Text = Text1.Text + "6"

    End Sub

    Private Sub Command7_Click()Text1.Text = Text1.Text + "7"End Sub

    Private Sub Command8_Click()Text1.Text = Text1.Text + "8"End Sub

    Private Sub Command9_Click()

    Text1.Text = Text1.Text + "9"End Sub

    Private Sub Form_Load()Dim a As SingleDim b As SingleDim c As SingleEnd Sub

    5

    University of Engineering and Technology Lahore Civil Engineering Department

  • 7/31/2019 Simple Visual Basic Calculator

    6/9

  • 7/31/2019 Simple Visual Basic Calculator

    7/9

    Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)c = a + bText3.Text = c

    If Not IsNumeric(Text1.Text) ThenMsgBox "Please enter number in x.", vbInformation'you may also consider erasing itText1.Text = ""

    End IfIf Not IsNumeric(Text2.Text) Then

    MsgBox "Please enter number in y.", vbInformation'you may also consider erasing itText2.Text = ""

    End IfEnd Sub

    Private Sub Command2_Click()a = Val(Text1.Text)b = Val(Text2.Text)c = a - bText3.Text = cIf Not IsNumeric(Text1.Text) Then

    MsgBox "Please enter number in x", vbInformation'you may also consider erasing itText1.Text = ""

    End IfIf Not IsNumeric(Text2.Text) Then

    MsgBox "Please enter number in y", vbInformation'you may also consider erasing itText2.Text = ""

    End IfEnd Sub

    Private Sub Command3_Click()a = Val(Text1.Text)b = Val(Text2.Text)c = a * bText3.Text = cIf Not IsNumeric(Text1.Text) Then

    MsgBox "Please enter number in x", vbInformation

    7

    University of Engineering and Technology Lahore Civil Engineering Department

  • 7/31/2019 Simple Visual Basic Calculator

    8/9

    'you may also consider erasing itText1.Text = ""

    End IfIf Not IsNumeric(Text2.Text) Then

    MsgBox "Please enter numbers only.", vbInformation'you may also consider erasing itText2.Text = ""

    End IfEnd Sub

    Private Sub Command4_Click()If Not IsNumeric(Text1.Text) Then

    MsgBox "Please enter numbers only.", vbInformation'you may also consider erasing itText1.Text = ""

    End If

    If Not IsNumeric(Text2.Text) ThenMsgBox "Please enter numbers only.", vbInformation'you may also consider erasing itText2.Text = ""

    GoTo 10End If

    a = Val(Text1.Text)b = Val(Text2.Text)c = a / bText3.Text = c10 'End Sub

    Private Sub Command5_Click()a = Val(Text1.Text)b = Val(Text4.Text)c = Val(Text5.Text)If Not IsNumeric(Text1.Text) Then

    MsgBox "Please enter the number in X to find power of.", vbInformation'you may also consider erasing it

    Text1.Text = ""GoTo 10End Ifd = a ^ (b / c)Text3.Text = d

    8

    University of Engineering and Technology Lahore Civil Engineering Department

  • 7/31/2019 Simple Visual Basic Calculator

    9/9

    10 'End Sub

    Private Sub Command6_Click()Text1.Text = ""

    Text2.Text = ""Text3.Text = ""End Sub

    Private Sub Command7_Click()a = Val(Text1.Text)b = Val(Text4.Text)b = Cos(a)Text3.Text = bEnd Sub

    9

    University of Engineering and Technology Lahore Civil Engineering Department