Kamis, 23 September 2010

Code Calculator Visual Basic

Dim op As String
Option Explicit

Dim i As Integer
Dim exp1 As Double
Dim exp2 As Double
Dim Result As Double
Dim count1 As Integer
Dim scitype As String
Private X As Double
Dim mem As Variant

Private Sub command1_Click(Index As Integer)
If count1 = 0 Then
Text1.Text = " "
MsgBox ("Calculator is not on please press the on button")

End If

If count1 = 1 Then
Text1.Text = " "
count1 = count1 + 1
End If

If count1 > 1 Then
Text1.Text = Text1.Text & command1(Index).Caption
End If
End Sub

Private Sub Command2_Click()
Text1.Text = -Val(Text1.Text)
End Sub

Private Sub Command3_Click()
If count1 > 0 Then
exp2 = Val(Text1.Text)
Select Case (op)
Case "+"
Result = exp1 + exp2
Text1.Text = Result
count1 = 0
Case "-"
Result = exp1 - exp2
Text1.Text = Result
count1 = 0
Case "*"
Result = exp1 * exp2
Text1.Text = Result
count1 = 0
Case "/"
Result = exp1 / exp2
Text1.Text = Result
count1 = 0
Case "%"
Result = (exp1 / 100) * exp2
Text1.Text = Result
count1 = 0
End Select
End If
End Sub

Private Sub Command4_Click(Index As Integer)
Result = exp1
exp1 = Result + Val(Text1.Text)
Text1.Text = " "
op = Command4(Index).Caption
End Sub

Private Sub Command5_Click()
Result = 0
exp1 = 0
exp2 = 0
Text1.Text = " "
count1 = 1

End Sub

Private Sub Command6_Click()
count1 = 0
Text1.Text = ""
End Sub

Private Sub Command7_Click()
Result = 0
exp1 = 0
exp2 = 0
count1 = 1
Text1.Text = "0"
End Sub

Private Sub Command8_Click(Index As Integer)
scitype = Command8(Index).Caption
Select Case (scitype)
Case "sin"
Text1.Text = (Text1.Text * 3.14) / 180
Text1.Text = Math.Sin(Val(Text1.Text))
count1 = 0
Case "cos"
Text1.Text = (Text1.Text * 3.14) / 180
Text1.Text = Math.Cos(Val(Text1.Text))
count1 = 0
Case "tan"
Text1.Text = (Text1.Text * 3.14) / 180
Text1.Text = Math.Tan(Val(Text1.Text))
count1 = 0
Case "log"
Text1.Text = Math.Log(Val(Text1.Text))
count1 = 0
End Select
End Sub

0 komentar:

Halaman