PROGRAM CALCULATOR MENGGUNAKAN VICUAL BASIC 2010
Pada program kali ini kita akan membuat program calculator dengan menggunakan visual basic 2010,dalam program kali ini toolbox yang kita gunakan hanya 3 yaitu :button,label dan textbox.Untuk lebih jelasnya kita simak dan pelajari langkah-langkah pembuatan calculator di bawah ini
Langkah-langkah pembuatan program calculator
1.buka microsoft visual studio 2010 lalu new project
( tampilan utama pada Microsoft visual 2010)
2.kemudian pilih windows form application,kemudian mengganti nama sesuai dengan keinginan anda
3.buat form
4.masukan label 1,textbox 1,button 17
5.merubah text pada button,label,dan nama pada textbox
6.mendesain tampilan pada calculator
7.kemudian membuat koding program seperti gambar di bawah ini
8.kemudian langkah terakhir klik debug > klik start debugging
(selesai)
(tampilan calculator menggunakan vicual basic 2010)
Koding program calculator
Public Class Form1
Dim nilai1, nilai2, hasil As Decimal
Dim sharedoperator As String
Dim phi As Decimal = 3.1415926535897944
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim nilai1 As Object
Dim sharedoperator As String
Dim hasil As Object
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Txthasil.Text = "" Then
Txthasil.Text = 1
Else : Txthasil.Text = Txthasil.Text & 1
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If Txthasil.Text = "" Then
Txthasil.Text = 2
Else : Txthasil.Text = Txthasil.Text & 2
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Txthasil.Text = "" Then
Txthasil.Text = 3
Else : Txthasil.Text = Txthasil.Text & 3
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Txthasil.Text = "" Then
Txthasil.Text = 4
Else : Txthasil.Text = Txthasil.Text & 4
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Txthasil.Text = "" Then
Txthasil.Text = 5
Else : Txthasil.Text = Txthasil.Text & 5
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If Txthasil.Text = "" Then
Txthasil.Text = 6
Else : Txthasil.Text = Txthasil.Text & 6
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If Txthasil.Text = "" Then
Txthasil.Text = 7
Else : Txthasil.Text = Txthasil.Text & 7
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If Txthasil.Text = "" Then
Txthasil.Text = 8
Else : Txthasil.Text = Txthasil.Text & 8
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Txthasil.Text = "" Then
Txthasil.Text = 9
Else : Txthasil.Text = Txthasil.Text & 9
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If Txthasil.Text = "" Then
Txthasil.Text = 0
Else : Txthasil.Text = Txthasil.Text & 0
End If
Txthasil.Text = Int(Txthasil.Text)
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
If nilai1 = 0 Then
nilai1 = Val(Txthasil.Text)
Else
nilai1 = nilai1 + Val(Txthasil.Text)
End If
sharedoperator = "+"
Txthasil.Text = 0
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
If nilai1 = 0 Then
nilai1 = Val(Txthasil.Text)
Else
nilai1 = nilai1 * Val(Txthasil.Text)
End If
sharedoperator = "*"
Txthasil.Text = 0
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
If nilai1 = 0 Then
nilai1 = Val(Txthasil.Text)
Else
nilai1 = nilai1 - Val(Txthasil.Text)
End If
sharedoperator = "-"
Txthasil.Text = 0
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
If nilai1 = 0 Then
nilai1 = Val(Txthasil.Text)
Else
nilai1 = nilai1 / Val(Txthasil.Text)
End If
sharedoperator = "/"
Txthasil.Text = 0
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
If sharedoperator = "+" Then
hasil = nilai1 + Val(Txthasil.Text)
Txthasil.Text = hasil
ElseIf sharedoperator = "-" Then
hasil = nilai1 - Val(Txthasil.Text)
Txthasil.Text = hasil
ElseIf sharedoperator = "*" Then
hasil = nilai1 * Val(Txthasil.Text)
Txthasil.Text = hasil
ElseIf sharedoperator = "/" Then
hasil = nilai1 / Val(Txthasil.Text)
Txthasil.Text = hasil
End If
nilai1 = 0
End Sub
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
Txthasil.Clear()
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
Me.Close()
End Sub
End Class
Tidak ada komentar:
Posting Komentar