Modul Visual Basic membuat Contoh Looping
1. Buatlah sebuah aplikasi baru (File | New Project | Standard EXE)
2. Masukan 2 TextBox, 2 Label, 1 ListBox dan 2 CommandButton
3. Gantilah properties masing-masing komponen seperti tertera dibawah ini :
Object Properties Value
Form1 ===> Caption ===> Looping
Label1 ===> Caption ===> Contoh Looping
Label2 ===> Caption ===> Jenis Looping
Label3 ===> Caption ===> Banyaknya Looping
Label4 ===> Caption ===> Ketikan Bandung - Lampung
Text1 ===> Text ===> <kosong>
Text2 ===> Text ===> <kosong>
ComboBox1=> Text ===> <kosong>
Form1 ===> Caption ===> Looping
Label1 ===> Caption ===> Contoh Looping
Label2 ===> Caption ===> Jenis Looping
Label3 ===> Caption ===> Banyaknya Looping
Label4 ===> Caption ===> Ketikan Bandung - Lampung
Text1 ===> Text ===> <kosong>
Text2 ===> Text ===> <kosong>
ComboBox1=> Text ===> <kosong>
Name ===> cmbJenisLooping
List1Box
Command1 => Caption ===> Looping
Command2 => Caption ===> Keluar
4. Sesuai dengan Layout berikut :
Command1 => Caption ===> Looping
Command2 => Caption ===> Keluar
4. Sesuai dengan Layout berikut :
5. Masukan code untuk CommandButton Looping
Dim Count As Integer
Dim i As Integer
Count = Val(Text1.Text)
## Visual Programming (Visual Basic) ##
Created by Aristoteles, 2007 13
If Count <= 0 Then
MsgBox "Nilai harus besar dari 0", vbInformation, "Error"
Else
List1.Clear
i = 0
Select Case cmbJenisLooping.ListIndex
Case 0:
For i = 0 To Count - 1
List1.AddItem Text2.Text & " data ke - " & i + 1 & " For -- Next", i
Next i
Case 1:
While i < Count
List1.AddItem Text2.Text & " data ke - " & i + 1 & " While -- Wend", i
i = i + 1
Wend
Case Else
Do
List1.AddItem Text2.Text & " data ke - " & i + 1 & " Do -- Loop Until", i
i = i + 1
Loop Until i > Count - 1
End Select
End If
6. Masukan code untuk FormLoad
cmbJenisLooping.AddItem "For -- next"
cmbJenisLooping.AddItem "While -- wend"
cmbJenisLooping.AddItem "Do loop until"
cmbJenisLooping.ListIndex = 0
7. Masukan code untuk CommandButton Keluar
Unload Me
8. Tekan F5 untuk menjalankan program (Running)