Pages

Selasa, 19 Mei 2009

BIKIN KALKULATOR DI VISUAL BASIC-MU!!!

Nah.... yang ini ni, salah satu tugas VBquw semester kemarin...Bikin simple calculator...
Mmmm, muga bermanfaat yaah... ^__^

Public Class Form1
Dim DATA1 As Double
Dim DATA2 As Double
Dim TANDA As String
Dim STATUS As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BOX.Text = "0"
STATUS = True
End Sub

Private Sub BTN_1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_1.Click
If STATUS = True Then
BOX.Text = "1"
STATUS = False
Else
BOX.Text = BOX.Text & 1
End If
End Sub

Private Sub BTN_2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_2.Click
If STATUS = True Then
BOX.Text = "2"
STATUS = False
Else
BOX.Text = BOX.Text & 2
End If
End Sub

Private Sub BTN_3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_3.Click
If STATUS = True Then
BOX.Text = "3"
STATUS = False
Else
BOX.Text = BOX.Text & 3
End If
End Sub

Private Sub BTN_4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_4.Click
If STATUS = True Then
BOX.Text = "4"
STATUS = False
Else
BOX.Text = BOX.Text & 4
End If
End Sub

Private Sub BTN_5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_5.Click
If STATUS = True Then
BOX.Text = "5"
STATUS = False
Else
BOX.Text = BOX.Text & 5
End If
End Sub

Private Sub BTN_6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_6.Click
If STATUS = True Then
BOX.Text = "6"
STATUS = False
Else
BOX.Text = BOX.Text & 6
End If
End Sub

Private Sub BTN_7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_7.Click
If STATUS = True Then
BOX.Text = "7"
STATUS = False
Else
BOX.Text = BOX.Text & 7
End If
End Sub

Private Sub BTN_8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_8.Click
If STATUS = True Then
BOX.Text = "8"
STATUS = False
Else
BOX.Text = BOX.Text & 8
End If
End Sub

Private Sub BTN_9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_9.Click
If STATUS = True Then
BOX.Text = "9"
STATUS = False
Else
BOX.Text = BOX.Text & 9
End If
End Sub

Private Sub BTN_0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_0.Click
If STATUS = True Then
BOX.Text = "0"
STATUS = False
Else
BOX.Text = BOX.Text & 0
End If
End Sub

Private Sub BTN_KOMA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_KOMA.Click
If Not BOX.Text.Contains(".") Then
BOX.Text = BOX.Text & "."
Else
Beep()
End If
End Sub

Private Sub BTN_KALI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_KALI.Click
If BOX.Text.Length <> 0 Then
If TANDA = "" Then
DATA1 = Val(BOX.Text)
STATUS = True
Else
If STATUS = False Then
calculate()
STATUS = True
End If
End If
End If
TANDA = "*"
End Sub

Private Sub BTN_BAGI_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_BAGI.Click

If BOX.Text.Length <> 0 Then
If TANDA = "" Then
DATA1 = Val(BOX.Text)
STATUS = True
Else
If STATUS = False Then
calculate()
STATUS = True
End If
End If
End If
TANDA = "/"
End Sub

Private Sub BTN_TAMBAH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_TAMBAH.Click
If BOX.Text.Length <> 0 Then
If TANDA = "" Then
DATA1 = Val(BOX.Text)
STATUS = True
Else
If STATUS = False Then
calculate()
STATUS = True
End If
End If
End If
TANDA = "+"
End Sub

Private Sub BTN_KURANG_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_KURANG.Click
If BOX.Text.Length <> 0 Then
If TANDA = "" Then
DATA1 = Val(BOX.Text)
STATUS = True
Else
If STATUS = False Then
calculate()
STATUS = True
End If
End If
End If
TANDA = "-"
End Sub

Private Sub BTN_PROSES_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_PROSES.Click
If BOX.Text.Length <> 0 Then
If DATA1 <> 0 Then
calculate()
TANDA = ""
End If
End If
End Sub

Private Sub BTN_C_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_C.Click
BOX.Text = "0"
status = True
TANDA = ""
End Sub

Private Sub BTN_EXIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_EXIT.Click
Me.Close()
End Sub

Private Sub BTN_DEL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_DEL.Click
Dim A As String
A = BOX.Text
If Len(A) > 1 Then
BOX.Text = A.Substring(0, A.Length - 1)
Else
BOX.Text = "0"
STATUS = True
End If
End Sub

Private Sub BTN_PLUSMIN_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTN_PLUSMIN.Click
Dim ISIBOX As Integer
ISIBOX = CInt(CDbl(BOX.Text) * -1)
BOX.Text = CStr(ISIBOX)
'DATA1 = BOX.Text
End Sub
Public Sub calculate()
DATA2 = Val(BOX.Text)
Try
If TANDA = "/" Then
STATUS = True
If DATA2 <> 0 Then
DATA1 = DATA1 / DATA2
Else
MessageBox.Show("Pembagian dengan 0", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
ElseIf TANDA = "*" Then
DATA1 = DATA1 * DATA2
ElseIf TANDA = "+" Then
DATA1 = DATA1 + DATA2
ElseIf TANDA = "-" Then
DATA1 = DATA1 - DATA2
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
BOX.Text = "ERROR"
End Try
BOX.Text = CStr(DATA1)
STATUS = True
End Sub
End Class

0 komentar:

Posting Komentar

 

UM Bloggers


Universitas Negeri Malang

Sample Text

Starting Point...

Bila aku harus mengulangi hidup ini, aku akan membuat kesalahan-kesalahan yang sama, tetapi aku pastikan bahwa aku menemukan kesalahan-kesalahan itu jauh lebih awal. Sehingga keberhasilan akan datang lebih awal menjemput dan meng'elukanku.
Aku tidak tahu takdirku, tetapi aku tahu hakku untuk berhasil.