Home, Forum diskusi, Chatting, Download


Latihan 2

Judul : Memahami beberapa event yang umum pada kontrol.

1. Buatlah project baru, dengan Form1

Kontrol Properti Value
Text1 Name
CauseValidation
txtUmur
True
Text2 Name txtCoba1
Text3 Name txtCoba2
Command1 Name
Caption
Default
cmdDefault
&Default True
True
Command2 Name
Caption
Cancel
cmdCancel
&Cancel True
True

2. Lakukan Koding berikut :

Private Sub cmdCancel_Click()
MsgBox "cmdCancel Event Click"
End Sub

Private Sub cmdDefault_Click()
MsgBox "cmdDefault Event Enter"
End Sub

Private Sub txtCoba2_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print "txtCoba2 Event Keydown dengan KeyCode :" & KeyCode & " Shift : " & Shift
End Sub

Private Sub txtCoba2_KeyPress(KeyAscii As Integer)
Debug.Print "txtCoba2 Event KeyPressed dengan KeyAscii : " & KeyAscii
End Sub

Private Sub txtCoba2_KeyUp(KeyCode As Integer, Shift As Integer)
Debug.Print "txtCoba2 Event Keyup dengan KeyCode : " & KeyCode & " Shift : " & Shift
End Sub

Private Sub txtCoba3_Click()
Debug.Print "txtCoba3 Event Click"
End Sub

Private Sub txtCoba3_DblClick()
Debug.Print "txtCoba3 Event DblClick"
End Sub

Private Sub txtCoba3_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "txtCoba3 Event MouseDown dengan Button : " & Button & " Shift : " & Shift & " X : " & X & " Y : " & Y
End Sub

Private Sub txtCoba3_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "txtCoba3 Event MouseMove dengan Button : " & Button & " Shift : " & Shift & " X : " & X & " Y : " & Y
End Sub

Private Sub txtCoba3_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "txtCoba3 Event MouseUp dengan Button : " & Button & " Shift : " & Shift & " X : " & X & " Y : " & Y
End Sub


Private Sub txtCoba1_GotFocus()
MsgBox "txtCoba1 menerima fokus"
End Sub

Private Sub txtCoba1_LostFocus()
MsgBox "txtCoba1 kehilangan fokus"
End Sub

Private Sub txtCoba2_Change()
Debug.Print "txtCoba2 Change"
End Sub

Private Sub txtUmur_Validate(Cancel As Boolean)
If (Val(txtUmur) < 5) Or (Val(txtUmur) > 125) Then
   MsgBox "Masukkan umur 5 s/d 125" & vbCrLf & _
          "Event Validate"
   Cancel = True
End If
End Sub

Dibuat  oleh hendra@indoprog.com
Medan - Sumatera Utara
Indonesia