- Nilai Alas,Tinggi dan Sisi Miringnya --> Rumus Phytagoras
Untuk memulai membuat program, persiapkan dulu hal-hal berikut
- Atur sebuah layout seperi gambar (lihat di bagian bawah postingan ini.
- Atur propertinya sbb:
* TextBox = TTinggi, TAlas, TAtas, TBawah, TSisi
* Label = LLuas
* CommandButton = CReset, CHitung, CKeluar
* Line untuk membentuk gambar segittiga
Option Explicit
Dim rAtas As String
Dim rBawah As String
Dim pi As String
Dim Opp As String
Dim SisiMiring As String
Dim Adj As String
Dim Sudut As String
Dim X As String
Sub Reset()
TTinggi.Text = ""
TAlas.Text = ""
TSisi.Text = ""
TAtas.Text = ""
TBawah.Text = ""
LLuas = ""
pi = 3.14159265358979
End Sub
Sub Konversi()
Opp = ""
SisiMiring = ""
Sudut = ""
Adj = ""
rAtas = ""
rBawah = ""
If TAtas.Text <> "" Then rAtas = TAtas.Text * pi / 180
If TBawah.Text <> "" Then rBawah = TBawah.Text * pi / 180
End Sub
Private Sub CHitung_Click(Index As Integer)
Call HitungSudut
If TTinggi.Text <> "" Or TAlas.Text <> "" Or TSisi.Text <> "" Then
Call Konversi
If rBawah <> "" And TTinggi.Text <> "" Or TSisi.Text <> "" And rBawah <> "" Then
Sudut = rBawah
Opp = TTinggi.Text
SisiMiring = TSisi.Text
Call Calcsin
TTinggi.Text = Opp
TSisi.Text = SisiMiring
End If
If rAtas <> "" And TAlas.Text <> "" Or TSisi.Text <> "" And rAtas <> "" Then
Opp = TAlas.Text
SisiMiring = TSisi.Text
Sudut = rAtas
Call Calcsin
TAlas.Text = Opp
TSisi.Text = SisiMiring
End If
If rBawah <> "" And TAlas.Text <> "" Or TSisi.Text <> "" And rBawah <> "" Then
Sudut = rBawah
Adj = TAlas.Text
SisiMiring = TSisi.Text
Call Calccos
TAlas.Text = Adj
TSisi.Text = SisiMiring
End If
If rAtas <> "" And TTinggi.Text <> "" Or TSisi.Text <> "" And rAtas <> "" Then
Sudut = rAtas
Adj = TTinggi.Text
SisiMiring = TSisi.Text
Call Calccos
TTinggi.Text = Adj
TSisi.Text = SisiMiring
End If
If rAtas <> "" And TAlas.Text <> "" Or rAtas <> "" And TTinggi.Text <> "" Then
Sudut = rAtas
Adj = TTinggi.Text
Opp = TAlas.Text
Call Calctan
TTinggi.Text = Adj
TAlas.Text = Opp
End If
If rBawah <> "" And TAlas.Text <> "" Or rBawah <> "" And TTinggi.Text <> "" Then
Sudut = rAtas
Adj = TAlas.Text
Opp = TTinggi.Text
Call Calctan
TAlas.Text = Adj
TTinggi.Text = Opp
End If
If rAtas = "" And TAlas.Text <> "" And TTinggi.Text <> "" Then
Sudut = rAtas
Opp = TAlas.Text
Adj = TTinggi.Text
Call InvTan
TAtas.Text = Sudut * 180 / pi
End If
If rBawah = "" And TAlas.Text <> "" And TTinggi.Text <> "" Then
Sudut = rAtas
Opp = TTinggi.Text
Adj = TAlas.Text
Call InvTan
TBawah.Text = Sudut * 180 / pi
End If
If rAtas = "" And TAlas.Text <> "" And TSisi.Text <> "" Then
Sudut = rAtas
Opp = TAlas.Text
SisiMiring = TSisi.Text
Call InvSin
TAtas.Text = Sudut * 180 / pi
End If
If rBawah = "" And TTinggi.Text <> "" And TSisi.Text <> "" Then
Sudut = rBawah
Opp = TTinggi.Text
SisiMiring = TSisi.Text
Call InvSin
TBawah.Text = Sudut * 180 / pi
End If
End If
LLuas = (TAlas.Text * TTinggi.Text) / 2
End Sub
Private Sub CKeluar_Click(Index As Integer)
Unload Me
End Sub
Private Sub CReset_Click()
Call Reset
End Sub
Private Sub Form_Load()
Call Reset
End Sub
Function Calcsin() As Single
If Opp = "" And SisiMiring <> "" And Sudut <> "" Then Opp = SisiMiring * Sin(Sudut)
If SisiMiring = "" And Opp <> "" And Sudut <> "" Then SisiMiring = Opp / Sin(Sudut)
End Function
Function Calccos() As Single
If Adj = "" And SisiMiring <> "" And Sudut <> "" Then Adj = SisiMiring * Cos(Sudut)
If SisiMiring = "" And Adj <> "" And Sudut <> "" Then SisiMiring = Adj / Cos(Sudut)
End Function
Sub HitungSudut()
If TBawah.Text <> "" And TAtas.Text <> "" Then
If Val(TAtas.Text) + Val(TBawah.Text) <> "90" Then MsgBox ("Tidak Bisa Diproses")
End If
If TBawah.Text <> "" And TAtas.Text = "" Then TAtas.Text = 90 - Val(TBawah.Text)
If TAtas.Text <> "" And TBawah.Text = "" Then TAtas.Text = 90 - Val(TAtas.Text)
If Val(TAtas.Text) > 90 Or Val(TAtas.Text) <> 90 Or Val(TBawah.Text) <>
End Sub
Function Calctan() As String
If Opp = "" And Adj <> "" And Sudut <> "" Then Opp = Adj * Tan(Sudut)
If Adj = "" And Opp <> "" And Sudut <> "" Then Adj = Opp / Tan(Sudut)
End Function
Function InvTan() As String
If Opp <> "" And Adj <> "" And Sudut = "" Then Sudut = Atn(Opp / Adj)
End Function
Function InvSin() As String
X = Opp / SisiMiring
Sudut = Atn(X / Sqr(-X * X + 1))
End Function
Maka hasil program akan seperti gambar di bawah ini:
Posting Komentar