Langsung ke konten utama

Kasus 1 sampai 3 (Tipe data dan Variabel) pada Visual Basic .NET


Kasus 1 (Tipe Data dan Variabel)

Berikut Source Codenya :

Public Class kasus1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim nik, nama, jabatan, alamat As String
        nik = TextBox1.Text
        nama = TextBox2.Text
        jabatan = ComboBox1.Text
        alamat = TextBox3.Text
        'nadiahtami 2017230007'
        TextBox4.Text = nik
        TextBox5.Text = nama
        TextBox6.Text = jabatan
        TextBox7.Text = alamat
    End Sub
    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 'hanya bisa menginput angka
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        ComboBox1.Text = ""
    End Sub
    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
            Close()
            End
        End If
    End Sub
End Class
Kasus 2 (Tipe Data dan Variabel)

Berikut Source Codenya :

Public Class kasus2
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim kode, nama, isbn, kategori, harga As String
        kode = TextBox1.Text
        nama = TextBox2.Text
        isbn = TextBox3.Text
        kategori = ComboBox1.Text
        harga = TextBox4.Text
        'nadiahtami 201723007'
        TextBox5.Text = kode
        TextBox6.Text = nama
        TextBox7.Text = isbn
        TextBox8.Text = kategori
        TextBox9.Text = harga
    End Sub
    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 'hanya bisa menginput angka
        If (e.KeyChar = Chr(13)) Then
            TextBox2.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
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""
        ComboBox1.Text = ""
    End Sub
    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
            Close()
            End
        End If
    End Sub
End Class

Kasus 3 (Tipe Data dan Variabel)



Berikut Source Codenya :

Public Class kasus3
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim nim, nama, jk, jurusan, alamat As String
        nim = TextBox1.Text
        nama = TextBox2.Text
        jk = ComboBox1.Text
        jurusan = ComboBox2.Text
        alamat = TextBox3.Text
        'nadiahtami 201723007'
        TextBox4.Text = nim
        TextBox5.Text = nama
        TextBox6.Text = jk
        TextBox7.Text = jurusan
        TextBox8.Text = alamat
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        ComboBox1.Text = ""
        ComboBox2.Text = ""
    End Sub
    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 'hanya bisa menginput angka
        If (e.KeyChar = Chr(13)) Then
            TextBox2.Focus()
        End If
    End Sub

    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
            Close()
            End
        End If
    End Sub

End Class

Komentar

Postingan populer dari blog ini

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...

Latihan Menggunakan Procedure dan Function pada VB.Net

Latihan 1 Menggunakan Procedure Berikut Source Codenya : Public Class proc1     'nadiahtami 2017230007     Private Sub gantitext(ByVal teksbaru As String)         TextBox1.Text = teksbaru     End Sub     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         'btn pilih         gantitext("unsada")     End Sub     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click         'btn keluar         Dim pesan As String         pesan = MsgBox("Yakin ingin keluar?", vbYesNo, "Konfirmasi")         If pesan = vbYes Then             End         End If     End Sub End Class Latihan 2 ...

Percabangan (Struktur If-Then sd Nested IF)

- PERCABANGAN (If – Then) merupakan struktur percabangan dimana suatu ekspresi akan dikerjakan bila kondisinya terpenuhi. Tetapi jika kondisinya tidak terpenuhi maka ekspresi di dalam struktur if tidak akan dijalankan dan blok If akan dilompati serta program akan melakukan tindakan berikutnya. Berikut Strukturnya : If (kondisi) Then … Ekspresi … End If • Kondisi : Berisi perbandingan antara satu variabel/konstanta dengan variabel/konstanta lain dengan menggunakan tanda <, >, =, <> dari suatu keadaan yang akan menghasilkan nilai “Benar” atau “Salah”. • Ekspresi : Rangkaian kode program (blok program) yang akan dijalankan jika kondisinya memenuhi syarat “Benar”. - PERCABANGAN (If – Then – Else) merupakan struktur percabangan di mana suatu ekspresi akan dikerjakan bila kondisinya terpenuhi. Tetapi jika kondisinya tidak terpenuhi maka ekspresi yang lainnya yang dikerjakan. Berikut Strukturnya : If (kondisi) Then … Ekspresi 1 … Else … Ekspresi 2 … ...