MACRO LIBRARY

Lesson 1.7 code

Free public access. No account or subscription required.

Files

Lesson 1.7 code

Code

Dim strInput As String
Dim dblHeight As Double
Dim dblLength As Double
Dim dblArea As Double
    
Sub main()
    strInput = InputBox("Please enter the height of the triangle.")
    Call InputChecker(strInput)
    dblHeight = CDbl(strInput)
    
    strInput = InputBox("Please enter the base length of the triangle.")
    Call InputChecker(strInput)
    dblLength = CDbl(strInput)
    
    dblArea = AreaCalc(dblHeight, dblLength)
    MsgBox "The area of the triangle is: " & dblArea
End Sub
    
Sub InputChecker(text As String)
    If IsNumeric(text) = False Then
        MsgBox "Numbers only. Macro will end."
        End
    End If
End Sub
    
Function AreaCalc(height As Double, length As Double) As Double
    AreaCalc = 0.5 * height * length
End Function