VB. Net

 avatar
user_8530559
c_cpp
a month ago
5.6 kB
2
Indexable
Never
Public Class Form1
    'Deklarasi komponen pada Form
    Private Nim As Label
    Private Nama As Label
    Private Kelas As Label
    Private Gender As Label
    Private Alamat As Label
    Private Nim As TextBox
    Private Nama As TextBox
    Private KelasA As CheckBox
    Private KelasB As CheckBox
    Private KelasC As CheckBox
    Private KelasD As CheckBox
    Private KelasE As CheckBox
    Private Pria As RadioButton
    Private Wanita As RadioButton
    Private Alamat As TextBox
    Private Cetak As Button
    Private Hapus As Button
    Private Keluar As Button
    Private lblOutputNim As Label
    Private lblOutputNama As Label
    Private lblOutputKelas As Label
    Private lblOutputGender As Label
    Private lblOutputAlamat As Label

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Inisialisasi komponen
        Me.Text = "Form Input Data Mahasiswa"
        Me.Size = New Size(400, 400)

        Nim = New Label With {.Text = "NIM:", .Location = New Point(10, 10)}
        Nim = New TextBox With {.Location = New Point(100, 10)}

        Nama = New Label With {.Text = "Nama:", .Location = New Point(10, 40)}
        Nama = New TextBox With {.Location = New Point(100, 40)}

        Kelas = New Label With {.Text = "Kelas:", .Location = New Point(10, 70)}
        KelasA = New CheckBox With {.Text = "A", .Location = New Point(100, 70)}
        KelasB = New CheckBox With {.Text = "B", .Location = New Point(150, 70)}
        KelasC = New CheckBox With {.Text = "C", .Location = New Point(200, 70)}
        KelasD = New CheckBox With {.Text = "D", .Location = New Point(250, 70)}
        KelasE = New CheckBox With {.Text = "E", .Location = New Point(300, 70)}

        Gender = New Label With {.Text = "Jenis Kelamin:", .Location = New Point(10, 100)}
        Pria = New RadioButton With {.Text = "Pria", .Location = New Point(100, 100)}
        Wanita = New RadioButton With {.Text = "Wanita", .Location = New Point(150, 100)}

        Alamat = New Label With {.Text = "Alamat:", .Location = New Point(10, 130)}
        Alamat = New TextBox With {.Location = New Point(100, 130), .Size = New Size(250, 20)}

        Cetak = New Button With {.Text = "Cetak", .Location = New Point(10, 160)}
        Hapus = New Button With {.Text = "Hapus", .Location = New Point(100, 160)}
        Keluar = New Button With {.Text = "Keluar", .Location = New Point(200, 160)}

        lblOutputNim = New Label With {.Text = "", .Location = New Point(10, 200), .Size = New Size(350, 20)}
        lblOutputNama = New Label With {.Text = "", .Location = New Point(10, 220), .Size = New Size(350, 20)}
        lblOutputKelas = New Label With {.Text = "", .Location = New Point(10, 240), .Size = New Size(350, 20)}
        lblOutputGender = New Label With {.Text = "", .Location = New Point(10, 260), .Size = New Size(350, 20)}
        lblOutputAlamat = New Label With {.Text = "", .Location = New Point(10, 280), .Size = New Size(350, 20)}

        'Menambahkan komponen ke Form
        Me.Controls.Add(Nim)
        Me.Controls.Add(Nim)
        Me.Controls.Add(Nama)
        Me.Controls.Add(Nama)
        Me.Controls.Add(Kelas)
        Me.Controls.Add(KelasA)
        Me.Controls.Add(KelasB)
        Me.Controls.Add(KelasC)
        Me.Controls.Add(KelasD)
        Me.Controls.Add(KelasE)
        Me.Controls.Add(Gender)
        Me.Controls.Add(Pria)
        Me.Controls.Add(Wanita)
        Me.Controls.Add(Alamat)
        Me.Controls.Add(Alamat)
        Me.Controls.Add(Cetak)
        Me.Controls.Add(Hapus)
        Me.Controls.Add(Keluar)
        Me.Controls.Add(lblOutputNim)
        Me.Controls.Add(lblOutputNama)
        Me.Controls.Add(lblOutputKelas)
        Me.Controls.Add(lblOutputGender)
        Me.Controls.Add(lblOutputAlamat)

        'Menambahkan event handler untuk tombol
        AddHandler Cetak.Click, AddressOf Me.Cetak_Click
        AddHandler Hapus.Click, AddressOf Me.Hapus_Click
        AddHandler Keluar.Click, AddressOf Me.Keluar_Click
    End Sub

    Private Sub Cetak_Click(sender As Object, e As EventArgs)
        Dim nim As String = Nim.Text
        Dim nama As String = Nama.Text
        Dim kelas As String = ""
        If KelasA.Checked Then kelas &= "A "
        If KelasB.Checked Then kelas &= "B "
        If KelasC.Checked Then kelas &= "C "
        If KelasD.Checked Then kelas &= "D "
        If KelasE.Checked Then kelas &= "E "
        Dim gender As String = If(Pria.Checked, "Pria", If(Wanita.Checked, "Wanita", ""))
        Dim alamat As String = Alamat.Text

        lblOutputNim.Text = $"NIM: {nim}"
        lblOutputNama.Text = $"Nama: {nama}"
        lblOutputKelas.Text = $"Kelas: {kelas}"
        lblOutputGender.Text = $"Jenis Kelamin: {gender}"
        lblOutputAlamat.Text = $"Alamat: {alamat}"
    End Sub

    Private Sub Hapus_Click(sender As Object, e As EventArgs)
        Nim.Clear()
        Nama.Clear()
        KelasA.Checked = False
        KelasB.Checked = False
        KelasC.Checked = False
        KelasD.Checked = False
        KelasE.Checked = False
        Pria.Checked = False
        Wanita.Checked = False
        Alamat.Clear()

        lblOutputNim.Text = ""
        lblOutputNama.Text = ""
        lblOutputKelas.Text = ""
        lblOutputGender.Text = ""
        lblOutputAlamat.Text = ""
    End Sub

    Private Sub Keluar_Click(sender As Object, e As EventArgs)
        Me.Close()
    End Sub
End Class
Leave a Comment