Senin, 03 Agustus 2020


CODING PEMBUATAN KALKULATOR VISUAL BASIC :

Option Explicit
Dim op1 As Double, op2 As Double, s As Integer, p As Integer, operator As String, eq As Integer

Private Sub abt_Click()
frmAbout.Show
End Sub

Private Sub exit_Click()
End
End Sub

Private Sub Form_Load()
Text1.Text = ""
p = 1
eq = 1
txtpint = "y"
s = 1
End Sub

Private Sub Image2_Click(Index As Integer)
If Index = 0 Then
'MsgBox txtpint.Text & eq
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & Index + 1
End If
End If

If Index = 1 Then
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & Index + 1
End If
End If

If Index = 2 Then
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & Index + 1
End If
End If

If Index = 3 Then
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & Index + 1
End If
End If

If Index = 4 Then
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & Index + 1
End If
End If

If Index = 5 Then
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & Index + 1
End If
End If

If Index = 6 Then
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & Index + 1
End If
End If

If Index = 7 Then
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & Index + 1
End If
End If

If Index = 8 Then
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & Index + 1
End If
End If

If Index = 9 Then
If txtpint = "y" And s = 0 Then
Call equal(Index)
txtpint.Text = "n"
Else
If Text1.Text Like ("0.*") Or s = 1 Or Val(Text1.Text) > 0 Then
Text1.Text = Text1.Text & "0"
s = 0
End If
End If
End If

If Index = 10 Then
If txtpint = "y" Then
Call equal(Index)
Else
Text1.Text = Text1.Text & "00"
End If
End If
End Sub

Public Sub proc()
If (Not IsNumeric(Text1.Text)) Then
MsgBox "Invalid value", 16, "Error"
Else
op1 = CDbl(Text1.Text)
Text1.Text = ""
End If
End Sub


Private Sub Image3_Click(sindex As Integer)
Call enable
If sindex = 0 Then
Call proc
operator = "+"
End If

If sindex = 1 Then
Call proc
operator = "-"
End If

If sindex = 2 Then
Call proc
operator = "*"
End If

If sindex = 3 Then
Call proc
operator = "/"
End If

If sindex = 4 Then
Call proc
Text1.Text = Sin(op1 * ((22 / 7) / 180))
txtpint.Text = "y"
eq = 0
'MsgBox txtpint.Text
End If

If sindex = 5 Then
Call proc
If op1 = "90" Then
Text1.Text = "0"
Else
Text1.Text = Cos(op1 * ((22 / 7) / 180))
End If
txtpint.Text = "y"
eq = 0
End If

If sindex = 6 Then
Call proc
If op1 = "90" Then
Text1.Text = "Invalid input or function"
Else
Text1.Text = Tan(op1 * ((22 / 7) / 180))
End If
txtpint.Text = "y"
eq = 0
End If

If sindex = 7 Then
Call proc
Text1.Text = Log(op1) / 2.30258509299405
txtpint.Text = "y"
eq = 0
End If

If sindex = 8 Then
Call proc
If (op1 < 0) Then
MsgBox "Akar Tidak terdefinisi", vbExclamation, "Error"
Else
Text1.Text = Sqr(op1)
End If
txtpint.Text = "y"
eq = 0
End If

If sindex = 9 Then
Call proc
If (op1 = 0) Then
MsgBox "Hasilnya 0!", 16, "Error"
Else
Text1.Text = 1 / op1
End If
txtpint.Text = "y"
eq = 0
End If

If sindex = 10 Then
If Text1.Text <> "" And Text1.Text <> "0" And eq <> 0 Then
MsgBox "Pertama"
Text1.Text = Text1.Text & "."
Image3(10).Enabled = False
End If
If txtpint = "y" And Text1.Text = "" And p = 1 Then
s = 1
Text1.Text = 0 & "."
Image3(10).Enabled = False
Else
If eq = 1 Then
If Text1.Text = "0" Then
Text1.Text = 0 & "."
Image3(10).Enabled = False
End If
End If
End If
End If

If sindex = 11 Then
s = 0
p = 1
Image3(10).Enabled = True
On Error Resume Next
Dim i, result, a, ans As Double
result = 1
op2 = Text1.Text
If (Not IsNumeric(Text1.Text)) Then
MsgBox "Nilai Invalid", 16, "Error"
Else
Select Case operator
Case "+"
ans = op1 + op2
Text1.Text = ans
Case "-"
ans = op1 - op2
Text1.Text = ans
Case "*"
ans = op1 * op2
Text1.Text = ans
Case "/"
ans = op1 / op2
Text1.Text = ans
Case "^"
For i = 1 To op2 Step 1
result = op1 * result
Next
Text1.Text = result
End Select
eq = 0
txtpint = "y"
'MsgBox " eq = " & eq & " s= " & s & "txtpint.text= " & txtpint.Text
End If
End If

If sindex = 12 Then
Image3(13).Enabled = True
Image3(14).Enabled = True
lblmem.Enabled = True
lblmem.Caption = " M"
lblmem.BackColor = &HD2EAF0
If Trim(Val(txtmem.Text)) = "" Then
txtmem.Text = Val(Text1.Text)
Else
txtmem.Text = Val(txtmem.Text) + Val(Text1.Text)
End If
txtpint.Text = "y"
eq = 0
End If

If sindex = 13 Then
Text1.Text = Val(txtmem.Text)
End If

If sindex = 14 Then
lblmem.Enabled = False
Image3(13).Enabled = False
Image3(14).Enabled = False
txtmem.Text = ""
lblmem.Caption = ""
lblmem.BackColor = vbWhite
End If

If sindex = 15 Then
On Error Resume Next
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
If Text1.Text = "" Then
Image3(15).Enabled = False
End If
End If

If sindex = 16 Then
Call proc
operator = "^"
End If

If sindex = 17 Then
Text1.Text = ""
eq = 1
txtpint = "y"
s = 1
End If

If sindex = 18 Then
End
End If

If sindex = 19 Then
If Not (Text1.Text = "") And Not (Val(Text1.Text) = 0) Then
Text1.Text = -Val(Text1.Text)
End If
End If


End Sub

Private Sub enable()
Image3(10).Enabled = True
End Sub

Private Sub equal(andex)
Dim p As Integer

Select Case andex
Case 0
If eq = 0 Then
Call qe(andex)
Else
If s = 1 Or Not (Text1.Text) = "" Then
Text1.Text = Text1.Text & "1"
Else
If s = 0 Then
Text1.Text = "1"
Call pint
End If
End If
End If

Case 1

If eq = 0 Then
Call qe(andex)
Else
If s = 1 Or Not (Text1.Text) = "" Then
Text1.Text = Text1.Text + "2"
Else
If s = 0 Then
Text1.Text = "2"
Call pint
End If
End If
End If

Case 2

If eq = 0 Then
Call qe(andex)
Else
If s = 1 Or Not (Text1.Text) = "" Then
Text1.Text = Text1.Text + "3"
Else
If s = 0 Then
Text1.Text = "3"
Call pint
End If
End If
End If

Case 3

If eq = 0 Then
Call qe(andex)
Else
If s = 1 Or Not (Text1.Text) = "" Then
Text1.Text = Text1.Text + "4"
Else
If s = 0 Then
Text1.Text = "4"
Call pint
End If
End If
End If

Case 4

If eq = 0 Then
Call qe(andex)
Else
If s = 1 Or Not (Text1.Text) = "" Then
Text1.Text = Text1.Text + "5"
Else
If s = 0 Then
Text1.Text = "5"
Call pint
End If
End If
End If

Case 5

If eq = 0 Then
Call qe(andex)
Else
If s = 1 Or Not (Text1.Text) = "" Then
Text1.Text = Text1.Text + "6"
Else
If s = 0 Then
Text1.Text = "6"
Call pint
End If
End If
End If

Case 6

If eq = 0 Then
Call qe(andex)
Else
If s = 1 Or Not (Text1.Text) = "" Then
Text1.Text = Text1.Text + "7"
Else
If s = 0 Then
Text1.Text = "7"
Call pint
End If
End If
End If

Case 7

If eq = 0 Then
Call qe(andex)
Else
If s = 1 Or Not (Text1.Text) = "" Then
Text1.Text = Text1.Text + "8"
Else
If s = 0 Then
Text1.Text = "8"
Call pint
End If
End If
End If

Case 8

If eq = 0 Then
Call qe(andex)
Else
If s = 1 Or Not (Text1.Text) = "" Then
Text1.Text = Text1.Text + "9"
Else
If s = 0 Then
Text1.Text = "9"
Call pint
End If
End If
End If

Case 9
If eq = 0 Then
Call qe(andex)
Else
's=0 And Not (eq = 0)
If Not (Text1.Text) = "0" And Not (Text1.Text) = "" Then
Text1.Text = Text1.Text & "0"
txtpint = "y"
Call pint
Else
If s = 0 Or eq = 0 Then
Text1.Text = "0"
txtpint = "y"
End If
End If
End If


Case 10
If s = 0 And (Not (Text1.Text) = "") And eq = 1 Then
Text1.Text = Text1.Text & "00"
Else
If Trim(Text1.Text) = "" Then
txtpint.Text = "y"
End If
End If
End Select
s = 0
End Sub

Private Sub Image4_Click(dex As Integer)
If dex = 0 Then
calci.WindowState = 1
Else
If dex = 1 Then
End
End If
End If
End Sub

Private Sub pint()
If txtpint = "y" Then
If s = 0 Then
txtpint = "n"
Else
txtpint = "y"
End If
End If
End Sub
Private Sub qe(andex)
If eq = 0 Then
If Not (Text1.Text) = "" And s = 1 Then
Text1.Text = Text1.Text & andex
Else
If s = 0 And eq = 0 And txtpint.Text = "y" And andex = 9 Then
Text1.Text = 0
Else
Text1.Text = andex + 1
eq = 1
txtpint.Text = "y"
s = 0
End If
End If
End If
End Sub

Private Sub onlyz(andex)
If Text1.Text = "0" Then
Text1.Text = andex + 1
End If
Exit Sub
End Sub

PROSES KERJA KALKULATOR VISUAL BASIC :


PROSES KERJA VIDEO  KALKULATOR VISUAL BASIC :




~ SELESAI ~

Tidak ada komentar:

Posting Komentar