Kali ini saya akan memberikan tutorial tentang pembuatan aplikasi sederhana Kalkulator dengan VB.NET, dan sebenarnya sehubungan dengan tugas kuliah juga button, dan radio , sehingga ada ide untuk membuat aplikasi sederhana ini.
Public Class Kalkulator
Dim k1, k2, Total As Double
Dim opera As String
Dim pindah As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "1"
Else
TextBox1.Text = TextBox1.Text + "1"
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "2"
Else
TextBox1.Text = TextBox1.Text + "2"
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "3"
Else
TextBox1.Text = TextBox1.Text + "3"
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "4"
Else
TextBox1.Text = TextBox1.Text + "4"
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "5"
Else
TextBox1.Text = TextBox1.Text + "5"
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "6"
Else
TextBox1.Text = TextBox1.Text + "6"
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "7"
Else
TextBox1.Text = TextBox1.Text + "7"
End If
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "8"
Else
TextBox1.Text = TextBox1.Text + "8"
End If
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "9"
Else
TextBox1.Text = TextBox1.Text + "9"
End If
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "0"
Else
TextBox1.Text = TextBox1.Text + "0"
End If
End Sub
Private Sub ButtonSamaDengan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSamaDengan.Click
If opera = "+" Then
Total = Val(TextBox1.Text) + Val(TextBox2.Text)
MsgBox(Total)
Label1.Text = Total
TextBox1.Text = Total
TextBox2.Text = ""
ElseIf opera = "-" Then
Total = Val(TextBox1.Text) - Val(TextBox2.Text)
MsgBox(Total)
Label1.Text = Total
TextBox1.Text = Total
TextBox2.Text = ""
ElseIf opera = "*" Then
Total = Val(TextBox1.Text) * Val(TextBox2.Text)
MsgBox(Total)
Label1.Text = Total
TextBox1.Text = Total
TextBox2.Text = ""
ElseIf opera = "/" Then
Total = Val(TextBox1.Text) / Val(TextBox2.Text)
MsgBox(Total)
Label1.Text = Total
TextBox1.Text = Total
TextBox2.Text = ""
End If
End Sub
Private Sub Button1Plus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1Plus.Click
opera = "+"
pindah = True
TextBox2.Focus()
End Sub
Private Sub ButtonKali_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonKali.Click
opera = "*"
pindah = True
TextBox2.Focus()
End Sub
Private Sub ButtonMin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonMin.Click
opera = "-"
pindah = True
TextBox2.Focus()
End Sub
Private Sub Kalkulator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PictureBox1.Image = System.Drawing.Image.FromFile("C:\Users\Muhamad Anjar\Documents\Visual Studio 2010\Projects\WindowsApplication1\WindowsApplication1\anjar software.jpg")
TextBox3.Text = 0
End Sub
Private Sub ButtonBagi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonBagi.Click
opera = "/"
pindah = True
TextBox2.Focus()
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
If pindah = True Then
TextBox2.Text = TextBox2.Text + "."
Else
TextBox1.Text = TextBox1.Text + "."
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
pindah = False
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox4.Text = (TextBox3.Text * 18 / 10) + 32
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox4.Text = (TextBox3.Text * 8 / 10)
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox4.Text = (TextBox3.Text + 27315 / 1000)
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
TextBox4.Text = (TextBox3.Text * 18 / 10) + 32
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
TextBox4.Text = (TextBox3.Text * 8 / 10)
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
TextBox4.Text = (TextBox3.Text + 27315 / 1000)
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
End Sub
End Class
0 komentar:
Posting Komentar