Minggu, 22 Desember 2013

Membuat Aplikasi “Calculator” dengan Visual Basic.NET 2010

Calculator VB.NET

Ada sedikit perbedaan dalam properti Command Button pada Visual Basic 6.0. Memang Visual Nasic.NET layak di acungi jempol dikarenakan banyak properti dari sebuah kontrol jadi lebih memikat lagi…”Good Job”…Dan seperti janji saya sebelumnya aplikasi ini sudah saya terapkan dan percaya atau tidak ternyata tidak ada perbedaan dalam pemrogramannya. Teman-teman penasaran dengan yang saya maksudkan?silahkan teman-teman coba sendiri.

 

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 Font Tahoma; 10pt
    Form Border Style Fixed Single
    Maximize Box False
    Minimize Box False
    Start Position Center Screen
    Text Calculator
Text Box txtDisplay Enabled False
    Font Tahoma; 18pt
    Text Align Right
Button cmdOne Text 1
Button cmdTwo Text 2
Button cmdThree Text 3
Button cmdFour Text 4
Button cmdFive Text 5
Button cmdSix Text 6
Button cmdSeven Text 7
Button cmdEight Text 8
Button cmdNine Text 9
Button cmdZero Text 0
Button cmdClear Fore Color Red
    Text C
Button cmdAdd Fore Color Red
    Text +
Button cmdSubtract Fore Color Red
    Text -
Button cmdMultiple Fore Color Red
    Text *
Button cmdDevide Fore Color Red
    Text /
Button cmdResult Fore Color Red
    Text =

5. Berikut event code program

Public Class Form1
Dim PointAdd As Integer
Dim PointSubtract As Integer
Dim PointMultiple As Integer
Dim PointDevide As Double
Dim Result As Integer
Dim Coice As String

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

Private Sub cmdOne_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOne.Click
txtDisplay.Text = txtDisplay.Text + cmdOne.Text
End Sub

Private Sub cmdTwo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTwo.Click
txtDisplay.Text = txtDisplay.Text + cmdTwo.Text
End Sub

Private Sub cmdThree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdThree.Click
txtDisplay.Text = txtDisplay.Text + cmdThree.Text
End Sub

Private Sub cmdFour_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFour.Click
txtDisplay.Text = txtDisplay.Text + cmdFour.Text
End Sub

Private Sub cmdFive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFive.Click
txtDisplay.Text = txtDisplay.Text + cmdFive.Text
End Sub

Private Sub cmdSix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSix.Click
txtDisplay.Text = txtDisplay.Text + cmdSix.Text
End Sub

Private Sub cmdSeven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSeven.Click
txtDisplay.Text = txtDisplay.Text + cmdSeven.Text
End Sub

Private Sub cmdEight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEight.Click
txtDisplay.Text = txtDisplay.Text + cmdEight.Text
End Sub

Private Sub cmdNine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNine.Click
txtDisplay.Text = txtDisplay.Text + cmdNine.Text
End Sub

Private Sub cmdZero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdZero.Click
txtDisplay.Text = txtDisplay.Text + cmdZero.Text
End Sub

Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
txtDisplay.Text = ""
End Sub

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
PointAdd = Val(txtDisplay.Text)
txtDisplay.Text = ""
Coice = "Add"
End Sub

Private Sub cmdSubtract_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubtract.Click
PointSubtract = Val(txtDisplay.Text)
txtDisplay.Text = ""
Coice = "Subtract"
End Sub

Private Sub cmdMultiple_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMultiple.Click
PointMultiple = Val(txtDisplay.Text)
txtDisplay.Text = ""
Coice = "Multiple"
End Sub

Private Sub cmdDevide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDevide.Click
PointDevide = Val(txtDisplay.Text)
txtDisplay.Text = ""
Coice = "Devide"
End Sub

Private Sub cmdResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdResult.Click
Select Case Coice
Case "Add"
Result = PointAdd + Val(txtDisplay.Text)
txtDisplay.Text = Str(Result)
Case "Subtract"
Result = PointSubtract - Val(txtDisplay.Text)
txtDisplay.Text = Str(Result)
Case "Multiple"
Result = PointMultiple * Val(txtDisplay.Text)
txtDisplay.Text = Str(Result)
Case "Devide"
Result = PointDevide / Val(txtDisplay.Text)
txtDisplay.Text = Str(Result)
End Select
End Sub
End Class

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda