Contoh Program Perulangan Menggunakan Case, For, While, Do While Pada VB 2008
1.Struktur keputusan menggunakan case
Gambar 1.2 Desain Program
Kode Program
Public Class Form1
Private Sub BtnBersih_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BtnBersih.Click
TxtHadiah.Clear()
TxtJPR.Clear()
End Sub
Private Sub BtnTutup_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BtnTutup.Click
End
End Sub
Private Sub BtnProses_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BtnProses.Click
Select Case Val(TxtJPR.Text)
Case
Is <= 1000
TxtHadiah.Text = "Mug Cantik"
Case
Is <= 1500
TxtHadiah.Text = "Boneka Cantik"
Case
Is <= 2000
TxtHadiah.Text = "Kipas Angin"
Case
Is <= 2500
TxtHadiah.Text = "Dispenser"
Case
Else
TxtHadiah.Text = "Tidak Ada"
End Select
End Sub
End Class
Gambar 1.2 Hasil Proses
Gambar 1.3 Tampilan Bersih
2.Program menggunakan Select Case To Case
Gambar 1.4 Desain Program
Kode Program
Gambar 1.5 Hasil Proses
Gambar 1.6 Tampilan Bersih
3.Contoh Program Menggunakan If Then Else
Gambar 1.7 Desain Grafis
Kode Program
Gambar 1.8 Hasil Proses
Gambar 1.9 Tampilan Penutup
4.Contoh Program Menggunakan Perulangan For
Gambar 1.10 Desain Program
Kode Program
Public Class Form1
Private Sub BtnProses_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BtnProses.Click
Dim i As Integer
ListBox1.Items.Clear()
For i =
1 To 10
ListBox1.Items.Add("Visual Basic")
Next
End Sub
End Class
Gambar 2.1 Hasil Proses
Gambar 2.2 Desain Program
Kode Program
Public Class Form2
Private Sub BtnProses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProses.Click
Dim i As Integer
i = 1
ListBox1.Items.Clear()
Do While i <= 10
ListBox1.Items.Add(i)
i = i + 1
Loop
End Sub
End Class
Gambar 2.3 Hasil Proses
Komentar
Posting Komentar