Kali ini saya akan menjelaskan pembuatan calculator di Visual Basic .NET, langkah-langkah pembuatannya adalah sebagai berikut:
- Buka Visual Basic 2008 kemudian anda buat Form baru. Bisa langsung di start page, klik Create Project atau bisa juga klik File di menubar pilih New Project sampai muncul tampilan seperti di bawah ini. Setelah itu pilih Windows Form Aplication kemudian isi label name dengan calculator, tekan tombol Ok .
- Kemudian setelah form baru muncul buat design calculator seperti gambar di bawah ini:
Isikan source codenya sebagai berikut:
Public Class calculator
Dim FirstNumber As Long
Dim Operation As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If LCD.Text = "0" Then
LCD.Text = "1"
Else
LCD.Text = LCD.Text & "1"
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If LCD.Text = "0" Then
LCD.Text = "2"
Else
LCD.Text = LCD.Text & "2"
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If LCD.Text = "0" Then
LCD.Text = "3"
Else
LCD.Text = LCD.Text & "3"
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If LCD.Text = "0" Then
LCD.Text = "4"
Else
LCD.Text = LCD.Text & "4"
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If LCD.Text = "0" Then
LCD.Text = "5"
Else
LCD.Text = LCD.Text & "5"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If LCD.Text = "0" Then
LCD.Text = "6"
Else
LCD.Text = LCD.Text & "6"
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If LCD.Text = "0" Then
LCD.Text = "7"
Else
LCD.Text = LCD.Text & "7"
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If LCD.Text = "0" Then
LCD.Text = "8"
Else
LCD.Text = LCD.Text & "8"
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If LCD.Text = "0" Then
LCD.Text = "9"
Else
LCD.Text = LCD.Text & "9"
End If
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If LCD.Text = "0" Then
LCD.Text = "0"
Else
LCD.Text = LCD.Text & "0"
End If
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
LCD.Text = "0"
End Sub
Private Sub badd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles badd.Click
FirstNumber = LCD.Text
LCD.Text = "0"
Operation = "+"
End Sub
Private Sub bmul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bmul.Click
FirstNumber = LCD.Text
LCD.Text = "0"
Operation = "-"
End Sub
Private Sub bmult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bmult.Click
FirstNumber = LCD.Text
LCD.Text = "0"
Operation = "*"
End Sub
Private Sub bdiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bdiv.Click
FirstNumber = LCD.Text
LCD.Text = "0"
Operation = "/"
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bequal.Click
Dim SecondNumber As Long
Dim Result As String
SecondNumber = LCD.Text
If Operation = "+" Then
Result = FirstNumber + SecondNumber
ElseIf Operation = "-" Then
Result = FirstNumber - SecondNumber
ElseIf Operation = "*" Then
Result = FirstNumber * SecondNumber
ElseIf Operation = "/" Then
Result = FirstNumber / SecondNumber
End If
FirstNumber = Result
LCD.Text = Result
End Sub
End Class
tolong posting code untuk password yg terprotection donk...
BalasHapusthxs...!