Langsung ke konten utama

Latihan 8-12 menggunakan Perulangan (Do While – Loop, Do – Loop While, Do Until – Loop, Do – Loop Until)

Latihan 8 - Perulangan Do While – Loop


Berikut Source Codenya :

Public Class latihan8
    'nadiahtami 2017230007'
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim pesan As String
        pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            End
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer = 0
        Do While i <= 10
            ListBox1.Items.Add("Perulangan dengan Do While ke" & i)
            i = i + 1
        Loop
    End Sub
End Class

Latihan 9 - Perulangan Do While – Loop



Berikut Source Codenya :

Public Class latihan9
    'nadiahtami 2017230007'
    Dim halaman As Byte
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim pesan As String
        pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            End
        End If
    End Sub
    Private Sub latihan9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        halaman = 1
        Do While halaman <= 10
            ComboBox1.Items.Add(halaman)
            halaman = halaman + 1
        Loop
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        halaman = 1
        Do While halaman <= 10
            ComboBox2.Items.Add(halaman)
            halaman = halaman + 1
        Loop
    End Sub
    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        Dim hasil As Double = 1
        For i = 1 To Val(ComboBox2.Text)
            hasil = hasil * ComboBox1.Text
        Next
        TextBox1.Text = hasil
    End Sub
End Class

Latihan 10 - Perulangan Do – Loop While


Berikut Source Codenya :

Public Class latihan10
    'nadiahtami 2017230007'
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim pesan As String
        pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            End
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x
        x = TextBox1.Text
        Do
            x = x Mod 2
            If x = 0 Then
                MsgBox("Bilangan Genap")
                Exit Do
            ElseIf x = 1 Then
                MsgBox("Bilangan Ganjil")
                Exit Do
            End If
        Loop While Not x
    End Sub
End Class

Latihan 11 - Perulangan Do Until – Loop


Berikut Source Codenya :

Public Class latihan11
    'nadiahtami 2017230007'
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim pesan As String
        pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            End
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        i = 1
        ListBox1.Items.Clear()
        Do Until i > 10
            ListBox1.Items.Add(i)
            i += 1
        Loop
    End Sub
End Class

Latihan 12 - Perulangan Do – Loop Until


Berikut Source Codenya :

Public Class latihan12
    'nadiahtami 2017230007'
    Sub ulang(ByVal angka As Byte)
        If angka > 0 Then
            ListBox1.Items.Add("*" & angka & "*")
        End If
    End Sub
    Sub ulang_cetak(ByVal angka As Byte)
        If angka > 0 Then
            ListBox1.Items.Add("*" & angka & "*")
        End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim pesan As String
        pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            End
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As Byte = 0
        Do
            Call ulang(x)
            x = x + 2
        Loop Until x > (TextBox1.Text)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim x As Byte = 0
        Do
            Call ulang_cetak(x)
            x = x + 3
        Loop Until x > (TextBox1.Text)
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = ""
        ListBox1.Items.Clear()
    End Sub
End Class

Komentar

Postingan populer dari blog ini

Latihan menggunakan If-then-Else dan Nested-If

Latihan 1 menggunakan (IF – THEN –ELSE) Berikut Source Codenya : Public Class latihan1    'nadiahtami 2017230007     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         Dim keterangan As String         If TextBox1.Text >= 80 Then             keterangan = "Selamat Anda Lulus"         Else             keterangan = "Mohon Maaf Anda Belum Lulus"         End If         TextBox2.Text = keterangan     End Sub     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click         Dim pesan As String         pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")         If pesan = vbYes Then  ...

Latihan dan Kasus Array Multidimensi pada VB.NET

Latihan 1 Array Multidimensi Berikut Source Codenya : Public Class latihan4     'nadiahtami 2017230007'     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         Dim arr(4) As String         arr(0) = TextBox1.Text         arr(1) = TextBox2.Text         arr(2) = ComboBox1.Text         arr(3) = ComboBox2.Text         Dim list As New ListViewItem         list = ListView1.Items.Add(arr(0))         list.SubItems.Add(arr(1))         list.SubItems.Add(arr(2))         list.SubItems.Add(arr(3))         TextBox1.Text = TextBox1.Text + 1         TextBox2.Text = ""         ComboBox1.Text = ""         C...

Contoh Kasus Menggunakan IIF dan Select-Case pada VB.NET

Kasus 6 Menggunakan IIF Berikut Source Code nya: Public Class kasus6     'nadiahtami 2017230007     Dim hadir, tugas, uts, uas, akhir As Integer     Dim grade, keterangan As String     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click         Application.Exit()     End Sub     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         TextBox1.Text = ""         TextBox2.Text = ""         TextBox3.Text = ""         TextBox4.Text = ""         TextBox5.Text = ""         TextBox6.Text = ""         TextBox7.Text = ""         TextBox8.Text = ""         ComboBox1.Text = ""     End Sub  ...