Tnou Study Center

Blog Owner: Vignesh A





Search This Blog

Tuesday, January 9, 2018

Visual Basic Calculator Programe



Ex.No:
Date:
CALCULATOR USING CONTROL ARRAY

Aim:
To write a program to create calculator using control array

Procedure:

1.     Open new standard form in visual basic for inserting controls.
           
            2. Place textbox and command button           
           
            3. Write the code in button for performs the operations.

            4. Run the application.


Form Design Specification Table:

Object
Property
Settings
Form1
Name
Calculator
Command
Caption
^
Name
Cmdpower
Command
Caption
sqr
Name
Cmdsqr
Command
Caption
ac
Name
Cmdac
Command
Caption
off
Name
Cmdoff
Command
Caption
sin
Name
Cmdsin
Command
Caption
cos
Name
Cmdcos
Command
Caption
tan
Name
Cmdtan
Command
Caption
exp
Name
Cmdexp
Command1
Caption
0 to 9
Name
Command1
Command
Caption
+
Name
Cmdplus
Command
Caption
-
Name
Cmdminus
Command
Caption
*
Name
Cmdmul
Command
Caption
/
Name
Cmddiv
Command
Caption
.
Name
Cmddot
Command
Caption
=
Name
Cmd





















Source Code:

Option Explicit
Dim cval, pval As Double
Dim result As Double
Dim choice As String

Private Sub cmdac_Click(Index As Integer)
 Text1.Text = " "
End Sub

Private Sub cmdequal_Click(Index As Integer)
Select Case choice
Case "+":
    result = pval + cval
    Text1.Text = result
Case "-":
    result = pval - cval
    Text1.Text = result
Case "*":
    result = pval * cval
    Text1.Text = result
Case "/":
    result = pval / cval
    Text1.Text = result
Case "^":
    result = pval ^ cval
    Text1.Text = result
End Select
End Sub

Private Sub cmdoff_Click(Index As Integer)
 End
End Sub



Private Sub cmdpower_Click(Index As Integer)
 Text1.Text = " "
 pval = cval
 choice = "^"
 End Sub

Private Sub cmdcos_click(Index As Integer)
 Text1.Text = Cos(Val(Text1.Text))
End Sub

Private Sub cmdsin_Click(Index As Integer)
 Text1.Text = Sin(Val(Text1.Text))
End Sub

Private Sub cmdsqr_Click(Index As Integer)
 Text1.Text = Val(Text1.Text) * Val(Text1.Text)
End Sub


Private Sub cmdexp_click(Index As Integer)
 Text1.Text = Exp(Val(Text1.Text))
End Sub

Private Sub cmdtan_Click(Index As Integer)
 Text1.Text = Tan(Val(Text1.Text))
End Sub

Private Sub command1_click(Index As Integer)
 Text1.Text = Text1.Text & command1(Index).Caption
 cval = Text1.Text
End Sub

Private Sub cmddot_click(Index As Integer)
Text1.Text = Text1.Text & cmddot(Index).Caption
End Sub



Private Sub cmdplus_click(Index As Integer)
 Text1.Text = " "
 pval = cval
 choice = "+"
End Sub

Private Sub cmdmins_click(Index As Integer)
 Text1.Text = " "
 pval = cval
 choice = "-"
End Sub

Private Sub cmdmul_click(Index As Integer)
 Text1.Text = " "
 pval = cval
 choice = "*"
End Sub

Private Sub cmddiv_click(Index As Integer)
 Text1.Text = " "
 pval = cval
 choice = "/"
End Sub













Form Design:





















Output: