Visual Basic Lanjutan Teori 3 - Perulangan
Tuesday, March 24, 2020
3 Comments
Kembali lagi bersama saya Ilham Ramadhan, saya akan melanjutkan pelajaran yang pernah saya bahas silahkan cek di beranda yaa. Kali ini saya akan membahas tentang Visual Basic Lanjutan (Perulangan), oke langsung saja kita bahas tanpa berlama-lama, oke check it out...
PERULANGAN
- Struktur pengulangan atau Loop digunakan untuk mengulang suatu blok perintah sampai kondisi tertentu.
- Proses pengulangan ini dapat dikendalikan jumlahnya oleh aplikasi yang dibuat pada kondisi tertentu.
- Proses pengulangan akan terus dikerjakan selama kondisi yang dibandingkan oleh proses tersebut masih bernilai “Benar” (True).
- Jika kondisi yang dibandingkan bernilai “Salah” (False), proses pengulangan akan berhenti dan jalannya program akan dilanjutkan setelah proses pengulangan.
Struktur For - Next
- Struktur For – Next digunakan untuk mengulang blok perintah dalam jumlah yang sudah ditentukan.
- Pada struktur ini tidak perlu menentukan kondisi yang akan diuji tetapi perlu menentukan nilai awal dan akhir variabel penghitung.
- Nilai variabel penghitung secara otomatis akan bertambah atau berkurang setiap suatu pengulangan dikerjakan.
- Var : Nama variabel integer yang digunakan untuk melakukan proses
pengulangan. - Awal : Nilai suatu variabel integer untuk menentukan harga awal suatu
pengulangan. - Akhir : Nilai suatu variabel integer untuk menentukan harga akhir suatu
pengulangan. - Pertambahan/Penguarangan : Besarnya nilai perubahan dari nilai awal
sampai nilai akhir. Jika pengulangannya menurun yaitu dari nilai yang besar menuju ke nilai yang kecil, maka nilai perubahannya harus negatif. Nilai standar Visual Basic untuk pertambahan adalah 1, kecuali jika nilai perubahan ditentukan. Jika bentuk pengulangannya turun dari nilai besar ke nilai kecil, berikan nilai pertambahan negatif ( - ). - Ekspresi : Suatu blok perintah yang akan dikerjakan jika kondisi dari proses pengulangan memenuhi syarat.
- Source Code
Public Class Pertemuan_4_Latihan_1_Teori
Private Sub btkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btkeluar.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Pertemuan_4_Latihan_1_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_1_TeoriLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
End Sub
Private Sub btproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btproses.Click
Dim x As Integer
For x = 1 To 10
'laptopinformatika.blogspot.com
ListBox1.Items.Add(x)
Next x
End Sub
End Class
Latihan 2
- Source Code
Public Class Pertemuan_4_Latihan_2_Teori
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btkeluar.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btproses.Click
Dim x As Integer
For x = 10 To 1 Step -1
ListBox1.Items.Add(x)
Next
End Sub
Private Sub Pertemuan_4_Latihan_2_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_2_Teori_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
End Sub
End Class
Latihan 3
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
Private Sub bthitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bthitung.Click
Dim x, y, i, hasil As Double
x = Val(TextBox1.Text)
y = Val(TextBox2.Text)
hasil = 1
For i = 1 To y
hasil = hasil * x
Next
TextBox3.Text = Str(hasil)
End Sub
Private Sub Pertemuan_4_Latihan_3_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_3_Teori_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
End Sub
End Class
Latihan 4
- Source Code
Public Class Pertemuan_4_Latihan_4_Teori
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
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 Integer
For x = 1 To 7
'laptopinformatika.blogspot.com
ListBox1.Items.Add(WeekdayName(x))
Next
End Sub
Private Sub Pertemuan_4_Latihan_4_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_4_Teori_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
End Sub
End Class
- Source Code
Public Class Pertemuan_4_Latihan_5_Teori
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, y As Integer
For x = 1 To 3
For y = 1 To 3
ListBox1.Items.Add(x & y)
Next
Next
End Sub
Private Sub Pertemuan_4_Latihan_5_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_5_TeoriLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
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("Are You Sure Want to Exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
End Class
Latihan 6
- Source Code
Public Class Pertemuan_4_Latihan_6_Teori
Private Sub btkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btkeluar.Click
Dim pesan As String
pesan = MsgBox("Yakin Mau Keluar ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Pertemuan_4_Latihan_6_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Pertemuan_4_Latihan_6_TeoriLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
End Sub
Private Sub Btproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btproses.Click
Dim x As Integer
x = 1
While x <= 10
ListBox1.Items.Add(x)
x = x + 1
End While
End Sub
End Class
Latihan 7
- Source Code
Public Class Pertemuan_4_Latihan_7_Teori
Private Sub btcari_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btcari.Click
Dim x, i As Integer
x = Val(TextBox1.Text)
i = 1
x = x + 1
ListBox1.Items.Clear()
While i < 11
If x Mod 2 = 0 Then
ListBox1.Items.Add(x)
i = i + 1
End If
x = x + 1
End While
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("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Pertemuan_4_Latihan_7_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
Private Sub Pertemuan_4_Latihan_7_TeoriLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
End Sub
End Class
Kasus 1
- Source Code
Public Class Kasus 1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim pesan As String
pesan = MsgBox("Are You Sure Want to Exit", vbYesNo, "laptopinformatika.blogspot.com")
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 Integer
For x = 1 To 12
'laptopinformatika.blogspot.com
ListBox1.Items.Add(MonthName(x))
Next
End Sub
Private Sub Kasus_1Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
End Sub
End Class
Kasus 2
- Source Code
Public Class Kasus 2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pesan As String
pesan = MsgBox("Are You Sure Want to Exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Kasus_2Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
For i = 1 To 30
ComboBox1.Items.Add(i)
Next
For i = 1 To 12
ComboBox2.Items.Add(i)
Next
For i = 2019 To 1990 Step -1
ComboBox3.Items.Add(i)
Next
End Sub
End Class
- Source Code
Public Class Kasus 3
'laptopinformatika.blogspot.com'
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, y, i, hasil As Integer
x = Val(TextBox1.Text)
y = Val(TextBox2.Text)
For i = x To y
If i Mod 2 = 0 Then
ListBox2.Items.Add(i)
ElseIf i Mod 2 = 1 Then
ListBox1.Items.Add(i)
End If
Next
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("Are You Sure Want to Exit ?", vbYesNo, "laptopinformatika.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Kasus_3Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "laptopinformatika.blogspot.com"
End Sub
End Class
Thank you
ReplyDeleteMakasih bang
ReplyDeleteThanks bermanfaat sekali pelajarannya
ReplyDelete