Visual Basic Lanjutan Praktikum 5 - Procedure dan Function


Laptopinformatika.com - Assalamualaikum Wr.Wb. kemarin kita sudah bahas pengertian procedure dan function. kali ini saya akan memberikan materi lanjutan dari VB Lanjutan Teori 5 yaitu VB Lanjutan Praktikum 5, mungkin tidak berbeda jauh tapi lebih banyak saja di bagian design nya. Silahkan membaca pengertian Procedure dan Function di vb lanjutan teori 5.

Untuk Latihan-latihan sebelumnya ada di link bawah ini, jika kalian ingin mempelajari semuanya silahkan klik link di bawah ini :
  1. Visual Basic Lanjutan Teori 1 Variabel dan Type Data
  2. Visual Basic Lanjutan Praktikum 1 Operator
  3. Visual Basic Lanjutan Teori 2 Percabangan (Struktur If-Then, If-Then-Else, Nested IF)
  4. Visual Basic Lanjutan Praktikum 2 Percabangan (IIF dan Select Case)
  5. Visual Basic Lanjutan Teori 3 - Perulangan
  6. Visual Basic Lanjutan Praktikum 3 - Perulangan (Do While - Loop)
  7. Visual Basic Lanjutan Teori 4 - Array Dimensi Satu
  8. Visual Basic Lanjutan Praktikum 4 - Array Dimensi Dua
  9. Visual Basic Lanjutan Teori 5 - Procedure dan Function

Read More : Pemrosesan Transaksi dalam Sistem Manajemen Database yang Wajib Anda Ketahui

Kasus 1

Membuat Prosedur Untuk Menampilkan
  • Agama
  • Jurusan
  • Program Studi
  • Kota


  • Source Code

Public Class Form1
    Sub KomboAgama()
        Me.ComboBox1.Items.Add("Islam")
        Me.ComboBox1.Items.Add("Kristen Protestan")
        Me.ComboBox1.Items.Add("Kristen Katolic")
        Me.ComboBox1.Items.Add("Hindu")
        Me.ComboBox1.Items.Add("Buddha") 'laptopinformatika.com
    End Sub

    Sub KomboJurusan()
        Me.ComboBox2.Items.Add("Manajemen Informatika")
        Me.ComboBox2.Items.Add("Teknik Informatika")
        Me.ComboBox2.Items.Add("Sistem Informatika")
    End Sub

    Sub KomboProgi()
        Me.ComboBox3.Items.Add("D1")
        Me.ComboBox3.Items.Add("D2")
        Me.ComboBox3.Items.Add("D3")
        Me.ComboBox3.Items.Add("D4")
        Me.ComboBox3.Items.Add("S1")
        Me.ComboBox3.Items.Add("S2")
        Me.ComboBox3.Items.Add("S3") 'laptopinformatika.com
    End Sub

    Sub ListKota()
        Me.ListBox1.Items.Add("Bandung")
        Me.ListBox1.Items.Add("Denpasar")
        Me.ListBox1.Items.Add("Jakarta")
        Me.ListBox1.Items.Add("Surabaya")
        Me.ListBox1.Items.Add("Manado")
        Me.ListBox1.Items.Add("Medan")
        Me.ListBox1.BackColor = Color.Silver 'laptopinformatika.com
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "LaptopInformatika.com"
        KomboAgama()
        KomboJurusan()
        KomboProgi()
        ListKota()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim message As String
        message = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.com")
        If message = vbYes Then
            End
        End If
    End Sub
End Class

Read More : The Best SEO untuk Tahun 2020

Kasus 2


  • Source Code

Public Class Form2
    Sub Clean()
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()
        TextBox5.Clear()
        TextBox6.Clear()
    End Sub

    Private Function hitung()
        Dim jumlah, harga, total As Double
        jumlah = TextBox5.Text 'laptopinformatika.com
        harga = TextBox4.Text
        total = jumlah * harga
        TextBox6.Text = total
        Return total
    End Function

    Sub CheckEmptyData()
        If TextBox1.Text = "" Then
            MessageBox.Show("Item Code Must be filled !!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox1.Focus()
        ElseIf TextBox2.Text = "" Then 'laptopinformatika.com
            MessageBox.Show("Item Name Must be filled !!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox2.Focus()
        ElseIf TextBox3.Text = "" Then
            MessageBox.Show("Unit Must be filled !!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox3.Focus()
        ElseIf TextBox5.Text = "" Then
            MessageBox.Show("Amount Must be filled !!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox5.Focus()
        ElseIf TextBox4.Text = "" Then 'laptopinformatika.com
            MessageBox.Show("Unit Price Must be filled !!", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox4.Focus()
        Else
            Call hitung()
        End If
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "LaptopInformatika.com"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call CheckEmptyData() 'laptopinformatika.com
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call Clean() 'laptopinformatika.com
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim message As String
        message = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.com")
        If message = vbYes Then
            End
        End If
    End Sub
End Class

Read More : 6 Tips dan Triks Data Recovery RAID yang Perlu Anda Ketahui

Kasus 3

  • Buat Prosedur Bersih utk membersihkan semua textbox.
  • Buat Function hitung untuk Menghitung Total Harga.
  • Buat Prosedur Cekdatakosong utk mengecek inputan textbox mulai kode barang sd Jumlah harus diisi dan panggil Function hitung.
  • Pada saat Form di jalankan dan pada saat di klik Clear, Panggil Prosedur Bersih.
  • Tombol Hitung, panggil Prosedure cekdatakosong.
  • Tombol exit utk menutup aplikasi dengan Messagebox.


  • Source Code

Public Class Form3

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "LaptopInformatika.com"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ganjil, genap, prima, legend As Integer 'laptopinformatika.com
        proses(ganjil, genap, prima, legend)
        ShowSum(TextBox1.Text, TextBox2.Text)
    End Sub

    Sub ShowSum(ByRef number1 As Integer, ByVal number2 As Integer)
        Dim number As Integer
        number = number1 + number2 'laptopinformatika.com
        TextBox3.Text = number
    End Sub

    Sub bilganjil()
        Dim ganjil As Integer
        ListBox1.Items.Clear()
        ganjil = 1
        Do While ganjil <= 20
            ListBox1.Items.Add(ganjil) 'laptopinformatika.com
            ganjil = ganjil + 2
        Loop
    End Sub

    Sub bilgenap()
        Dim genap As Integer
        ListBox1.Items.Clear()
        genap = 0
        Do While genap <= 20
            ListBox1.Items.Add(genap) 'laptopinformatika.com
            genap = genap + 2
        Loop
    End Sub
    Sub bilprima()
        Dim prima, x, y, z As Integer
        ListBox1.Items.Clear()
        For x = 2 To 100
            z = 0
            For y = 2 To x
                prima = x Mod y
                If prima = 0 Then
                    z = z + 1
                End If
            Next y
            If z <= 1 Then
                ListBox1.Items.Add(x) 'laptopinformatika.com
            End If
        Next x
    End Sub

    Sub billegend()
        ListBox1.Items.Clear()
        Dim a As Integer = 0
        Dim b As Integer = 1
        Dim fib As Integer = 0
        ListBox1.Items.Add("1")
        Do
            fib = a + b
            a = b
            b = fib
            ListBox1.Items.Add(fib.ToString) 'laptopinformatika.com
        Loop While fib <= 100
    End Sub

    Sub proses(ByVal ganjil As String, ByRef genap As String, ByVal prima As String, ByVal legend As String)
        If (ComboBox1.SelectedIndex.Equals(0)) Then
            bilganjil()
        ElseIf (ComboBox1.SelectedIndex.Equals(1)) Then
            bilgenap()
        ElseIf (ComboBox1.SelectedIndex.Equals(2)) Then
            bilprima()
        ElseIf (ComboBox1.SelectedIndex.Equals(3)) Then 'laptopinformatika.com
            billegend()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim message As String
        message = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.com")
        If message = vbYes Then
            End
        End If
    End Sub
End Class

Oke mungkin sekian materi hari ini, mudah-mudahan bermanfaat bagi kalian semua, kurang lebihnya mohon maaf, Thank You~~~

Berlangganan update artikel terbaru via email:

0 Response to "Visual Basic Lanjutan Praktikum 5 - Procedure dan Function"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel