Disney fairies

Disney fairies

Selasa, 21 Desember 2010

Program Kalkulator Sederhana



1.    PADA LABEL KALKULATOR

Private Sub Label3_Click()
Label3.BackColor = purple
End Sub

Private Sub Timer1_Timer()
Label2.BackColor = RGB((Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
End Sub

Private Sub Timer2_Timer()
Label3.Left = Val(Label3.Left) - 20
If Val(Label3.Left) < -7000 Then Label3.Left = 70

End Sub

Private Sub txtDisplay_Change()
txtDisplay.SelStart = Len(txtDisplay.Text)
End Sub
Private Sub txtDisplay_GotFocus()
txtDisplay_Change
End Sub
2.    PADA TOMBOL ANGKA

Private Hasil As Double
Private Const opNol = 0
Private Const opTambah = 1
Private Const opKurang = 2
Private Const opKali = 3
Private Const opBagi = 4
Private Operator As Integer
Private NilaiBaru As Boolean

Private Sub Hapus()
Dim txt As String
Dim min_len As Integer
txt = txtDisplay.Text
If Left$(txt, 1) = "-" Then
min_len = 2
Else
min_len = 1
End If
If Len(txt) > min_len Then
txtDisplay.Text = Left$(txt, Len(txt) - 1)
Else
txtDisplay.Text = "0?"
End If
End Sub

Private Sub cmdAngka_Click(Index As Integer)
If NilaiBaru Then
txtDisplay.Text = Format$(Index)
NilaiBaru = False
Else
txtDisplay.Text = _
txtDisplay.Text & Format$(Index)
End If
End Sub

Private Sub cmdClear_Click()
cmdClearEntry_Click
Hasil = 0
Operator = opNol

End Sub

Private Sub cmdClearEntry_Click()
txtDisplay.Text = ""
End Sub

Private Sub cmdKoma_Click()
If InStr(txtDisplay.Text, ".") Then
Beep
Else
If NilaiBaru Then
txtDisplay.Text = "."
NilaiBaru = False
Else
txtDisplay.Text = txtDisplay.Text & "."
End If
End If

End Sub

Private Sub cmdOperator_Click(Index As Integer)
cmdSamaDengan_Click
Operator = Index
NilaiBaru = True

End Sub

Private Sub cmdPlusMinus_Click()
If NilaiBaru Then
txtDisplay.Text = "-"
ElseIf Left$(txtDisplay.Text, 1) = "-" Then
txtDisplay.Text = Right$(txtDisplay.Text, 2)
Else
txtDisplay.Text = "-" & txtDisplay.Text
End If

End Sub

Private Sub cmdSamaDengan_Click()
Dim HasilBaru As Double
If txtDisplay.Text = "" Then
HasilBaru = 0
Else
HasilBaru = CDbl(txtDisplay.Text)
End If
Select Case Operator
Case opNol
Hasil = HasilBaru
Case opTambah
Hasil = Hasil + HasilBaru
Case opKurang
Hasil = Hasil - HasilBaru
Case opKali
Hasil = Hasil * HasilBaru
Case opBagi

If HasilBaru = 0 Then
MsgBox "Tidak bisa dibagi 0?", vbOKOnly + vbCritical, "Kalku ERROR"
Call cmdClear_Click
Else
Hasil = Hasil / HasilBaru
End If
End Select
Operator = opNol
NilaiBaru = True
txtDisplay.Text = Format$(Hasil)

End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
txtDisplay_KeyPress KeyAscii
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
txtDisplay_KeyUp KeyCode, Shift
End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label3_Click()
Label3.BackColor = purple
End Sub

Private Sub Timer1_Timer()
Label2.BackColor = RGB((Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
End Sub

Private Sub Timer2_Timer()
Label3.Left = Val(Label3.Left) - 20
If Val(Label3.Left) < -7000 Then Label3.Left = 70

End Sub

Private Sub txtDisplay_Change()
txtDisplay.SelStart = Len(txtDisplay.Text)
End Sub
Private Sub txtDisplay_GotFocus()
txtDisplay_Change
End Sub

3.    UNTUK MASING _ MASING PENJUMLAHAN

Private Hasil As Double
Private Const opNol = 0
Private Const opTambah = 1
Private Const opKurang = 2
Private Const opKali = 3
Private Const opBagi = 4
Private Operator As Integer
Private NilaiBaru As Boolean

Private Sub Hapus()
Dim txt As String
Dim min_len As Integer
txt = txtDisplay.Text
If Left$(txt, 1) = "-" Then
min_len = 2
Else
min_len = 1
End If
If Len(txt) > min_len Then
txtDisplay.Text = Left$(txt, Len(txt) - 1)
Else
txtDisplay.Text = "0?"
End If
End Sub

Private Sub cmdAngka_Click(Index As Integer)
If NilaiBaru Then
txtDisplay.Text = Format$(Index)
NilaiBaru = False
Else
txtDisplay.Text = _
txtDisplay.Text & Format$(Index)
End If
End Sub

Private Sub cmdClear_Click()
cmdClearEntry_Click
Hasil = 0
Operator = opNol

End Sub

Private Sub cmdClearEntry_Click()
txtDisplay.Text = ""
End Sub

Private Sub cmdKoma_Click()
If InStr(txtDisplay.Text, ".") Then
Beep
Else
If NilaiBaru Then
txtDisplay.Text = "."
NilaiBaru = False
Else
txtDisplay.Text = txtDisplay.Text & "."
End If
End If

End Sub

Private Sub cmdOperator_Click(Index As Integer)
cmdSamaDengan_Click
Operator = Index
NilaiBaru = True

End Sub

Private Sub cmdPlusMinus_Click()
If NilaiBaru Then
txtDisplay.Text = "-"
ElseIf Left$(txtDisplay.Text, 1) = "-" Then
txtDisplay.Text = Right$(txtDisplay.Text, 2)
Else
txtDisplay.Text = "-" & txtDisplay.Text
End If

End Sub

Private Sub cmdSamaDengan_Click()
Dim HasilBaru As Double
If txtDisplay.Text = "" Then
HasilBaru = 0
Else
HasilBaru = CDbl(txtDisplay.Text)
End If
Select Case Operator
Case opNol
Hasil = HasilBaru
Case opTambah
Hasil = Hasil + HasilBaru
Case opKurang
Hasil = Hasil - HasilBaru
Case opKali
Hasil = Hasil * HasilBaru
Case opBagi

If HasilBaru = 0 Then
MsgBox "Tidak bisa dibagi 0?", vbOKOnly + vbCritical, "Kalku ERROR"
Call cmdClear_Click
Else
Hasil = Hasil / HasilBaru
End If
End Select
Operator = opNol
NilaiBaru = True
txtDisplay.Text = Format$(Hasil)

End Sub

Private Sub Command1_Click()
End
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
txtDisplay_KeyPress KeyAscii
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
txtDisplay_KeyUp KeyCode, Shift
End Sub

Private Sub Label1_Click()

End Sub

Private Sub Label3_Click()
Label3.BackColor = purple
End Sub

Private Sub Timer1_Timer()
Label2.BackColor = RGB((Rnd * 255), Int(Rnd * 255), Int(Rnd * 255))
End Sub

Private Sub Timer2_Timer()
Label3.Left = Val(Label3.Left) - 20
If Val(Label3.Left) < -7000 Then Label3.Left = 70

End Sub

Private Sub txtDisplay_Change()
txtDisplay.SelStart = Len(txtDisplay.Text)
End Sub
Private Sub txtDisplay_GotFocus()
txtDisplay_Change
End Sub
SELAMAT MENCOBA YuAH..............

 (^_^).... yipIIIYipPiii....



Tidak ada komentar:

Posting Komentar