Selasa, 27 September 2011

latihan bikin kalkulator di VB


LANGKAH – LANGKAH MEMBUAT
PROGRAM KALKULATOR
Dim st, st2 As String

Private Sub Text1_Click()
st = "T"
st2 = "f"
End Sub

Private Sub Text2_Click()
st = "f"
st2 = "T"
End Sub

1.   Private Sub Command1_Click()
If st = "T" Then
Text1.Text = 1
Else
If st2 = "T" Then
Text2.Text = 1
End If
End If
End Sub

2.   Private Sub Command2_Click()
If st = "T" Then
Text1.Text = 2
Else
If st2 = "T" Then
Text2.Text = 2
End If
End If
End Sub

3.   Private Sub Command3_Click()
If st = "T" Then
Text1.Text = 3
Else
If st2 = "T" Then
Text2.Text = 3
End If
End If
End Sub

4.   Private Sub Command4_Click()
If st = "T" Then
Text1.Text = 4
Else
If st2 = "T" Then
Text2.Text = 4
End If
End If
End Sub

5.   Private Sub Command5_Click()
If st = "T" Then
Text1.Text = 5
Else
If st2 = "T" Then
Text2.Text = 5
End If
End If
End Sub

6.   Private Sub Command6_Click()
If st = "T" Then
Text1.Text = 6
Else
If st2 = "T" Then
Text2.Text = 6
End If
End If
End Sub

7.   Private Sub Command7_Click()
If st = "T" Then
Text1.Text = 7
Else
If st2 = "T" Then
Text2.Text = 7
End If
End If
End Sub

8.   Private Sub Command8_Click()
If st = "T" Then
Text1.Text = 8
Else
If st2 = "T" Then
Text2.Text = 8
End If
End If
End Sub

9.   Private Sub Command9_Click()
If st = "T" Then
Text1.Text = 9
Else
If st2 = "T" Then
Text2.Text = 9
End If
End If
End Sub

10. Private Sub Command10_Click()
If st = "T" Then
Text1.Text = 0
Else
If st2 = "T" Then
Text2.Text = 0
End If
End If
End Sub

11. Private Sub Command11_Click()
Label1.Caption = "+"

End Sub

12. Private Sub Command12_Click()
Label1.Caption = "-"

End Sub

13. Private Sub Command13_Click()
Label1.Caption = "x"

End Sub

14. Private Sub Command14_Click()
Label1.Caption = "/"

End Sub

15. Private Sub Command15_Click()
If Label1.Caption = "+" Then
    Text3.Text = Val(Text1.Text) + Val(Text2.Text)
Else
   If Label1.Caption = "-" Then
      Text3.Text = Val(Text1.Text) - Val(Text2.Text)
Else
   If Label1.Caption = "x" Then
       Text3.Text = Val(Text1.Text) * Val(Text2.Text)
Else
  Text3.Text = Val(Text1.Text) / Val(Text2.Text)

End If

End If


End If

End Sub