NAMA : DELLA K. ARDIANSAH
JURUSAN : TELKOMMIL #4
NO : 20190433-E
JURUSAN : TELKOMMIL #4
NO : 20190433-E
MEMBUAT KALKULATOR TRIGOMETRI
LANGKAH LANGKAH PEMBUATAN KALKULATOR :
1. Buka VB pilih new project kemudian pilih standar exe
2. Buat button dan label seperti gambar dibawah
3. Komponen yang di gunakan adalah sebagai berikut :
Penjelasan
program :
- Kontrol yang digunakan : command
button dan text
- Gunakan Variable bertipe double /
float untuk menampung angka yang akan dioperasikan
- Untuk akar gunakan sqr(….)
- Untuk sin, cos,
tan, gunakan Math.sin(cdbl(…*(phi/180)))
4. Untuk
codding sebagai berikut :
Dim a, b, hasil As Double
Dim ulang As Integer
Private Sub Command1_Click()
'kuadrat
a = Me.Text1.Text
If Me.Text1.Text = "0" Then
Me.Text1.Text = "0"
Else
hasil = a * a
End If
Me.Text1.Text = Str(hasil)
End Sub
Private Sub Command11_Click()
a = 0
Me.Text1.Text = "0"
End Sub
Private Sub Command12_Click()
Me.Text2.Text = Me.Text1.Text & " mod "
b = Me.Text1.Text
Me.Label1.Caption = "4"
Me.Text1.Text = "0"
End Sub
Private Sub Command13_Click()
Me.Text1.Text = "0"
Me.Text2.Text = ""
Me.Label1.Caption = ""
a = 0
b = 0
hasil = 0
End Sub
Private Sub Command16_Click()
Me.Text1.Text = 3.14
a = Val(Me.Text1.Text)
End Sub
Private Sub Command17_Click()
'7
If Me.Text1.Text = "0" Then
Me.Text1.Text = "7"
Else
Me.Text1.Text = Me.Text1.Text &
"7"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command18_Click()
'8
If Me.Text1.Text = "0" Then
Me.Text1.Text = "8"
Else
Me.Text1.Text = Me.Text1.Text &
"8"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command19_Click()
'9
If Me.Text1.Text = "0" Then
Me.Text1.Text = "9"
Else
Me.Text1.Text = Me.Text1.Text &
"9"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command2_Click()
'pemangkatan
a = Me.Text1.Text
Me.Text2.Text = Me.Text1.Text & " ^ "
Me.Text1.Text = "0"
Me.Label1.Caption = "5"
MsgBox a
End Sub
Private Sub Command20_Click()
'kali
If Me.Text2.Text = "" Then
Me.Text2.Text = Me.Text1.Text &
" x "
Else
Me.Text2.Text = Me.Text2.Text &
Me.Text1.Text
End If
If b = 0 Then
b = a
Else
b = b * a
End If
Me.Label1.Caption = "3"
Me.Text1.Text = "0"
End Sub
Private Sub Command22_Click()
'4
If Me.Text1.Text = "0" Then
Me.Text1.Text = "4"
Else
Me.Text1.Text = Me.Text1.Text &
"4"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command23_Click()
If Me.Text1.Text = "0" Then
Me.Text1.Text = "5"
Else
Me.Text1.Text = Me.Text1.Text &
"5"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command24_Click()
'6
If Me.Text1.Text = "0" Then
Me.Text1.Text = "6"
Else
Me.Text1.Text = Me.Text1.Text &
"6"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command25_Click()
'kurang
If Me.Text2.Text = "" Then
Me.Text2.Text = Me.Text1.Text &
" - "
Else
Me.Text2.Text = Me.Text2.Text &
Me.Text1.Text
End If
If b = 0 Then
b = a
Else
b = b - a
End If
Me.Label1.Caption = "2"
Me.Text1.Text = "0"
End Sub
Private Sub Command27_Click()
'1
If Me.Text1.Text = "0" Then
Me.Text1.Text = "1"
Else
Me.Text1.Text = Me.Text1.Text &
"1"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command28_Click()
'2
If Me.Text1.Text = "0" Then
Me.Text1.Text = "2"
Else
Me.Text1.Text = Me.Text1.Text &
"2"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command29_Click()
'3
If Me.Text1.Text = "0" Then
Me.Text1.Text = "3"
Else
Me.Text1.Text = Me.Text1.Text &
"3"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command3_Click()
a = Int(Me.Text1.Text)
If Me.Text1.Text = "0" Then
Me.Text1.Text = "0"
Else
Me.Text2.Text = " Sin "
& Me.Text1.Text
hasil = Math.Sin(CDbl(a * ((22 / 7)
/ 180)))
End If
Me.Text1.Text = hasil
End Sub
Private Sub Command30_Click()
If Me.Text2.Text = "" Then
Me.Text2.Text = Me.Text1.Text &
" + "
Else
Me.Text2.Text = Me.Text2.Text &
Me.Text1.Text
End If
b = b + a
Me.Label1.Caption = "1"
Me.Text1.Text = "0"
End Sub
Private Sub Command33_Click()
'3
If Me.Text1.Text = "0" Then
Me.Text1.Text = "0"
Else
Me.Text1.Text = Me.Text1.Text &
"0"
End If
a = Val(Me.Text1.Text)
End Sub
Private Sub Command35_Click()
'samadengan
If Me.Label1.Caption = "1" Then
Me.Text2.Text = Me.Text2.Text &
Me.Text1.Text & " = "
hasil = Val(Me.Text1.Text) + b
ElseIf Me.Label1.Caption = "2" Then
Me.Text2.Text = Me.Text2.Text &
Me.Text1.Text & " = "
hasil = b - Val(Me.Text1.Text)
ElseIf Me.Label1.Caption = "3" Then
Me.Text2.Text = Me.Text2.Text &
Me.Text1.Text & " = "
hasil = b * Val(Me.Text1.Text)
ElseIf Me.Label1.Caption = "4" Then
Me.Text2.Text = Me.Text2.Text &
Me.Text1.Text & " = "
hasil = b Mod a
ElseIf Me.Label1.Caption = "5" Then
Me.Text2.Text = Me.Text2.Text &
Me.Text1.Text & " = "
b = Me.Text1.Text
hasil = 1
For ulang = 1 To b
hasil =
hasil * a
Next
End If
Me.Text1.Text = Str(hasil)
End Sub
Private Sub Command4_Click()
a = Int(Me.Text1.Text)
If Me.Text1.Text = "0" Then
Me.Text1.Text = "0"
Else
If a = 90 Then
Me.Text1.Text
= "0"
Else
Me.Text2.Text
= " cos " & Me.Text1.Text
hasil =
Cos(CDbl(a * ((22 / 7) / 180)))
End If
End If
Me.Text1.Text = hasil
End Sub
Private Sub Command5_Click()
a = Int(Me.Text1.Text)
If a = 90 Then
Text1.Text = "invalid"
Else
hasil = Tan(a * ((22 / 7) / 180))
Me.Text2.Text = " Tan "
& Me.Text1.Text
End If
Me.Text1.Text = hasil
End Sub
Private Sub Command6_Click()
a = Int(Me.Text1.Text)
Me.Text1.Text = Sqr(a)
End Sub
Private Sub Command7_Click()
If Me.Text1.Text = "0" Then
Me.Text1.Text = "0"
Else
hasil = 1
For ulang = 1 To Val(Me.Text1.Text)
hasil =
hasil * 10
Next
Me.Text1.Text = Str(hasil)
End If
End Sub
Private Sub Image1_Click()
End Sub
9. Setelah selesai coba run atau jalankan proggramnya.
jika benar maka akan terlihat seperti ini :
Contoh Program Visual Basic (VB) Kalkultor
Komentar
Posting Komentar