Bagi pada pemula yang masih bingung untuk Membuat
kalkulator sederhana menggunakan visual basic 2008/vb.net kali ini
saya ingin memberikan artikel bagaimanaMembuat kalkulator sederhana
menggunakan visual basic 2008/vb.net dan dibawah ini adalah cara memulai
pembuatan kalkulator sederhana versi saya.
Buatlah satu form
dengan komponen :
1 textbox
2 label
4 radio button
rubah visible untuk label1 menjadi falsedan
ganti text radiobutton1 menjadi Tambah, radiobutton2 menjadi Kurang,
radiobutton3 menjadi Kali dan radiobtton4 menjadi Bagi seperti gambar dibawah:
Selanjutnya klik 2
kali form yang sudah dibuat dan hapus semua kode yang ada lalu ganti dengan
kode ini:
Public Class form1
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Then
TextBox1.Text = 0
End If
If RadioButton1.Checked = True Then
Label2.Text = TextBox1.Text + +Label1.Text
ElseIf RadioButton2.Checked = True Then
Label2.Text = Label1.Text - TextBox1.Text
ElseIf RadioButton3.Checked = True Then
Label2.Text = Label1.Text * TextBox1.Text
ElseIf RadioButton4.Checked = True Then
Label2.Text = Label1.Text / TextBox1.Text
End If
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
Label1.Text = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
Label1.Text = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
Label1.Text = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
Label1.Text = TextBox1.Text
TextBox1.Text = 0
End Sub
End Class
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Then
TextBox1.Text = 0
End If
If RadioButton1.Checked = True Then
Label2.Text = TextBox1.Text + +Label1.Text
ElseIf RadioButton2.Checked = True Then
Label2.Text = Label1.Text - TextBox1.Text
ElseIf RadioButton3.Checked = True Then
Label2.Text = Label1.Text * TextBox1.Text
ElseIf RadioButton4.Checked = True Then
Label2.Text = Label1.Text / TextBox1.Text
End If
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
Label1.Text = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
Label1.Text = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
Label1.Text = TextBox1.Text
TextBox1.Text = 0
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
Label1.Text = TextBox1.Text
TextBox1.Text = 0
End Sub
End Class
Tidak ada komentar:
Posting Komentar