Use the below coding to create a calculator program using VB (Visual Basic) Software.
Public Curval As Double
Public Preval As Double
Public choice As String
Public result As Double
Private Sub cmd_Click(Index As Integer)
Text1.Text = Text1.Text &
cmd(Index).Caption
Curval = Val(Text1.Text)
End Sub
Private Sub Command10_Click()
Text1.Text = " "
Preval = Curval
Curval = 0
choice = "-"
End Sub
Private Sub Command14_Click()
Select Case choice
Case "+"
result = Preval + Curval
Text1.Text = Str(result)
Case "-"
result = Preval - Curval
Text1.Text = Str(result)
Case "/"
result = Preval / Curval
Text1.Text = Str(result)
Case "*"
result = Preval * Curval
Text1.Text = Str(result)
End Select
Curval = result
End Sub
Private Sub Command15_Click()
Text1.Text = " "
Preval = Curval
Curval = 0
choice = "/"
End Sub
Private Sub Command16_Click()
Text1.Text = " "
Preval = Curval
Curval = 0
choice = "*"
End Sub
Private Sub Command17_Click()
Curval = -Curval
Text1.Text = Str(Curval)
End Sub
Private Sub Command18_Click()
Curval = Preval = 0
Text1.Text = " "
End Sub
Private Sub Command5_Click()
Text1.Text = " "
Preval = Curval
Curval = 0
choice = "+"
End Sub
0 comments:
Post a Comment