Sabtu, 21 Desember 2013

Membuat Aplikasi “Simple Calculator” dengan Visual Basic.NET 2010

SimpleCalculator.NET

Seperti janji saya sebelumnya kali ini saya terapkan pembuatan aplikasi ini dengan Visual Basic.NET dan jika teman-teman bandingkan dari kedua gambarnya aplikasi ini saya buat semirip mungkin tampilannya dalam pembuatan aplikasi serupa dengan menggunakan Visual Basic 6. Sehingga kita dapat membandingkannya secara langsung perbedaan perintah dari kedua bahasa pemrograman ini. Untuk selanjutnya saya masih akan terus mengembangkan pembuatan aplikasi dengan prosedur aritmatika tetapi mungkin sama halnya dengan aplikasi ini bersifat sederhana.

1. Jalankan terlebih dahulu aplikasi Visual Basic 2010

2. Pada tabulasi “Start Page” pilih “New Project” atau bisa juga dengan menekan tombol “Ctrl + N” pada keyboard

3. Pada jendela “New Project” pilih “Windows Forms Application” kemudian tekan tombol “OK

4. Berikut setingan kontrol properti yang terdapat pada aplikasi ini

Object Name Properties Setting
Form Form1 Form Border Style Fixed Single
    Maximize Box False
    Minimize Box False
    Start Position Center Screen
    Text Simple Calculator
Label lblFirst Font Tahoma; 10pt
    Text First Number :
Text Box txtFirst Font Tahoma; 12pt
    Text Align Right
Label lblSecond Font Tahoma; 10pt
    Text Second Number :
Text Box txtSecond Font Tahoma; 12pt
    Text Align Right
Button cmdAdd Font Tahoma; 10pt
    Text Add
Button cmdSubtract Font Tahoma; 10pt
    Text Subtract
Button cmdMultiple Font Tahoma; 10pt
    Text Multiple
Button cmdDevide Font Tahoma; 10pt
    Text Divide
Label lblResult Font Tahoma; 10pt
    Text Result :
Text Box txtResult Font Tahoma; 12pt
    Text Align Right
Button cmdClear Font Tahoma; 10pt
    Text Clear
Button cmdExit Font Tahoma; 10pt
    Text Exit

5. Berikut event code program

Public Class Form1

Private Sub txtFirst_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFirst.KeyPress
If e.KeyChar = ChrW(Keys.Enter) Then SendKeys.Send("{tab}")

If Not (e.KeyChar >= ChrW(Keys.D0) And e.KeyChar <= ChrW(Keys.D9) Or e.KeyChar = ChrW(Keys.Back)) Then
e.KeyChar = ChrW(0)
End If
End Sub

Private Sub txtSecond_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSecond.KeyPress
If e.KeyChar = ChrW(Keys.Enter) Then SendKeys.Send("{tab}")

If Not (e.KeyChar >= ChrW(Keys.D0) And e.KeyChar <= ChrW(Keys.D9) Or e.KeyChar = ChrW(Keys.Back)) Then
e.KeyChar = ChrW(0)
End If
End Sub

Private Sub txtResult_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtResult.TextChanged
cmdClear.Enabled = True
End Sub

Private Sub txtSecond_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSecond.TextChanged
cmdAdd.Enabled = True
cmdSubtract.Enabled = True
cmdMultiple.Enabled = True
cmdDevide.Enabled = True

If txtSecond.Text = "" Then
cmdAdd.Enabled = False
cmdSubtract.Enabled = False
cmdMultiple.Enabled = False
cmdDevide.Enabled = False
End If
End Sub

Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
End
End Sub

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
txtResult.Text = Val(txtFirst.Text) + Val(txtSecond.Text)
End Sub

Private Sub cmdSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubtract.Click
txtResult.Text = Val(txtFirst.Text) - Val(txtSecond.Text)
End Sub

Private Sub cmdMultiple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMultiple.Click
txtResult.Text = Val(txtFirst.Text) * Val(txtSecond.Text)
End Sub

Private Sub cmdDevide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDevide.Click
txtResult.Text = Val(txtFirst.Text) / Val(txtSecond.Text)
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtResult.BackColor = Color.FromKnownColor(KnownColor.Window)
End Sub

Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
txtFirst.Text = ""
txtSecond.Text = ""
txtResult.Text = ""
cmdClear.Enabled = False
txtFirst.Focus()
End Sub

End Class

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda