cara membuat kalkulator pada vb.net atau visual basic . net.
buatlah form seperti ini pada form[design] :
buatlah form seperti ini pada form[design] :
lalu pada form1.vb ketik seperti ini :
Public Class Form1
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kali.CheckedChanged
If kali.Checked Then
bagi.Enabled = False
kurang.Enabled = False
tambah.Enabled = False
bagi.Enabled = False
pangkat.Enabled = False
End If
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah.CheckedChanged
If tambah.Checked Then
bagi.Enabled = False
kurang.Enabled = False
kali.Enabled = False
pangkat.Enabled = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If tambah.Checked Then
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
ElseIf kali.Checked Then
TextBox3.Text = Val(TextBox1.Text) * Val(TextBox2.Text)
ElseIf pangkat.Checked Then
TextBox3.Text = Val(TextBox1.Text) ^ Val(TextBox2.Text)
ElseIf kurang.Checked Then
TextBox3.Text = Val(TextBox1.Text) - Val(TextBox2.Text)
ElseIf bagi.Checked Then
TextBox3.Text = Val(TextBox1.Text) / Val(TextBox2.Text)
End If
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 = ""
tambah.Checked = False
tambah.Enabled = True
kurang.Checked = False
kurang.Enabled = True
kali.Checked = False
kali.Enabled = True
bagi.Checked = False
bagi.Enabled = True
pangkat.Checked = False
pangkat.Enabled = True
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End
End Sub
Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kurang.CheckedChanged
If kurang.Checked Then
tambah.Enabled = False
kali.Enabled = False
bagi.Enabled = False
pangkat.Enabled = False
End If
End Sub
Private Sub pangkat_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pangkat.CheckedChanged
If pangkat.Checked Then
bagi.Enabled = False
kurang.Enabled = False
kali.Enabled = False
tambah.Enabled = False
End If
End Sub
Private Sub bagi_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bagi.CheckedChanged
If bagi.Checked Then
tambah.Enabled = False
kurang.Enabled = False
kali.Enabled = False
pangkat.Enabled = False
End If
End Sub
ini adalah contoh program yang sedang di jalakan sebagai berikut :
Tidak ada komentar:
Posting Komentar