Visual Basic Lanjutan Praktikum 1 Operator



Assalamu’alaikum warahmatullahi wabarakatuh..
Kembali lagi bersama saya Ilham Ramadhan, saya akan melanjutkan pelajaran yang pernah saya bahas yaitu Variabel dan Type Data cek link DISINI . Kali ini saya akan membahas tentang Visual Basic Lanjutan (Operator), oke langsung saja kita bahas tanpa berlama-lama, oke check it out...


Operator
  • Suatu tanda yang digunakan untuk menghubungkan satu variabel lain dengan tujuan melakukan berbagai manipulasi dan pengolahan data.
  • Operator adalah simbol dan karakter khusus (matematika) yang digunakan dalam suatu ekspresi.
Jenis-Jenis  Operator
  • Operator Penugasan
  • Operator Aritmatika
  • Operator Pembanding
  • Operator Logika
Contoh untuk aplikasinya dan source codenya dibawah ini :

Latihan 4 - Operator Aritmatika
  • Nilai Alas dan Tinggi di input.
  • Berikan Validasi Nilai Alas dan Tinggi hanya bisa diinput angka saja.
  • Jika tombol Hitung di klik maka Nilai luas akan tampil pada textbox Luas.
  • Tombol Keluar untuk Keluar dari aplikasi.
  • Source Code
Public Class Form1

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        'textbox hanya bisa diisi dengan angka
        'tekan enter untuk pindah ke textbox selanjutnya
        If (e.KeyChar = Chr(13)) Then
            TextBox2.Focus()
        End If
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[0-9]" _
            OrElse keyascii = Keys.Back) Then 'LaptopInformatika.com
            keyascii = 0
        End If
        e.Handled = CBool(keyascii)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim alas, tinggi As Integer
        Dim hasil As Double
        alas = TextBox1.Text
        tinggi = TextBox2.Text
        hasil = (alas * tinggi) / 2 'LaptopInformatika.com
        TextBox3.Text = hasil
    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 Mau Keluar ??", vbYesNo, "Konfirmasi") 'LaptopInformatika.com
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
    End Sub
End Class

Latihan 5 - Operator Logika

  • Nama depan dan nama belakang wajib diisi.
  • Berikan validasi hanya bisa diinput dengan HURUF.
  • Jika user tidak input nama depan atau belakang akan ada info “Anda belum input nama depan atau belakang” ketika di klik tombol OK.
  • Tombol keluar untuk keluar dari aplikasi.

  • Source Code
Public Class Form2

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        e.Handled = CBool(keyascii) 'LaptopInformatika.com
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        e.Handled = CBool(keyascii) 'LaptopInformatika.com
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim depan, belakang As String
        depan = TextBox1.Text
        belakang = TextBox2.Text
        If (TextBox1.Text = "" And TextBox2.Text = "") Then
            MessageBox.Show("ANDA BELUM MEMASUKKAN NAMA DEPAN DAN BELAKANG")
        ElseIf (TextBox1.Text = "" Or TextBox2.Text = "") Then
            MessageBox.Show("ANDA BELUM MEMASUKKAN NAMA DEPAN ATAU BELAKANG")
        Else : MessageBox.Show("Nama lengkap anda adalah " + depan + " " + belakang) 'LaptopInformatika.com
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Clear()
        TextBox2.Clear()
    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 Mau Keluar ??", vbYesNo, "Konfirmasi") 'LaptopInformatika.com
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Kasus 4 - Operator
  • Nilai Jari-jari diinput.
  • Gunakan Konstanta untuk Nilai Phi.
  • Gunakan Global Variabel.
  • Berikan validasi hanya angka untuk Inputan jari-jari.
  • Ketika dienter (Keypress) di textbox jari-jari Luas dan Keliling Lingkaran akan muncul.
  • Button Clear untuk membersihkan layar.
  • Button Keluar untuk keluar dari aplikasi.
Catatan :
       luas = phi * r * r
       Keliling = 2 * phi * r


  • Source Code
Public Class Form3
    Public jari As Integer
    Public luas, keliling As Double

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        'Validasi textbox panjang hanya bisa diisi oleh angka
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            Const phi = 3.14
            jari = Val(TextBox1.Text)
            luas = phi * jari * jari
            keliling = 2 * phi * jari 'LaptopInformatika.com
            TextBox2.Text = luas
            TextBox3.Text = keliling
        End If
    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 = ""
    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 Mau Keluar ??", vbYesNo, "Konfirmasi") 'LaptopInformatika.com
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Kasus 5 - Operator
  • Kode barang, Nama barang, Satuan, Harga Satuan dan Jumlah Beli di input.
  • Gunakan Global Variabel.
  • Berikan validasi untuk Inputan huruf dan angka.
  • Ketika dienter di textbox jumlah beli, Nilai total harga akan muncul(Keypress).
  • Uang Bayar diinput, ketika dienter, uang kembali akan muncul(Keypress).
  • Button Clear untuk membersihkan layar.
Catatan :
    Total harga = harga satuan*jumlah beli
    Uang Kembali = Uang Bayar-Total Harga


  • Source Code
Public Class Form4
    Dim kode, jumlah As Integer
    Dim nama As String
    Dim harga, total, bayar, kembali As Double

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then 'LaptopInformatika.com
            TextBox2.Focus()
        End If
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        If e.KeyChar = Chr(13) Then
            Me.ComboBox1.Focus()
        End If
        e.Handled = CBool(keyascii) 'LaptopInformatika.com
    End Sub

    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            TextBox4.Focus()
        End If
    End Sub

    Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            harga = Val(TextBox3.Text)
            jumlah = Val(TextBox4.Text) 'LaptopInformatika.com
            total = harga * jumlah
            TextBox5.Text = total
            TextBox6.Focus()
        End If
    End Sub

    Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            total = Val(TextBox5.Text)
            bayar = Val(TextBox6.Text)
            kembali = bayar - total
            TextBox7.Text = kembali
        End If
    End Sub

    Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            Me.TextBox3.Focus()
        End If
    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 = ""
        ComboBox1.Text = ""
        TextBox7.Text = ""
    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 Mau Keluar ??", vbYesNo, "Konfirmasi") 'LaptopInformatika.com
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Kasus 6 - Operator
  • Kode buku, Nama buku, kategori, Harga buku dan Jumlah Beli di input.
  • Berikan validasi untuk Inputan huruf dan angka.
  • Jumlah beli diinput ketika dienter, subtotal akan muncul(Keypress).
  • Uang Bayar diinput, ketika dienter, uang kembali akan muncul(Keypress).
  • Button Clear untuk membersihkan layar.

Catatan :
    Total harga = harga satuan*jumlah beli
    Uang Kembali = Uang Bayar-Total Harga

  • Source Code
Public Class Form5
    Dim kode, jumlah As Integer
    Dim nama As String
    Dim harga, total, bayar, kembali As Double
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            TextBox2.Focus()
        End If
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then 'LaptopInformatika.com
            keyascii = 0
        End If
        If e.KeyChar = Chr(13) Then
            Me.ComboBox1.Focus()
        End If
        e.Handled = CBool(keyascii)
    End Sub

    Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            Me.TextBox3.Focus()
        End If
    End Sub

    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            TextBox4.Focus()
        End If
    End Sub

    Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            harga = Val(TextBox3.Text)
            jumlah = Val(TextBox4.Text) 'LaptopInformatika.com
            total = harga * jumlah
            TextBox5.Text = total
            TextBox6.Focus()
        End If
    End Sub

    Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            total = Val(TextBox5.Text)
            bayar = Val(TextBox6.Text)
            kembali = bayar - total
            TextBox7.Text = kembali 'LaptopInformatika.com
        End If
    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 = ""
        ComboBox1.Text = ""
        TextBox7.Text = ""
    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 Mau Keluar ??", vbYesNo, "Konfirmasi") 'LaptopInformatika.com
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Mungkin segitu saja penjelasan dari saja kurang lebihnya mohon maaf hehehe

Berlangganan update artikel terbaru via email:

1 Response to "Visual Basic Lanjutan Praktikum 1 Operator"

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel