Senin, 10 April 2017

Contoh Penggunaan Enable & Disable pada Visual Studio 2015



KODINGNYA:

Public Class Form1
    Dim hasil As Integer
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label1.Text = "Nilai 1"
        Label2.Text = "Nilai 2"
        Label3.Text = "Nilai 3"
        Label4.Text = "Nilai 4"
        Button1.Text = "Ok"
        Button2.Text = "Tambah"
        Button3.Text = "Kurang"
        Button4.Text = "Kali"
        Button5.Text = "Bagi"
        RadioButton1.Text = "Tambah"
        RadioButton2.Text = "Kurang"
        RadioButton3.Text = "Kali"
        RadioButton4.Text = "Bagi"

        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False

        TextBox4.Enabled = False
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        MsgBox("Anda akan menghidupkan input textnya")
        TextBox4.Enabled = True
    End Sub

    Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
        Button2.Enabled = True

        Button3.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False
    End Sub

    Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
        Button3.Enabled = True
        Button2.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False
    End Sub

    Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
        Button4.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False

        Button5.Enabled = False
    End Sub

    Private Sub RadioButton4_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton4.CheckedChanged
        Button5.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        MsgBox("Anda akan membagi nilainya")
        ListBox1.Items.Add("----------Hasil dari pembagian adalah----------")
        hasil = Val(TextBox1.Text) / Val(TextBox2.Text) / Val(TextBox3.Text) / Val(TextBox4.Text)
        ListBox1.Items.Add(hasil)
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        MsgBox("Anda akan menjumlahkan nilainya")
        ListBox1.Items.Add("----------Hasil dari pertambahan adalah----------")
        hasil = Val(TextBox1.Text) + Val(TextBox2.Text) + Val(TextBox3.Text) + Val(TextBox4.Text)
        ListBox1.Items.Add(hasil)
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        MsgBox("Anda akan mengurangi nilainya")
        ListBox1.Items.Add("----------Hasil dari pengurangan adalah----------")
        hasil = Val(TextBox1.Text) - Val(TextBox2.Text) - Val(TextBox3.Text) - Val(TextBox4.Text)
        ListBox1.Items.Add(hasil)
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        MsgBox("Anda akan mengalikan nilainya")
        ListBox1.Items.Add("----------Hasil dari perkalian adalah----------")
        hasil = Val(TextBox1.Text) * Val(TextBox2.Text) * Val(TextBox3.Text) * Val(TextBox4.Text)
        ListBox1.Items.Add(hasil)
    End Sub
End Class


0 komentar:

Posting Komentar