yaitu membuat kalkulator di Microsoft Visual Basic 6
1) Buka Visual Basic mu ~> Buat 1 buah Textbox dan 10 buah Command Button
2) Kemudian, ubah CAPTION semuanya menjadi seperti gambar .. INGAT ! CAPTION ! BUKAN NAME !
P.s : cara merubahnya ada di box Sebelah kanan .. untuk TEXT 1 .. Kosongkan CAPTIONNYA
3) Buat lagi 10 Command Button dan letakkan seperti gambar dibawah
4) Atur Properties menjadi :
Kontrol
|
Properti
| |
Text1
|
Text
| |
Command2
|
Name
Caption
|
Koma
.
|
Command3
|
Name
Caption
|
AC
AC
|
Command4
|
Name
Caption
|
Tambah
+
|
Command5
|
Name
Caption
|
Kurang
-
|
Command6
|
Name
Caption
|
Tanda
+/-
|
Command7
|
Name
Caption
|
Bagi
/
|
Command8
|
Name
Caption
|
Kali
x
|
Command9
|
Name
Caption
|
Akar
Akar
|
Command10
|
Name
Caption
|
Hasil
=l
|
Command11
|
Name
Caption
|
Kuadrat
X^2
|
5) Setelah selesai EDIT, Kurang lebih hasilnya seperti ini :
6) Di Bagian yg kosong (yg ada titik" ) klik kanan ~> View Code ~> Pastekan kode dibawah
Private pilihan As String
Private x As Double
Private y As Double
Private Sub AC_Click()
Text1.Text = ""
y = x = 0
Tanda.Enabled = False
End Sub
Private Sub Akar_Click()
If x < 0 Then
Text1.Text = "Angka Tidak Boleh Negatif Coy"
Else
Text1.Text = Sqr(x)
End If
End Sub
Private Sub Bagi_Click()
Text1.Text = ""
pilihan = "bagi"
y = x
x = 0
Tanda.Enabled = False
End Sub
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
x = Text1.Text
Tanda.Enabled = True
End Sub
Private Sub Form_Load()
Tanda.Enabled = False
End Sub
Private Sub Hasil_Click()
If pilihan = "tambah" Then
x = y + x
Text1.Text = x
ElseIf pilihan = "kurang" Then
x = y - x
Text1.Text = x
ElseIf pilihan = "kali" Then
x = y * x
Text1.Text = x
ElseIf pilihan = "bagi" And x <> 0 Then
x = y / x
Text1.Text = x
Else
Text1.Text = "Tidak Terdefinisi"
End If
End Sub
Private Sub Kali_Click()
Text1.Text = ""
pilihan = "kali"
y = x
x = 0
Tanda.Enabled = False
End Sub
Private Sub Koma_Click()
If Text1.Text = "" Then
Text1.Text = "0."
Else
Text1.Text = Text1.Text & "."
End If
End Sub
Private Sub Kuadrat_Click()
Text1.Text = x ^ 2
End Sub
Private Sub Kurang_Click()
Text1.Text = ""
pilihan = "kurang"
y = x
x = 0
Tanda.Enabled = False
End Sub
Private Sub Tambah_Click()
Text1.Text = ""
pilihan = "tambah"
y = x
x = 0
Tanda.Enabled = False
End Sub
Private Sub Tanda_Click()
If x < 0 Then
Text1.Text = -x
x = -x
Else
Text1.Text = "-" & Text1.Text
x = -x
End If
End Sub
Private x As Double
Private y As Double
Private Sub AC_Click()
Text1.Text = ""
y = x = 0
Tanda.Enabled = False
End Sub
Private Sub Akar_Click()
If x < 0 Then
Text1.Text = "Angka Tidak Boleh Negatif Coy"
Else
Text1.Text = Sqr(x)
End If
End Sub
Private Sub Bagi_Click()
Text1.Text = ""
pilihan = "bagi"
y = x
x = 0
Tanda.Enabled = False
End Sub
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
x = Text1.Text
Tanda.Enabled = True
End Sub
Private Sub Form_Load()
Tanda.Enabled = False
End Sub
Private Sub Hasil_Click()
If pilihan = "tambah" Then
x = y + x
Text1.Text = x
ElseIf pilihan = "kurang" Then
x = y - x
Text1.Text = x
ElseIf pilihan = "kali" Then
x = y * x
Text1.Text = x
ElseIf pilihan = "bagi" And x <> 0 Then
x = y / x
Text1.Text = x
Else
Text1.Text = "Tidak Terdefinisi"
End If
End Sub
Private Sub Kali_Click()
Text1.Text = ""
pilihan = "kali"
y = x
x = 0
Tanda.Enabled = False
End Sub
Private Sub Koma_Click()
If Text1.Text = "" Then
Text1.Text = "0."
Else
Text1.Text = Text1.Text & "."
End If
End Sub
Private Sub Kuadrat_Click()
Text1.Text = x ^ 2
End Sub
Private Sub Kurang_Click()
Text1.Text = ""
pilihan = "kurang"
y = x
x = 0
Tanda.Enabled = False
End Sub
Private Sub Tambah_Click()
Text1.Text = ""
pilihan = "tambah"
y = x
x = 0
Tanda.Enabled = False
End Sub
Private Sub Tanda_Click()
If x < 0 Then
Text1.Text = -x
x = -x
Else
Text1.Text = "-" & Text1.Text
x = -x
End If
End Sub
7) Jika sudah coba jalankan dengan menekan tombol F5
Selamat Mencoba !!!
0 comments:
Post a Comment