“Mari membuat ‘Kalkulator Sains’ dengan Visual Basic 2010″:)
Hai kawan, piye kabare jal?apik toh..
kali ini kami kan berbagi sedikit ilmu yang sudah kami dapat di kampus TI UNDIP tercinta. Ilmu yang kami dapat ini berkaitan dengan modul 2 praktikum teknologi informatika yang sudah kami lakukan sebelumnya.
Modul 2 ini berisi tentang “PengaplikasianOperator yang terdapat pada Visual Basic 2010″. Sebelu membuat suatu program pada VB 2010, terlebih dahulu kita buat flowchartnya ini akan memudahkan kita untuk mengetahui prosedur tahapan yang akan kita buat di programnya kita.
Nah, berikut adalah flowchart dari ‘kalkulator sains’ yang kami buat
a.Flowchart
Setelah flowchart dibuat, berikut adalah tutorial untuk membuat programnya
b. Tutorial
Tutorial Teknologi Informatika Visual Basic 2010 Modul 2
“ Scientific Calculator”
Langkah-langkah pembuatan programnya :
Membuka Aplikasi Visual Basic 2010
2. Klik ok maka akan mucul tampilan seperti berikut
3. Menampilkan Toolbox yang akan digunakan
Memasukkan toolbox-toolbox yang digunakanMemasukkan toolbox-toolbox yang akan digunakan dalam program ini. Untuk memunculkan toolbox, bisa dimunculkan dari menu bar -view – other windows – toolbox
4. Ubah nama Button dengan angka dan operator aritmatika yang diinginkan
Komponen toolbox yangdigunakan:
Komponen | Properties | Keterangan |
Form 1 | Nama
Text
| Form 1
TextBox1
|
Button1 | Nama
Text
| Button1
1
|
Button2 | Nama
Text
| Button2
2
|
Button3 | Nama
Text
| Button3
3
|
Button4 | Nama
Text
| Button4
4
|
Button5 | Nama
Text
| Button5
5
|
Button6 | Nama
Text
| Button6
6
|
Button7 | Nama
Text
| Button7
7
|
Button8 | Nama
Text
| Button8
8
|
Button9 | Nama
Text
| Button9
9
|
Button10 | Nama
Text
| Button10
0
|
Button11 | Nama
Text
| Button11
=
|
Button12 | Nama
Text
| Button12
+
|
Button13 | Nama
Text
| Button13
-
|
Button14 | Nama
Text
| Button14
*
|
Button15 | Nama
Text
| Button15
/
|
Button16 | Nama
Text
| Button16
^
|
Button17 | Nama
Text
| Button17
C
|
Button18 | Nama
Text
| Button18
Off
|
Button19 | Nama
Text
| Button19
%
|
Button20 | Nama
Text
| Button20
.
|
Button21 | Nama
Text
| Button21
sin
|
Button22 | Nama
Text
| Button22
Cos
|
Button23 | Nama
Text
| Button23
tan
|
Button24 | Nama
Text
| Button24
n!
|
Button25 | Nama
Text
| Button25
√
|
Button26 | Nama
Text
| Button26
00
|
Button27 | Nama
Text
| Button27
Log x
|
Button28 | Nama
Text
| Button28
del
|
5. Untuk mengganti background form1 pilih properties – Backgroundimage-local resource-import-ok
5. Mengganti jenis huruf pada button dan textBox (font), klik toolbox font
Lalu pilih jenis font, font style, dan size font dan mengganti latar button dan textBox (Back Color), klik toolbox BackColor silver.
Setelah bentuk form1 selesai, kemudian
Deklarasikan pada Public Class Form 1
Dim Angka, Hasil As Double
Dim sharedoperator As String
Const pi As Double = 3.14159265358979
Dim a, b As Integer
2.Untuk menampilkan angka 1 bila menekan button angka maka klik Button1 kemudian masukkan listing berikut :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “1”
Else
TextBox1.Text = TextBox1.Text & “1”
End If
End Sub
3.Untuk menampilkan angka 2 bila menekan button angka maka klik Button2 kemudian masukkan listing berikut :
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “2”
Else
TextBox1.Text = TextBox1.Text & “2”
End If
End Sub
4.Untuk menampilkan angka 3 bila menekan button angka maka klik Button3 kemudian masukkan listing berikut :
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “3”
Else
TextBox1.Text = TextBox1.Text & “3”
End If
End Sub
5.Untuk menampilkan angka 4 bila menekan button angka maka klik Button4 kemudian masukkan listing berikut :
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “4”
Else
TextBox1.Text = TextBox1.Text & “4”
End If
End Sub
6.Untuk menampilkan angka 5 bila menekan button angka maka klik Button5 kemudian masukkan listing berikut :
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “5”
Else
TextBox1.Text = TextBox1.Text & “5”
End If
End Sub
7.Untuk menampilkan angka 6 bila menekan button angka maka klik Button6 kemudian masukkan listing berikut :
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “6”
Else
TextBox1.Text = TextBox1.Text & “6”
End If
End Sub
8.Untuk menampilkan angka 7 bila menekan button angka maka klik Button7 kemudian masukkan listing berikut :
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “7”
Else
TextBox1.Text = TextBox1.Text & “7”
End If
End Sub
9.Untuk menampilkan angka 8 bila menekan button angka maka klik Button8 kemudian masukkan listing berikut :
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “8”
Else
TextBox1.Text = TextBox1.Text & “8”
End If
End Sub
10. Untuk menampilkan angka 9 bila menekan button angka maka klik Button9 kemudian masukkan listing berikut :
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “9”
Else
TextBox1.Text = TextBox1.Text & “9”
End If
End Sub
11. Untuk menampilkan angka 0 bila menekan button angka maka klik Button10 kemudian masukkan listing berikut :
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “0”
Else
TextBox1.Text = TextBox1.Text & “0”
End If
End Sub
12. Untuk event Button11_click dengan klik Button11 kemudian masukkan listing berikut:
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
If sharedoperator = “+” Then
Hasil = Angka + Val(TextBox1.Text)
TextBox1.Text = Hasil
ElseIf sharedoperator = “-” Then
Hasil = Angka – Val(TextBox1.Text)
TextBox1.Text = Hasil
ElseIf sharedoperator = “*” Then
Hasil = Angka * Val(TextBox1.Text)
TextBox1.Text = Hasil
ElseIf sharedoperator = “/” Then
Hasil = Angka / Val(TextBox1.Text)
TextBox1.Text = Hasil
ElseIf sharedoperator = “^” Then
Hasil = Angka ^ Val(TextBox1.Text)
TextBox1.Text = Hasil
ElseIf sharedoperator = “%” Then
Hasil = Angka / 100
TextBox1.Text = Hasil
ElseIf sharedoperator = “n!” Then
Hasil = a * (a – 1) * (a – 2) * (a – 3) * (a – b)
b = a – 1
TextBox1.Text = Hasil
ElseIf sharedoperator = “√” Then
Hasil = Angka ^ 0.5
TextBox1.Text = Hasil
End If
End Sub
13. Untuk Keluar maka klik Button18 kemudian masukkan listing berikut :
Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
End
End Sub
14. Untuk menampilkan tanda desimal(.) bila menekan button tanda maka klik Button20 kemudian masukkan listing berikut :
Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “.”
Else
TextBox1.Text = TextBox1.Text & “.”
End If
End Sub
15. Untuk menampilkan angka 00 bila menekan button angka maka klik Button26 kemudian masukkan listing berikut :
Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click
If TextBox1.Text = “0” Then
TextBox1.Text = “00”
Else
TextBox1.Text = TextBox1.Text & “00”
End If
End Sub
16. Untuk event Button12_Click kemudian klik Button12 lalu masukkan listing berikut :
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call Tambah()
End If
sharedoperator = “+”
TextBox1.Text = 0
End Sub
Private Sub Tambah()
If Angka = “0” Then
Angka = Val(TextBox1.Text)
Else
Angka = Angka + Val(TextBox1.Text)
End If
sharedoperator = “+”
TextBox1.Text = “”
End Sub
17.Untuk event Button13_Click kemudian klik Button13 lalu masukkan listing berikut :
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call kurang()
End If
sharedoperator = “-“
TextBox1.Text = 0
End Sub
Private Sub kurang()
If Angka = “0” Then
Angka = Val(TextBox1.Text)
Else
Angka = Angka – Val(TextBox1.Text)
End If
sharedoperator = “-“
TextBox1.Text = “”
End Sub
18. Untuk event Button14_Click kemudian klik Button14 lalu masukkan listing berikut :
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call kali()
End If
sharedoperator = “*”
TextBox1.Text = 0
End Sub
Private Sub kali()
If Angka = “0” Then
Angka = Val(TextBox1.Text)
Else
Angka = Angka * Val(TextBox1.Text)
End If
sharedoperator = “*”
TextBox1.Text = “”
End Sub
19. Untuk event Button15_Click kemudian klik Button15 lalu masukkan listing berikut :
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call bagi()
End If
sharedoperator = “/”
TextBox1.Text = 0
End Sub
Private Sub bagi()
If Angka = “0” Then
Angka = Val(TextBox1.Text)
Else
Angka = Angka / Val(TextBox1.Text)
End If
sharedoperator = “/”
TextBox1.Text = “”
End Sub
20. Untuk event Button16_Click kemudian klik Button16 lalu masukkan listing berikut :
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call pangkat()
End If
sharedoperator = “^”
TextBox1.Text = 0
End Sub
Private Sub pangkat()
If Angka = “0” Then
Angka = Val(TextBox1.Text)
Else
Angka = Angka ^ Val(TextBox1.Text)
End If
sharedoperator = “^”
TextBox1.Text = “”
End Sub
21.Untuk event Button17_Click kemudian klik Button17 lalu masukkan listing berikut :
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
TextBox1.Text = “0”
Angka = 0
Hasil = 0
sharedoperator = “”
End Sub
22.Untuk event Button19_Click kemudian klik Button19 lalu masukkan listing berikut :
Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call persen()
End If
sharedoperator = “%”
TextBox1.Text = 0
End Sub
Private Sub persen()
If Angka = 0 Then
Angka = Val(TextBox1.Text)
Else
Angka = Angka / 100
End If
sharedoperator = “%”
TextBox1.Text = “”
End Sub
23. Untuk event Button21_Click kemudian klik Button21 lalu masukkan listing berikut :
Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call sin()
End If
sharedoperator = “sin”
TextBox1.Text = 0
End Sub
Private Sub sin()
TextBox1.Text = Math.Sin(TextBox1.Text * (pi / 180))
End Sub
25. Untuk event Button22_Click kemudian klik Button22 lalu masukkan listing berikut :
Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call cos()
End If
sharedoperator = “cos”
TextBox1.Text = 0
End Sub
private Sub cos()
TextBox1.Text = Math.Cos(TextBox1.Text * (pi / 180))
end Sub
27. Untuk event Button23_Click kemudian klik Button23 lalu masukkan listing berikut :
Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call Tan()
End If
sharedoperator = “tan”
TextBox1.Text = 0
End Sub
Private Sub Tan()
TextBox1.Text = Math.Tan(TextBox1.Text * (pi / 180))
End Sub
28. Untuk event Button24_Click kemudian klik Button24 lalu masukkan listing berikut :
Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call faktorial()
End If
sharedoperator = “n!”
TextBox1.Text = 0
End Sub
Private Sub faktorial()
Dim a As Long
Dim fac As Integer
b = a – 1
If a = 0 Then
a = Val(TextBox1.Text)
Else : a = a * (a – 1) * (a – 2) * (a – b)
End If
fac = 1
a = TextBox1.Text
Dim i As Integer
For i = a To 1 Step -1
fac = fac * i
Next i
TextBox1.Text = fac
End Sub2
28.Untuk event Button27_Click kemudian klik Button27 lalu masukkan listing berikut :
Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button27.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call Log()
End If
sharedoperator = “log10″
TextBox1.Text = 0
End Sub
Private Sub Log()
TextBox1.Text = Math.Log10(TextBox1.Text)
End Sub
29.Untuk event Button25_Click kemudian klik Button25 lalu masukkan listing berikut :
Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
If sharedoperator <> “” Then
Select Case sharedoperator
Case “+”
Call Tambah()
Case “-“
Call kurang()
Case “x”
Call kali()
Case “/”
Call bagi()
Case “^”
Call pangkat()
Case “log”
Call Log()
Case “^1/2″
Call akar()
Case “n!”
Call faktorial()
Case “%”
Call persen()
Case “Sin”
Call sin()
Case “Cos”
Call cos()
Case “Tan”
Call Tan()
End Select
Else
Call akar()
End If
sharedoperator = “√”
TextBox1.Text = 0
End Sub
Private Sub akar()
If Angka = 0 Then
Angka = Val(TextBox1.Text)
Else
Angka = Angka ^ 0.5
End If
sharedoperator = “√”
TextBox1.Text = “”
End Sub
30.Untuk event Button28_Click kemudian klik Button28 lalu masukkan listing berikut :
Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button28.Click
If TextBox1.Text.Length <> 0 Then
TextBox1.Text = TextBox1.Text.Remove(TextBox1.Text.Length – 1, 1)
End If
End Sub
End Class
Setelah semua listing telah dimasukkan, kemudian Run Program yang telah dibuat tersebut dengan cara menekan tombol F5 pada keyboard.
0 comments:
Post a Comment