Option Strict Off
Option Explicit On
<System.Runtime.InteropServices.ProgId("TableDef_ANSI.TableDef")> Public Class TableDef
    Dim m_Thickness As Double
    Dim m_Radius(25) As Double
    Dim m_Angle(25) As Double
    Dim m_FlatLength(25) As Double

    Dim m_TableCount As Short

    Public Sub New()
        m_TableCount = 0
    End Sub

    Protected Overrides Sub Finalize()
        ' nothing to do
    End Sub

    Public Property Thickness() As Double
        Get
            Thickness = m_Thickness
        End Get
        Set(ByVal Value As Double)
            m_Thickness = Value
        End Set
    End Property

    Public Function ThicknessMatch(ByRef thk As Double) As Short
        'Use this function to compare a given thickness to the thickness of this table
        'Returns True if it matches, False if it does not.
        If System.Math.Abs(thk - m_Thickness) <= gTol Then
            ThicknessMatch = True
        Else
            ThicknessMatch = False
        End If
    End Function

    Public Sub AddEntry(ByRef Radius As Double, ByRef Angle As Double, ByRef Length As Double)
        'Add and entry into the table
        'The program has a max of 25 table entries. You can change this if needed.
        m_TableCount = m_TableCount + 1

        If m_TableCount < 26 Then
            m_Radius(m_TableCount) = Radius
            m_Angle(m_TableCount) = Angle
            m_FlatLength(m_TableCount) = Length
        Else
            m_TableCount = 25
        End If

    End Sub

    Public Function GetValueFromTable(ByRef R As Double, ByRef A As Double) As Double
        'Use this function to get a value from this table for a given bend radius and angle.
        'If there is not match in the table return -1.
        Dim ii As Short
        Dim RDelta As Double
        Dim ADelta As Double

        'Loop through table and check for a match
        ii = 1
        Do While ii <= m_TableCount
            RDelta = System.Math.Abs(R - m_Radius(ii))
            ADelta = System.Math.Abs(A - m_Angle(ii))

            If RDelta <= gTol And ADelta <= gTol Then
                GetValueFromTable = m_FlatLength(ii)
                Exit Function
            End If
            ii = ii + 1
        Loop

        'Did not find a match in table return -1
        GetValueFromTable = -1

    End Function
End Class