Private Sub calculatefromabc()
On Error GoTo eh
Dim a As Double, b As Double, c As Double
Dim X As Double, AngA As Double
Dim w As Double, h As Double
a = CDbl(aTextBox.Text)
b = CDbl(bTextBox.Text)
c = CDbl(cTextBox.Text)
X = (-a * a + b * b + c * c) / (2 * b * c)
AngA = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1) 'arccosine
h = b * Sin(AngA)
w = b * Cos(AngA)
hTextBox.Text = CStr(h)
wTextBox.Text = CStr(w)
Label6.Caption = "-"
Exit Sub
eh:
Label6.Caption = "Error"
wTextBox.Text = ""
hTextBox.Text = ""
End Sub
Private Sub drawParallelogram(c As Double, w As Double, h As Double)
ActiveDrawing.Graphics.AddLineSingle 0, 0, 0, c, 0, 0 'base line c
ActiveDrawing.Graphics.AddLineSingle 0, 0, 0, w, h, 0 'diag line b
ActiveDrawing.Graphics.AddLineSingle c, 0, 0, w, h, 0 'line a
ActiveDrawing.Graphics.AddLineSingle w, h, 0, w - c, h, 0 'paralell c
ActiveDrawing.Graphics.AddLineSingle 0, 0, 0, w - c, h, 0 ' paralell a
End Sub
Private Sub aTextBox_Change()
calculatefromabc
End Sub
Private Sub bTextBox_Change()
calculatefromabc
End Sub
Private Sub CommandButton1_Click()
On Error GoTo eh:
Dim a As Double, c As Double
Dim w As Double, h As Double
c = CDbl(cTextBox.Text)
w = CDbl(wTextBox.Text)
h = CDbl(hTextBox.Text)
drawParallelogram c, w, h
Exit Sub
eh:
Label6.Caption = "Cannot draw parallelogram"
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub cTextBox_Change()
calculatefromabc
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
calculatefromabc
End Sub