Anda di halaman 1dari 4

TUGAS 6

Latihan 1:
(Operasi String)

1. Buat sebuah Project Standard Exe baru.

2. Source Code :

Dim nim As String


Dim hasil As String
Dim ps As String

Private Sub Command1_Click()


hasil = "Halo " + UCase(Text1.Text) + ", kalau tidak salah Anda adalah :" + vbCr
nim = Left(Text2.Text, 2)
hasil = hasil + "Mahasiswa Angkatan " + nim + vbCr
nim = Mid(Text2.Text, 3, 1)
If nim = 1 Then
ps = "Strata 1"
ElseIf nim = 3 Then
ps = "Diploma 3"
Else
ps = "Anda tidak jelas"
End If
hasil = hasil + "Program Studi " + ps + vbCr
nim = Right(Text2.Text, 4)
hasil = hasil + "Dan Anda Adalah Mahasiswa Ke " + nim + " di STMIK Global" + vbCr
hasil = hasil + "Benar kan?"
MsgBox hasil, vbOKOnly + vbInformation, "::message nim ::"
End Sub

Private Sub Command2_Click()


Unload Me
End Sub

3. Jalankan dengan menekan F5


Latihan 2:
(Operasi Date/Time)

1. Pada Jendela Form buatlah UI (User Interface) seperti ini :

Name : DtPicker

Untuk mengaktifkan objek DtPicker, tekan


Ctrl + T, lalu centang Microsoft windows
Control 2.6.0

2. Source Code :

Private Sub Command1_Click()


Text1.Text = DateDiff("d", DTPicker1.Value, DTPicker2.Value)
End Sub

Latihan 3:
(Validasi Input)

1. Buka form latihan 1 di atas.


2. Tambahkan module, dengan cara pilih menu Project  Add Module, lalu ketik kode di bawah ini :

Public Sub CharacterValid(KeyAscii As Integer) 3. Double klik Textbox Nama, dan pada
Const Character = event Keypress ketikkan :
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXx
YyZz "
Private Sub Text1_KeyPress(KeyAscii As
If KeyAscii <> 8 And KeyAscii <> 13 Then
Integer)
If InStr(Character, Chr(KeyAscii)) = 0 Then
Call CharacterValid(KeyAscii)
KeyAscii = 0
End Sub
Exit Sub
End If
End If
End Sub 4. Double klik Textbox NIM, dan pada
event Keypress ketikkan :

Public Sub NumberValid(KeyAscii As Integer) Private Sub Text2_KeyPress(KeyAscii As


Const Number = "0123456789" Integer)
If KeyAscii <> 8 And KeyAscii <> 13 Then Call NumberValid(KeyAscii)
If InStr(Number, Chr(KeyAscii)) = 0 Then End Sub
KeyAscii = 0
Exit Sub
5. Jalankan aplikasi tersebut.
End If
End If
End Sub
Latihan 4:
(Contoh Prosedur)

1. Buatlah form dengan lay-out sbb :

Objek : Timer1
Properties= Interval : 500

Objek : TextBoz1
Properties
Text : 8
Alignment : 1

2. Source Code :

Private Sub Check1_Click()


If Check5.Value = 1 Then
Call SetFont(Check1.Value, Check2.Value, Check3.Value, Check4.Value, Text1.Text)
Else
Call SetFont(Check1.Value, Check2.Value, Check3.Value, Check4.Value, 8)
End If
End Sub

Private Sub Check2_Click() Private Sub Check3_Click() Private Sub Check4_Click()


Call Check1_Click Call Check1_Click Call Check1_Click
End Sub End Sub End Sub
Private Sub Check5_Click() Private Sub Timer1_Timer()
Call Check1_Click Label2.Visible = Not Label2.Visible
End Sub End Sub

3. Jalankan aplikasi tersebut dengan menekan F5