Latihan 1
BIODATA
Form1 :
Code :
Private Sub Command1_Click()
Label6.Caption = Me.Text1.Text
Label7.Caption = Me.Text2.Text
Label8.Caption = Me.Text3.Text
Label9.Caption = Me.Text4.Text
End Sub
Private Sub Command2_Click()
Me.Text1 = ""
Me.Text2 = ""
Me.Text3 = ""
Me.Text4 = ""
Me.Label6 = ""
Me.Label7 = ""
Me.Label8 = ""
Me.Label9 = ""
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Text1_Change()
Label6.Caption = Text1.Text
End Sub
Private Sub Text2_Change()
Label7.Caption = Text2.Text
End Sub
Private Sub Text3_Change()
Label8.Caption = Text3.Text
End Sub
Private Sub Text4_Change()
Label9.Caption = Text4.Text
End Sub
Label6.Caption = Me.Text1.Text
Label7.Caption = Me.Text2.Text
Label8.Caption = Me.Text3.Text
Label9.Caption = Me.Text4.Text
End Sub
Private Sub Command2_Click()
Me.Text1 = ""
Me.Text2 = ""
Me.Text3 = ""
Me.Text4 = ""
Me.Label6 = ""
Me.Label7 = ""
Me.Label8 = ""
Me.Label9 = ""
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Text1_Change()
Label6.Caption = Text1.Text
End Sub
Private Sub Text2_Change()
Label7.Caption = Text2.Text
End Sub
Private Sub Text3_Change()
Label8.Caption = Text3.Text
End Sub
Private Sub Text4_Change()
Label9.Caption = Text4.Text
End Sub
Latihan 2
FUNGSI OPERATOR
Code :
End Sub
Private Sub cmd1_Click(Index As Integer)
txthasil = Val(txtnil1.Text) = (txtnil2.Text)
End Sub
Private Sub cmd2_Click(Index As Integer)
txthasil = Val(txtnil1.Text) < (txtnil2.Text)
End Sub
Private Sub cmd3_Click(Index As Integer)
txthasil = Val(txtnil1.Text) > (txtnil2.Text)
End Sub
Private Sub cmd4_Click(Index As Integer)
txthasil = Val(txtnil1.Text) <= (txtnil2.Text)
End Sub
Private Sub cmd5_Click(Index As Integer)
txthasil = Val(txtnil1.Text) >= (txtnil2.Text)
End Sub
Private Sub cmd6_Click(Index As Integer)
txthasil = Val(txtnil1.Text) <> (txtnil2.Text)
End Sub
Private Sub cmdand_Click(Index As Integer)
If txtnil1 = "true" And txtnil2 = "true" Then
txthasil = "true"
ElseIf txtnil1 = "true" And txtnil2 = "false" Then
txthasil = "false"
ElseIf txtnil1 = "true" And txtnil2 = "false" Then
txthasil = "false"
ElseIf txtnil1 = "false" And txtnil2 = "true" Then
txthasil = "false"
Else
txthasil = "false"
End If
End Sub
Private Sub cmdbagi_Click(Index As Integer)
txthasil = Val(txtnil1.Text) / (txtnil2.Text)
End Sub
Private Sub cmdkali_Click()
txthasil = Val(txtnil1.Text) * (txtnil2.Text)
End Sub
Private Sub cmdkeluar_Click(Index As Integer)
End
End Sub
Private Sub cmdkurang_Click()
txthasil = Val(txtnil1.Text) - (txtnil2.Text)
End Sub
Private Sub cmdlagi_Click(Index As Integer)
txtnil1.Text = ""
txtnil2.Text = ""
txthasil = ""
txtnot = ""
txtnil1.SetFocus
End Sub
Private Sub cmdmod_Click()
txthasil = Val(txtnil1.Text) Mod (txtnil2.Text)
End Sub
Private Sub cmdnot_Click(Index As Integer)
If cmdnot = True Then
txtnot = Not True
Else
txtnot = Not False
End If
End Sub
Private Sub cmdor_Click(Index As Integer)
If txtnil1 = "true" Or txtnil2 = "true" Then
txthasil = "true"
ElseIf txtnil1 = "true" Or txtnil2 = "false" Then
txthasil = "true"
ElseIf txtnil1 = "false" Or txtnil2 = "true" Then
txthasil = "true"
Else
txthasil = "false"
End If
End Sub
Private Sub cmdtambah_Click(Index As Integer)
txthasil = Val(txtnil1.Text) + (txtnil2.Text)
End Sub
Private Sub txtnil1_Change()
End Sub
Setelah di Run :
Latihan 3
PERCABANGAN
Code :
Private Sub cmdbersih_Click(Index As Integer)
Me.txtabsen = ""
Me.txttugas = ""
Me.txtuas = ""
Me.txtuts = ""
Me.txttotnil = ""
Me.txtgrade1 = ""
Me.txtket = ""
End Sub
Private Sub cmdhitung_Click(Index As Integer)
'Menghitung Total Nilai
txttotnil = Val(habsen.Text) + Val(htgs.Text) + Val(huts.Text) + Val(huas.Text)
'menghitung grade
If txttotnil >= 80 And txttotnil <= 100 Then
txtgrade1 = "A"
Else
If txttotnil >= 69 And txttotnil <= 79 Then
txtgrade1 = "B"
Else
If txttotnil >= 56 And txttotnil <= 68 Then
txtgrade1 = "C"
Else
If txttotnil >= 40 And txttotnil <= 55 Then
txtgrade1 = "D"
Else
txtgrade1 = "E"
End If
End If
End If
End If
'Menghitung keterangan
If txtgrade1 = "A" Or txtgrade1 = "B" Or txtgrade1 = "C" Then
txtket = "LULUS"
Else
txtket = "GAGAL"
End If
End Sub
Private Sub cmdkeluar_Click(Index As Integer)
End
End Sub
Private Sub Form_Activate()
habsen.Enabled = False
htgs.Enabled = False
huts.Enabled = False
huas.Enabled = False
txtabsen.SetFocus
End Sub
Private Sub txtabsen_Change()
habsen = 0.1 * Val(txtabsen)
End Sub
Private Sub txttgs_Change()
htgs = 0.2 * Val(txttgs)
End Sub
Private Sub txttugas_Change()
htgs = 0.2 * Val(txttgs)
End Sub
Private Sub txtuts_Change()
huts = 0.3 * Val(txtuts)
End Sub
Private Sub txtuas_Change()
huas = 0.4 * Val(txtuas)
End Sub
Setelah di Run :
konfirmasi :
Latihan 4
CAFE YUNFA
Code :
Private Sub Cmdpaket_Change()
End Sub
Private Sub Cmbmenu_Change()
End Sub
Private Sub Command1_Click()
Me.txtubay = ""
Me.txthrgmenu = ""
Me.txthrgminum = ""
Me.txtjumbel = ""
Me.txttotbay = ""
Me.txtubay = ""
Me.txtukem = ""
Me.txthrgfasilitas = ""
Me.List1 = ""
Me.Cmbmenu = ""
Me.Cmbpaket = ""
Me.Option1 = False
Me.Option2 = False
Me.Check1 = False
Me.Check2 = False
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Option1_Click()
txthrgfasilitas = 5000
End Sub
Private Sub Option2_Click()
txthrgfasilitas = 0
End Sub
Private Sub Form_Load()
Cmbmenu.AddItem ("Sarapan Pagi")
Cmbmenu.AddItem ("Makan Siang")
Cmbpaket.AddItem ("Paket 1")
Cmbpaket.AddItem ("Paket 2")
End Sub
Private Sub txtjumbel_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txttotbay = Val(txtjumbel) * (Val(txthrgmenu) + Val(txthrgfasilitas) + Val(txthrgminum))
txtubay.SetFocus
End If
End Sub
Private Sub cmbpaket_Click()
If Cmbmenu.Text = "Sarapan Pagi" Then
Select Case (Cmbpaket.Text)
Case "Paket 1"
List1.Clear
List1.AddItem ("Nasi Uduk")
List1.AddItem ("Telur")
List1.AddItem ("Tempe Orek")
txthrgmenu = 5000
Case Else
List1.Clear
List1.AddItem ("Nasi Goreng")
List1.AddItem ("Telur Mata Sapi")
List1.AddItem ("Tempe goreng")
txthrgmenu = 7000
End Select
Else
Select Case (Cmbpaket.Text)
Case "Paket 1"
List1.Clear
List1.AddItem ("Nasi Putih")
List1.AddItem ("Ayam Bakar")
List1.AddItem ("Lalapan")
txthrgmenu = 8000
Case Else
List1.Clear
List1.AddItem ("Nasi Putih")
List1.AddItem ("Rendang")
List1.AddItem ("Sayur")
List1.AddItem ("Sambal Ijo")
txthrgmenu = 10000
End Select
End If
End Sub
Private Sub Check1_Click()
If Check1 = 1 And Check2 = 1 Then
txthrgminum = 3000
ElseIf Check1 = 1 And Check2 = 0 Then
txthrgminum = 2500
ElseIf Check1 = 0 And Check2 = 1 Then
txthrgminum = 500
Else
txthrgminum = 0
End If
End Sub
Private Sub Check2_Click()
If Check1 = 1 And Check2 = 1 Then
txthrgminum = 3000
ElseIf Check1 = 1 And Check2 = 0 Then
txthrgminum = 2500
ElseIf Check1 = 0 And Check2 = 1 Then
txthrgminum = 500
Else
txthrgminum = 0
End If
End Sub
Private Sub txtubay_Change()
txtukem = Val(txtubay) - (txttotbay)
End Sub
Setelah di RUN :
Latihan 5
PERULANGAN ( LOOPING)
Code :
Private Sub Command3_Click()
End Sub
Private Sub cmddountil_Click()
List1.Clear
i = 1
Do Until i > 5
List1.AddItem (i)
i = i + 1
Loop
End Sub
Private Sub cmddowhile_Click()
List1.Clear
i = 10
Do While i > 6
List1.AddItem (i)
i = i - 1
Loop
End Sub
Private Sub cmdfornext_Click()
List1.Clear
Dim a As Integer
a = 1
jumlah = 0
For i = 1 To 10
List1.AddItem (i)
jumlah = jumlah + a
a = a + 2
Next
End Sub
Private Sub cmdwhilewent_Click()
List1.Clear
i = 20
While i <= 60
List1.AddItem (i)
i = i + 10
Wend
End Sub
Private Sub Form_Load()
For i = 1 To 31
Me.cmbtgl.AddItem (Str(i))
Next i
For i = 1 To 12
Me.cmbbln.AddItem (MonthName(i))
Next i
For i = 1990 To Year(Now)
Me.cmbthn.AddItem (Str(i))
Next i
End Sub
Private Sub List1_Click()
End Sub
End Sub
Private Sub cmddountil_Click()
List1.Clear
i = 1
Do Until i > 5
List1.AddItem (i)
i = i + 1
Loop
End Sub
Private Sub cmddowhile_Click()
List1.Clear
i = 10
Do While i > 6
List1.AddItem (i)
i = i - 1
Loop
End Sub
Private Sub cmdfornext_Click()
List1.Clear
Dim a As Integer
a = 1
jumlah = 0
For i = 1 To 10
List1.AddItem (i)
jumlah = jumlah + a
a = a + 2
Next
End Sub
Private Sub cmdwhilewent_Click()
List1.Clear
i = 20
While i <= 60
List1.AddItem (i)
i = i + 10
Wend
End Sub
Private Sub Form_Load()
For i = 1 To 31
Me.cmbtgl.AddItem (Str(i))
Next i
For i = 1 To 12
Me.cmbbln.AddItem (MonthName(i))
Next i
For i = 1990 To Year(Now)
Me.cmbthn.AddItem (Str(i))
Next i
End Sub
Private Sub List1_Click()
End Sub
Setelah di RUN :
moho maaf sebelumnya saya boleh minta property nya gak dari semua project ini satu per satu?biar lbh mengerti bljrnya.Thx before
BalasHapus