Program kalkkulator ini saya buat karna ada tugas mata kuliah interaksi manusia dengan komputer mengenai desain sebuah program. Program ini bukan full buatan saya, saya hanya mengedit program yang sudah jadi menjadi lebih sempurna lagi. Tanpa banyak basa-basi saya akan segera menuliskan kodingan programnya. Sebelumnya mari kita buat desainnya.
- Form1 --> Nama: <biarkan pada default>, Caption: SCIENTIFIC CALCULATOR
- Option1 --> Nama: option1, Caption: deg, Index: 0
- Option2 --> Nama: option1, Caption: rad, Index: 1
- Option3 --> Nama: option1, Caption: grad, Index:2
- Text1 --> Nama: <biarkan pada default>, Text: <kosongkan>
- Text2 --> Nama: <biarkan pada default>, Text: <kosongkan>
- command1 --> Nama: cmdon, Caption: ON
- command2 --> Nama: cmdclear, Caption: AC
- command3 --> Nama: cmdoff, Caption: OFF
- Frame1 --> Caption: Operator
- command4 --> Caption: cmd22, Nama: 1/X, Index:0
- command5 --> Caption: cmd22, Nama: x2, Index:1
- command6 --> Caption: cmd22, Nama: x3, Index:2
- command7 --> Caption: cmd22, Nama: x!, Index:3
- command8 --> Caption: cmd22, Nama: sqrt, Index:4
- command9 --> Caption: cmd22, Nama: 10^x, Index:5
- command10 --> Caption: cmd22, Nama: log, Index:6
- command11 --> Caption: cmd22, Nama: ln, Index:7
- command12 --> Caption: cmd22, Nama: e(x), Index:8
- command13 --> Caption: cmd27, Nama: sin, Index:0
- command14 --> Caption: cmd27, Nama: cos, Index:1
- command15 --> Caption: cmd27, Nama: tan, Index:2
- command16 --> Caption: cmd27, Nama: cosin, Index:3
- command17 --> Caption: cmd27, Nama: sec, Index:4
- command18 --> Caption: cmd27, Nama: cotan, Index:5
- command19 --> Caption: cmdangka, Nama: 0, Index: 0
- command20 --> Caption: cmdangka, Nama: 1, Index: 1
- command21 --> Caption: cmdangka, Nama: 2, Index: 2
- command22 --> Caption: cmdangka, Nama: 3, Index: 3
- command23 --> Caption: cmdangka, Nama: 4, Index: 4
- command24 --> Caption: cmdangka, Nama: 5, Index: 5
- command25 --> Caption: cmdangka, Nama: 6, Index: 6
- command26 --> Caption: cmdangka, Nama: 7, Index: 7
- command27 --> Caption: cmdangka, Nama: 8, Index: 8
- command28 --> Caption: cmdangka, Nama: 9, Index: 9
- command29 --> Caption: cmdplusminus, Nama: +/-
- command30 --> Caption: cmdkoma, Nama: .
- command31 --> Caption: cmdop, Nama: +, Index: 0
- command32 --> Caption: cmdop, Nama: -, Index: 1
- command33 --> Caption: cmdop, Nama: *, Index: 2
- command34 --> Caption: cmdop, Nama: /, Index: 3
Dim ans, b, c, hasil, sudut As DoubleDim a As String
Dim i, X As IntegerDim no1 As Double, cnt1 As IntegerDim op As String, op1 As String
Private Sub cmd22_Click(Index As Integer)Dim s1, s2, s3 As Stringop = "lain"s = Val(Text1.Text)Select Case IndexCase 0Text2.Text = "1/" & sIf s = 0 ThenText1.Text = " eror"ElseIf s <> 0 ThenText1.Text = 1 / sEnd IfIf Val(tampilan.Caption) <> 0 Then tampilan.Caption = 1 / Val(tampilan.Caption)Case 1Text2.Text = s & "^(2)"Text1.Text = s ^ 2Case 2Text2.Text = s & "^(3)"Text1.Text = s ^ 3Case 3Dim n, f, k As Integern = Text1.Textf = 1k = 1Text2.Text = Text2.Text & "!"If (n < 0) ThenText1.Text = "salah input"ElseIf (n = 0) ThenText1.Text = 1ElseDo While k <= nf = f * kk = k + 1LoopText1.Text = Str(f)End IfCase 4Text2.Text = "sqr(" & s & ")"Text1.Text = Sqr(s)Case 5Text2.Text = "10^" & Text2.TextText1.Text = 10 ^ (Val(Text1.Text))Case 6Text2.Text = "log(" & s & ")"If Val(Text1.Text) > 0 ThenText1.Text = Str((Log(Val(Text1.Text)) / Log(10)))ElseText1.Text = "error"End IfCase 7Text2.Text = "ln" & Text2.TextIf Val(Text1.Text) > 0 ThenText1.Text = Str(Log(Val(Text1.Text)))ElseText1.Text = "error"End IfCase 8Text2.Text = "e^(x)" & Text2.TextIf Val(Text1.Text) < 700 ThenText1.Text = Str(Exp(Val(Text1.Text)))ElseMsgBox (" OVERFLOW. VALUE TOO BIG ")End IfEnd Select
End Sub
Private Sub cmd27_Click(Index As Integer)s = Val(Text1.Text)sudut = 180 / 3.14159265358979Dim a, b, c As SingleSelect Case IndexCase 0Text2.Text = "sin (" & Text2.Text & ")"Text1.Text = Sin(s / sudut)Case 1Text2.Text = "cos (" & Text2.Text & ")"If s = 90 Or s = 270 ThenText1.Text = 0ElseText1.Text = Cos(s / sudut)End IfCase 2If s = 90 Or s = 270 ThenText1.Text = "error"Elsea = Sin(s / sudut)b = Cos(s / sudut)c = a / bText1.Text = cEnd IfText2.Text = "tan (" & Text2.Text & ")"Case 3If s = 90 Or s = 270 ThenText1.Text = "error"Elsea = Sin(s / sudut)b = Cos(s / sudut)c = a / bText1.Text = cEnd IfText2.Text = "tan (" & Text2.Text & ")"Case 4Text2.Text = "sec (" & Text2.Text & ")"If s = 90 Or s = 270 ThenText1.Text = 0ElseText1.Text = Cos(s / sudut)End IfCase 5Text2.Text = "arc tan (" & Text2.Text & ")"Text1.Text = Str((Atn(Val(Text1.Text)) / (3.14159265358979 / 180)))End Select
End Sub
Private Sub cmd7_Click(Index As Integer)Select Case IndexCase 0Memo = Memo + Val(Text1.Text)Case 1Text1.Text = Str(Memo)prev = Val(Text1.Text)End SelectEnd Sub
Private Sub cmdangka_Click(Index As Integer)If Text1.Text = "0" ThenText1.Text = ""End IfIf X = 0 ThenText1.Text = ""X = X + 1End IfText1.Text = Text1.Text + cmdangka(Index).CaptionText2.Text = Text2.Text + cmdangka(Index).Caption
End Sub
Private Sub cmdclear_Click()Select Case IndexCase 0cnt1 = 0X = 0Text1.Text = ""Text2.Text = ""Text1.Visible = TrueCase 1Text2.Text = Mid(Text2.Text, 1, Len(Text2.Text) - 1)End Select
End Sub
Private Sub cmdkoma_Click()Text1.Text = Text1.Text + "."Text2.Text = Text2.Text + "."
End Sub
Private Sub cmdoff_Click()Unload MeEnd Sub
Private Sub cmdon_Click()Text1.Visible = TrueText2.Visible = True
End Sub
Private Sub cmdop_Click(Index As Integer)X = 0If cnt1 > 0 ThenSelect Case opCase "+"ans = no1 + Text1.TextText1.Text = ansno1 = Text1.Textop = cmdop(Index).CaptionCase "-"ans = no1 - Text1.TextText1.Text = ansno1 = Text1.Textop = cmdop(Index).CaptionCase "/"ans = no1 / Text1.TextText1.Text = ansno1 = Text1.Textop = cmdop(Index).CaptionCase "*"ans = no1 * Val(Text1.Text)Text1.Text = ansno1 = Text1.Textop = cmdop(Index).CaptionEnd Select
Elseno1 = Val(Text1.Text)op = cmdop(Index).Captioncnt1 = cnt1 + 1End IfText2.Text = Text2.Text + cmdop(Index).Caption
End Sub
Private Sub cmdplusminus_Click()Text1.Text = Text1.Text * (-1)Text2.Text = Text2.Text * (-1)
End Sub
Private Sub cmdsmdgn_Click()cnt1 = 0Select Case opCase "+"ans = Text1.Text + no1If cnt = 0 Thenno1 = Text1.Textcnt = cnt + 1End IfText1.Text = ansCase "-"If cnt > 0 ThenText1.Text = no1no1 = ansEnd Ifans = no1 - Text1.Textno1 = Text1.TextText1.Text = anscnt = cnt + 1Case "*"ans = no1 * Text1.TextIf cnt = 0 Thenno1 = Text1.Textcnt = cnt + 1End IfText1.Text = ansCase "/"If cnt > 0 ThenText1.Text = no1no1 = ansEnd IfIf Text1.Text = "0" Theni = MsgBox("Divide by zero error", vbExclamation + vbOKOnly, "ERROR")Elseans = no1 / Text1.Textno1 = Text1.TextText1.Text = anscnt = cnt + 1End If
End SelectText1.Text = Text1.TextText1.Visible = True
End Sub
Private Sub Option1_Click(Index As Integer)Select Case IndexCase 0ang = 3.141592654 / 180Case 1ang = 1Case 2ang = 3.141592654 / 200End SelectEnd Sub
- Form1 --> Nama: <biarkan pada default>, Caption: SCIENTIFIC CALCULATOR
Tidak ada komentar:
Posting Komentar