TUTORIAL MEMBUAT KALKULATOR DENGAN VISUAL BASIC 2010

24 Nov

TUTORIAL MEMBUAT KALKULATOR

MENGGUNAKAN VISUAL BASIC 2010

 

Program yang akan dibuat di dalam program visual basic 2010 ini adalah sebuah kalkulator sederhana. Tujuan pembuatan kalkulator ini adalah untuk memudahkan dalam perhitungan suatu angka, di dalam kalkulator ini terdapat beberapa jenis operasi angka, yaitu penjumlahan, pengurangan, perkalian, pembagian, dan akar kuadrat. Cara pemakaian dari kalkulator ini sama seperti kalkulator pada umumnya. Untuk lebih jelasnya tentang cara pembuatan kalkulator ini bias dilihat pada tutorial berikut ini:

Bukalah program Visual Basic 2010 pada computer anda.

  1. Setelah jendela Visual Basic terbuka, maka pilihlah file -> new project->windows forms applications pada menu tab seperti gambar di bawah ini

2. Setelah itu, akan muncul sebuah form yang berjudul form1 . Kita dapat memberi nama form tersebut dengan mengubah nama pada properties nya, dalam hal ini nama form1 diganti dengan nama “CALCULATOR” . setelah itu untuk menambahkan tombol-tombol angka, tombol-tombol operasi, dan juga input angka pada kalkulator yang akan kita buat, kita dapat menambahkan textbox untuk kotak memasukkan angka pada kalkulator dan menggunakan button untuk tombol-tombol angka dan pengoperasian pada kalkulator. Texbox dan button diatur sedemikian rupa sehingga terlihat seperti pada gambar di bawah ini

@font-face { font-family: “Wingdings”; }@font-face { font-family: “Calibri”; }@font-face { font-family: “Tahoma”; }@font-face { font-family: “Consolas”; }p.MsoNormal, li.MsoNormal, div.MsoNormal { margin: 0in 0in 10pt; line-height: 115%; font-size: 11pt; font-family: “Times New Roman”; }p.MsoAcetate, li.MsoAcetate, div.MsoAcetate { margin: 0in 0in 0.0001pt; font-size: 8pt; font-family: Tahoma; }p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph { margin: 0in 0in 10pt 0.5in; line-height: 115%; font-size: 11pt; font-family: “Times New Roman”; }p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst { margin: 0in 0in 0.0001pt 0.5in; line-height: 115%; font-size: 11pt; font-family: “Times New Roman”; }p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle { margin: 0in 0in 0.0001pt 0.5in; line-height: 115%; font-size: 11pt; font-family: “Times New Roman”; }p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast { margin: 0in 0in 10pt 0.5in; line-height: 115%; font-size: 11pt; font-family: “Times New Roman”; }span.BalloonTextChar { font-family: Tahoma; }div.Section1 { page: Section1; }ol { margin-bottom: 0in; }ul { margin-bottom: 0in; }

Apabila form sudah dibuat sepert pada gambar di atas, dilanjutkan dengan memasukkan listing agar kalkulator tersebut dapat digunakan. Listing pada pembuatan kalkulator di atas adalah:

 

 

Public Class Form1

Dim nilai, Hasil, Angka As Double

Dim pattern As String

 

 

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click

TextBox1.Text = TextBox1.Text & “0”

End Sub

 

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

TextBox1.Text = TextBox1.Text & “1”

End Sub

 

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

TextBox1.Text = TextBox1.Text & “2”

End Sub

 

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

TextBox1.Text = TextBox1.Text & “3”

End Sub

 

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

TextBox1.Text = TextBox1.Text & “4”

End Sub

 

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

TextBox1.Text = TextBox1.Text & “5”

End Sub

 

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

TextBox1.Text = TextBox1.Text & “6”

End Sub

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

TextBox1.Text = TextBox1.Text & “7”

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

TextBox1.Text = TextBox1.Text & “8”

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

TextBox1.Text = TextBox1.Text & “9”

End Sub

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

nilai = TextBox1.Text

pattern = “/”

TextBox1.Text = “”

End Sub

 

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click

TextBox1.Text = Nothing

nilai = Nothing

Hasil = Nothing

Angka = Nothing

pattern = Nothing

End Sub

 

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

nilai = TextBox1.Text

pattern = “*”

TextBox1.Text = “”

End Sub

 

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

nilai = TextBox1.Text

pattern = “-“

TextBox1.Text = “”

End Sub

 

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click

nilai = TextBox1.Text

pattern = “+”

TextBox1.Text = “”

End Sub

 

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click

nilai = TextBox1.Text

pattern = “^”

TextBox1.Text = “”

End Sub

 

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click

TextBox1.Text = TextBox1.Text & “.”

End Sub

 

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click

If pattern = “+” Then

Hasil = nilai + Val(TextBox1.Text)

TextBox1.Text = Format(Hasil)

ElseIf pattern = “-” Then

Hasil = nilai – Val(TextBox1.Text)

TextBox1.Text = Format(Hasil)

ElseIf pattern = “*” Then

Hasil = nilai * Val(TextBox1.Text)

TextBox1.Text = Format(Hasil)

ElseIf pattern = “/” Then

Hasil = nilai / Val(TextBox1.Text)

TextBox1.Text = Format(Hasil)

ElseIf pattern = “^” Then

Hasil = nilai ^ Val(TextBox1.Text)

TextBox1.Text = Format(Hasil)

End If

Angka = “0”

End Sub

 

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click

TextBox1.Text = TextBox1.Text ^ 0.5

End Sub

 

Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click

TextBox1.Text = TextBox1.Text & “00”

End Sub

 

Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click

Close()

End Sub

Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click

TextBox1.Enabled = True

Button1.Enabled = True

Button2.Enabled = True

Button3.Enabled = True

Button4.Enabled = True

Button5.Enabled = True

Button6.Enabled = True

Button7.Enabled = True

Button8.Enabled = True

Button9.Enabled = True

Button10.Enabled = True

Button11.Enabled = True

Button12.Enabled = True

Button13.Enabled = True

Button14.Enabled = True

Button15.Enabled = True

Button16.Enabled = True

Button17.Enabled = True

Button18.Enabled = True

Button19.Enabled = True

Button20.Enabled = True

End Sub

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

TextBox1.Enabled = False

Button1.Enabled = False

Button2.Enabled = False

Button3.Enabled = False

Button4.Enabled = False

Button5.Enabled = False

Button6.Enabled = False

Button7.Enabled = False

Button8.Enabled = False

Button9.Enabled = False

Button10.Enabled = False

Button11.Enabled = False

Button12.Enabled = False

Button13.Enabled = False

Button14.Enabled = False

Button15.Enabled = False

Button16.Enabled = False

Button17.Enabled = False

Button18.Enabled = False

Button19.Enabled = False

Button20.Enabled = False

End Sub

 

Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click

TextBox1.Enabled = False

Button1.Enabled = False

Button2.Enabled = False

Button3.Enabled = False

Button4.Enabled = False

Button5.Enabled = False

Button6.Enabled = False

Button7.Enabled = False

Button8.Enabled = False

Button9.Enabled = False

Button10.Enabled = False

Button11.Enabled = False

Button12.Enabled = False

Button13.Enabled = False

Button14.Enabled = False

Button15.Enabled = False

Button16.Enabled = False

Button17.Enabled = False

Button18.Enabled = False

Button19.Enabled = False

Button20.Enabled = False

End Sub

End Class

 

 

Setelah semua listing tersebut dimasukkan, kita dapat menggunakan kalkulator tersebut dengan cara running( menekan F5) pada Visual Basic.

 

Selamat mencoba J

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: