You are on page 1of 7

Syntak Program Untuk Tombol Standar Option Explicit Private hasil As Double Private Const opNol = 0 Private Const

opTambah = 1 Private Const opKurang = 2 ' untuk menghapus karakter terakhir Private Sub Hapus() Dim txt As String Dim min_len As Integer txt = txtdisplay.Text If Left$(txt, 1) = "-" Then min_len = 2 Else Private Sub Cmdbackspace_Click() Dim tanda As Integer If txtdisplay = "" Then txtdisplay.SetFocus Exit Sub End If ' hapus angka, hasil terakhir dan operator Private Sub Cmdclear_Click() cmdClearEntry_Click hasil = 0 Operator = opNol End Sub ' menambahkan koma (desimal) Private Sub Cmdkoma_Click() If InStr(txtdisplay.Text, ".") Then Beep Else If NilaiBaru Then txtdisplay.Text = "." ' Menghitung 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 Private Const opKali = 3 Private Const opBagi = 4 Private Operator As Integer Private NilaiBaru As Boolean 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 txtdisplay = Left(txtdisplay, Len(txtdisplay) - 1) If tanda > 0 Then tanda = 0 End If End Sub ' hapus angka Private Sub cmdClearEntry_Click() txtdisplay.Text = "" txtdisplay.SetFocus End Sub NilaiBaru = False Else txtdisplay.Text = txtdisplay.Text & "." End If End If End Sub

hasil = hasil * HasilBaru Case opBagi 'Tidak bisa dibagi nol 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

' menuliskan angka Private Sub cmdAngka_Click(Index As Integer) If NilaiBaru Then txtdisplay.Text = Format$(Index) NilaiBaru = False ' tombol tambah/kurang/bagi/kali Private Sub cmdOperator_Click(Index As Integer) Cmdsamadengan_Click ' merubah tanda +/Private Sub Cmdplusminus_Click() If NilaiBaru Then txtdisplay.Text = "-" ElseIf Left$(txtdisplay.Text, 1) = "-" Then ' filter untuk angka saja yg dapat diketikkan 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 ' supaya kursor tetap di kanan Private Sub txtDisplay_Change() txtdisplay.SelStart = Len(txtdisplay.Text) End Sub ' untuk mengetikkan angka di keyboard Private Sub txtDisplay_KeyPress(KeyAscii As Integer) Dim ch As String ch = Chr$(KeyAscii) Select Case ch Case "0" cmdAngka_Click 0 Case "1" cmdAngka_Click 1 Case "2" cmdAngka_Click 2 Case "3" cmdAngka_Click 3 Case "4" cmdAngka_Click 4 Case "5" cmdAngka_Click 5 Case "6" cmdAngka_Click 6 Case "7" cmdAngka_Click 7 ' untuk ketikan angka di numpad

Else txtdisplay.Text = _ txtdisplay.Text & Format$(Index) End If End Sub Operator = Index NilaiBaru = True End Sub txtdisplay.Text = Right$(txtdisplay.Text, 2) Else txtdisplay.Text = "-" & txtdisplay.Text End If End Sub End Sub Private Sub mnScientific_Click() Form1.Show End Sub Private Sub mnStandar_Click() standar.Show End Sub Private Sub txtDisplay_GotFocus() txtDisplay_Change End Sub Case "8" cmdAngka_Click 8 Case "9" cmdAngka_Click 9 Case "*", "x", "X" cmdOperator_Click opKali Case "+" cmdOperator_Click opTambah Case vbCrLf, vbCr, "=" Cmdsamadengan_Click Case "-" cmdOperator_Click opKurang Case "." Cmdkoma_Click Case "/" cmdOperator_Click opBagi Case "C", "c" cmdClearEntry_Click End Select KeyAscii = 0 End Sub Private Sub txtDisplay_KeyUp(KeyCode As Integer, Shift As Integer)

Select Case KeyCode Case vbKeyNumpad0 cmdAngka_Click 0 Case vbKeyNumpad1 cmdAngka_Click 1 Case vbKeyNumpad2 cmdAngka_Click 2 Case vbKeyNumpad3 cmdAngka_Click 3 Case vbKeyNumpad4 cmdAngka_Click 4 Case vbKeyNumpad5 cmdAngka_Click 5 Case vbKeyNumpad6 cmdAngka_Click 6 Case vbKeyNumpad7 cmdAngka_Click 7 Case vbKeyNumpad8 cmdAngka_Click 8 Case vbKeyNumpad9 cmdAngka_Click 9 Case vbKeyMultiply Syntax program Untuk Tombol Canggih Dim nilai1, nilai2, hasil As Double Dim tanda, unik As Integer Private Sub cmdangka0_Click() 'Tombol angka 0. txtinput.Text = txtinput.Text & "0" If tanda > 0 Then Private Sub cmdangka1_Click() 'Tombol angka 1. txtinput.Text = txtinput.Text & "1" If tanda > 0 Then Private Sub cmdangka2_Click() 'Tombol angka 2. txtinput.Text = txtinput.Text & "2" If tanda > 0 Then txthasil.Text = txthasil.Text & "2" End If End Sub Private Sub Cmdangka4_Click() 'TOMBOL ANGKA 4 txtinput.Text = txtinput.Text & "4" If tanda > 0 Then Private Sub Cmdangka5_Click() 'TOMBOL ANGKA 5 txtinput.Text = txtinput.Text & "5" If tanda > 0 Then

cmdOperator_Click opKali Case vbKeyAdd cmdOperator_Click opTambah Case vbKeySeparator Cmdsamadengan_Click Case vbKeySubtract cmdOperator_Click opKurang Case vbKeyDivide cmdOperator_Click opBagi Case vbKeyDecimal Cmdkoma_Click Case vbKeyBack, vbKeyDelete Hapus End Select KeyCode = 0 End Sub Private Sub Form_Activate() txtdisplay.Alignment = 1 txtdisplay.MaxLength = 12 standar.WindowState = 2 End Sub

txthasil.Text = txthasil.Text & "0" End If End Sub txthasil.Text = txthasil.Text & "1" End If End Sub Private Sub Cmdangka3_Click() 'TOMBOL ANGKA 3 txtinput.Text = txtinput.Text & "3" If tanda > 0 Then txthasil.Text = txthasil.Text & "3" End If End Sub txthasil.Text = txthasil.Text & "4" End If End Sub txthasil.Text = txthasil.Text & "5" End If End Sub

Private Sub Cmdangka6_Click() 'TOMBOL ANGKA 6 txtinput.Text = txtinput.Text & "6" If tanda > 0 Then Private Sub Cmdangka7_Click() 'TOMBOL ANGKA 7 txtinput.Text = txtinput.Text & "7" If tanda > 0 Then Private Sub Cmdangka8_Click() 'TOMBOL ANGKA 8 txtinput.Text = txtinput.Text & "8" If tanda > 0 Then Private Sub Cmdangka9_Click() 'TOMBOL ANGKA 9 txtinput.Text = txtinput.Text & "9" If tanda > 0 Then Private Sub Cmdtambah_Click() 'Tombol TAMBAH If tanda = 50 Then txtinput.Text = hasil nilai1 = txthasil.Text tanda = 1 txtinput.Text = txtinput.Text & "+" Private Sub Cmdkurang_Click() 'Tombol KURANG If tanda = 50 Then txtinput.Text = hasil nilai1 = txthasil.Text tanda = 2 txtinput.Text = txtinput.Text & "-" Private Sub Cmdkali_Click() 'TOMBOL KALI If tanda = 50 Then txtinput.Text = hasil nilai1 = txthasil.Text tanda = 3 txtinput.Text = txtinput.Text & "x" Private Sub Cmdbagi_Click() 'TOMBOL BAGI If tanda = 50 Then txtinput.Text = hasil nilai1 = txthasil.Text tanda = 4 txtinput.Text = txtinput.Text & "/" Private Sub Cmdsin_Click() 'TOMBOL SINUS txtinput.Text = "" tanda = 8

txthasil.Text = txthasil.Text & "6" End If End Sub txthasil.Text = txthasil.Text & "7" End If End Sub txthasil.Text = txthasil.Text & "8" End If End Sub txthasil.Text = txthasil.Text & "9" End If End Sub Exit Sub End If nilai1 = txtinput.Text tanda = 1 txtinput.Text = txtinput.Text & "+" End Sub Exit Sub End If nilai1 = txtinput.Text tanda = 2 txtinput.Text = txtinput.Text & "-" End Sub Exit Sub End If nilai1 = txtinput.Text tanda = 3 txtinput.Text = txtinput.Text & "x" End Sub Exit Sub End If nilai1 = txtinput.Text tanda = 4 txtinput.Text = txtinput.Text & "/" End Sub txtinput.Text = txtinput.Text & "sin" End Sub

Private Sub Cmdcos_Click() 'TOMBOL COSINUS txtinput.Text = "" Private Sub Cmdtan_Click() 'TOMBOL TANGEN txtinput.Text = "" Private Sub Cmdakar_Click() 'TOMBOL AKAR tanda = 11 txtinput.Text = txtinput.Text & "sqr" End Sub Private Sub Cmdplusminus_Click() 'Tombol bentuk positif / negatif If tanda > 0 Then Private Sub Cmdkoma_Click() 'Tombol bentuk DESIMAL txtinput.Text = txtinput.Text & "." Private Sub Cmdkuadrat_Click() 'TOMBOL KUADRAT If tanda = 50 Then txtinput.Text = hasil nilai1 = txthasil.Text tanda = 5 txtinput.Text = txtinput.Text & "^2" Private Sub Cmdpangkat_Click() 'TOMBOL PANGKAT n If tanda = 50 Then txtinput.Text = hasil nilai1 = txthasil.Text tanda = 6 txtinput.Text = txtinput.Text & "^" Private Sub Cmdsamadengan_Click() 'TOMBOL SAMA DENGAN nilai2 = txthasil.Text If unik = 1 Then nilai2 = nilai2 * -1 End If Select Case tanda Case 1 hasil = (nilai1 - 1) + (nilai2 + 1) 'PENJUMLAHAN Case 2 hasil = nilai1 - nilai2 'PENGURANGAN Case 3 hasil = nilai1 * nilai2 'PERKALIAN Case 4 If nilai2 = 0 Then MsgBox " TERJADI ERROR, PEMBAGIAN DENGAN O ", vbCritical, "Error" txtinput.Text = "" Exit Sub

tanda = 9 txtinput.Text = txtinput.Text & "cos" End Sub tanda = 10 txtinput.Text = txtinput.Text & "tan" End Sub txtinput.Text = txtinput.Text & "-" unik = 1 'VARIABLE unik 1 UNTUK bentuk negatif Exit Sub End If txtinput.Text = txtinput.Text * -1 End Sub unik = 2 'VARIABLE unik 2 UNTUK DESIMAL End Sub Exit Sub End If nilai1 = txtinput.Text tanda = 5 txtinput.Text = txtinput.Text & "^2" End Sub Exit Sub End If nilai1 = txtinput.Text tanda = 6 txtinput.Text = txtinput.Text & "^" End Sub End If hasil = nilai1 / nilai2 'PEMBAGIAN Case 5 hasil = nilai1 * nilai1 'KUADRAT Case 6 hasil = nilai1 ^ nilai2 'PANGKAT n Case 7 hasil = nilai2 Case 8 hasil = Sin(CDbl(nilai2)) Case 9 hasil = Cos(CDbl(nilai2)) Case 10 hasil = Tan(CDbl(nilai2)) Case 11 If nilai2 < 0 Then MsgBox "TIDAK DAPAT MENGHITUNG NILAI AKAR DARI BILANGAN NEGATIF ", vbInformation, "PEMBERITAHUAN ERROR" Exit Sub

End If hasil = Sqr(nilai2) End Select If unik = 2 Then hasil = hasil * 0.1 Private Sub Cmdclear_Click() 'TOMBOL CLEAR tanda = 0 txtinput.Text = "" txthasil.Text = "" End Sub Private Sub Command25_Click() 'TOMBOL FAKTORIAL txtinput.Text = hasil nilai1 = txtinput.Text tanda = 7 txtinput.Text = txtinput.Text & "!" Private Sub Cmdbackspace_Click() 'TOMBOL BACKSPACE If txtinput.Text = "" Then txthasil.SetFocus Exit Sub End If Private Sub Form_Load() 'SAAT FORM LOAD txtinput.Enabled = False Syntax Menu About Private Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" (ByVal hwnd As Long, _ ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long Const SW_SHOWNORMAL = 1 'Konstanta untuk menampilkan jendela normal Private Sub Form_Load() 'Tampilkan nama untuk setiap label about.WindowState = 2 Label7.Caption = "-->Kembali" lblemail.Caption = "agung_baitul_hikmah@yahoo.com" 'Email lblemail.Font.Underline = True lblemail.ForeColor = vbBlue 'Warna link mula-mula biru lblsitus.Caption = "http://agungbsi.tk" 'Situs lbldownload.Caption = "" 'Download lblsitus.Font.Underline = True

End If tanda = 50 txthasil.Text = "" txthasil.Text = hasil End Sub Private Sub Cmdpersen_Click() 'TOMBOL PERSEN txthasil.Text = txthasil.Text * 0.01 txtinput.Text = txtinput.Text & "%" End Sub For a = nilai1 - 1 To 1 Step -1 nilai1 = nilai1 * a Next a txthasil.Text = nilai1 End Sub txtinput.Text = Left(txtinput.Text, Len(txtinput.Text) - 1) If tanda > 0 Then tanda = 0 End If End Sub tanda = 0 End Sub lblsitus.ForeColor = vbBlue 'Warna link mulamula biru End Sub Private Sub lbldownload_Click() Dim download As Long 'Tampilkan program default untuk membuka situs ke alamat lblSitus download = ShellExecute(0, vbNullString, _ lbldownload, "", "", vbNormalFocus) lbldownload.ForeColor = &H8000& 'Setelah diklik, berubah warna End Sub Private Sub lblEmail_Click() Dim email As Long 'Tampilkan program default untuk mengirim email ke alamat lblEmail email = ShellExecute(0, vbNullString, _ "mailto:" & lblemail, "", "", vbNormalFocus) lblemail.ForeColor = &H8000& 'Setelah diklik, berubah warna End Sub

Private Sub lblSitus_Click() Dim situs As Long 'Tampilkan program default untuk membuka situs ke alamat lblSitus situs = ShellExecute(0, vbNullString, _ lblsitus, "", "", vbNormalFocus) lblsitus.ForeColor = &H8000& 'Setelah diklik, berubah warna End Sub Private Sub Label7_Click() Unload Me End Sub Private Sub Timer1_Timer() 'tulisan berkedip berwarna

If Label7.ForeColor = vbGreen Then Label7.ForeColor = vbRed Else Label7.ForeColor = vbGreen End If 'tulisan berjalan 'Label6 = Right(Label6, Len(Label6) - 1) + Left(Label6, 1) 'tulisan berkedip disembunyikan If Label1.Visible = True Then Label1.Visible = False Else Label1.Visible = True End If End Sub

Tampilan Calculator Standar

Tampilan Calculator Sin/ Cos

You might also like