You are on page 1of 3

Struktur kontrol Perulangan. Dalam Visual basic kita kenal 2 struktur control yaitu : 1.

ForNext bu: For (pencacah) = (awal) to (akhir) (statemen) Next(pencacah) 2. DoLoop bu : a. Do While (kondisi) (blok) Loop b. Do Until (kondisi) (blok) Loop Contoh Program Sederhana 1. Buatlah Tampilan seperti ini :

Listing Program : Dim i As Integer Dim angka as string Private Sub Command1_Click() For i = 0 To 5 List1.AddItem i Next i End Sub Private Sub Command2_Click() i=1 Do While i <= 5 List2.AddItem i i=i+1

Loop End Sub Private Sub Command3_Click() i=0 Do Until i > 5 i=i+1 List3.AddItem i Loop End Sub Private Sub Command4_Click() For i = 1 To 3 angka = For j = 1 To i angka = angka & j & Next j List4.AddItem angka Next i End Sub 2. Buatlah Tampilan seperti ini :

Listing program : Dim i, isi As Integer Dim nama(20) As String Private Sub bersih() Text1.Text = List1.Clear Text1.SetFocus End Sub Private Sub Command1_Click() Label1.Visible = True Text1.Visible = True

bersih End Sub Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then isi = 1 i = Val(Text1.Text) Label1.Visible = False Text1.Visible = False Do While (isi <= i) nama(isi) = InputBox(Masukan Nama ke- + Str(isi), Menginput Nama sebanyak + Str(i) + Kali) List1.AddItem nama(isi) isi = isi + 1 Loop End If End Sub Tampilan Untuk input Box :

You might also like