Skip to main content
Search
Search This Blog
Vbfeed4
Home
More…
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
Labels
Visual Basic.Net
June 11, 2017
Program Kalkulator Dengan Visual Basic .Net
Public Class Form1 #Region "Deklarasi Variabel" Private valHolder1 As Double Private valHolder2 As Double Private tmpValue As Double Private Memory As Double Private hasDecimal As Boolean Private inputStatus As Boolean Private clearText As Boolean Private fungsihitung As String #End Region #Region "Tombol angka" Private Sub cmd9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd9.Click If inputStatus = False Then txtInput.Text += cmd9.Text Else txtInput.Text = cmd9.Text inputStatus = False End If End Sub Private Sub cmd8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd8.Click If inputStatus = False Then txtInput.Text += cmd8.Text Else txtInput.Text = cmd8.Text inputStatus = False End If End Sub Private Sub cmd7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd7.Click If inputStatus = False Then txtInput.Text += cmd7.Text Else txtInput.Text = cmd7.Text inputStatus = False End If End Sub Private Sub cmd6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd6.Click If inputStatus = False Then txtInput.Text += cmd6.Text Else txtInput.Text = cmd6.Text inputStatus = False End If End Sub Private Sub cmd5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd5.Click If inputStatus = False Then txtInput.Text += cmd5.Text Else txtInput.Text = cmd5.Text inputStatus = False End If End Sub Private Sub cmd4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd4.Click If inputStatus = False Then txtInput.Text += cmd4.Text Else txtInput.Text = cmd4.Text inputStatus = False End If End Sub Private Sub cmd3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd3.Click If inputStatus = False Then txtInput.Text += cmd3.Text Else txtInput.Text = cmd3.Text inputStatus = False End If End Sub Private Sub cmd2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd2.Click If inputStatus = False Then txtInput.Text += cmd2.Text Else txtInput.Text = cmd2.Text inputStatus = False End If End Sub Private Sub cmd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd1.Click If inputStatus = False Then txtInput.Text += cmd1.Text Else txtInput.Text = cmd1.Text inputStatus = False End If End Sub Private Sub cmd0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd0.Click If inputStatus = False Then If txtInput.Text.Length >= 1 Then txtInput.Text += cmd0.Text End If End If End Sub #End Region #Region "Tombol Operator" Private Sub cmdSqrRoot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSqrRoot.Click If txtInput.Text.Length <> 0 Then tmpValue = CDbl(txtInput.Text) tmpValue = System.Math.Sqrt(tmpValue) txtInput.Text = CStr(tmpValue) hasDecimal = False End If End Sub Private Sub cmdInverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInverse.Click If txtInput.Text.Length <> 0 Then tmpValue = CDbl(txtInput.Text) tmpValue = 1 / tmpValue txtInput.Text = CStr(tmpValue) hasDecimal = False End If End Sub Private Sub cmdSign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSign.Click If inputStatus = False Then If txtInput.Text.Length > 0 Then valHolder1 = -1 * CDbl(txtInput.Text) txtInput.Text = CStr(valHolder1) End If End If End Sub Private Sub cmdClearEntry_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClearEntry.Click txtInput.Text = String.Empty hasDecimal = False End Sub Private Sub cmdClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClearAll.Click txtInput.Text = String.Empty valHolder1 = 0 valHolder2 = 0 fungsihitung = String.Empty hasDecimal = False End Sub Private Sub cmdBackspace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBackspace.Click Dim str As String Dim loc As Integer If txtInput.Text.Length > 0 Then str = txtInput.Text.Chars(txtInput.Text.Length - 1) If str = "." Then hasDecimal = False End If loc = txtInput.Text.Length txtInput.Text = txtInput.Text.Remove(loc - 1, 1) End If End Sub Private Sub Hitung() valHolder2 = CDbl(txtInput.Text) Select Case fungsihitung Case "Tambah" valHolder1 = valHolder1 + valHolder2 Case "Kurang" valHolder1 = valHolder1 - valHolder2 Case "Bagi" valHolder1 = valHolder1 / valHolder2 Case "Kali" valHolder1 = valHolder1 * valHolder2 Case "Pangkat" valHolder1 = System.Math.Pow(valHolder1, valHolder2) End Select txtInput.Text = CStr(valHolder1) inputStatus = True End Sub Private Sub cmdbagi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdbagi.Click If txtInput.Text.Length <> 0 Then If fungsihitung = String.Empty Then valHolder1 = CDbl(txtInput.Text) txtInput.Text = String.Empty Else Hitung() End If fungsihitung = "Bagi" hasDecimal = False End If End Sub Private Sub cmdkali_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdkali.Click If txtInput.Text.Length <> 0 Then If fungsihitung = String.Empty Then valHolder1 = CDbl(txtInput.Text) txtInput.Text = String.Empty Else Hitung() End If fungsihitung = "Kali" hasDecimal = False End If End Sub Private Sub cmdkurang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdkurang.Click If txtInput.Text.Length <> 0 Then If fungsihitung = String.Empty Then valHolder1 = CDbl(txtInput.Text) txtInput.Text = String.Empty Else Hitung() End If fungsihitung = "Kurang" hasDecimal = False End If End Sub Private Sub CmdTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdTambah.Click If txtInput.Text.Length <> 0 Then If fungsihitung = String.Empty Then valHolder1 = CDbl(txtInput.Text) txtInput.Text = String.Empty Else Hitung() End If fungsihitung = "Tambah" hasDecimal = False End If End Sub Private Sub cmdSamadengan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSamadengan.Click If txtInput.Text.Length <> 0 AndAlso valHolder1 <> 0 Then Hitung() fungsihitung = "" hasDecimal = False End If End Sub Private Sub cmdpangkat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdpangkat.Click If txtInput.Text.Length <> 0 Then If fungsihitung = String.Empty Then valHolder1 = CDbl(txtInput.Text) txtInput.Text = String.Empty Else Hitung() End If fungsihitung = "Pangkat" hasDecimal = False End If End Sub Private Sub cmdtitik_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdtitik.Click If Not inputStatus Then If Not hasDecimal Then If txtInput.Text.Length > 1 Then If Not txtInput.Text = "0" Then txtInput.Text += cmdtitik.Text hasDecimal = True End If Else txtInput.Text = "0." End If End If End If End Sub #End Region End Class
Comments
Popular Posts
January 28, 2017
Pengenalan, Sejarah, dan Perkembangan aplikasi Adobe Illustrator
May 07, 2013
Apakah saya dapat menggunakan lebih dari satu domain dalam satu akun hosting?
Comments
Post a Comment