Imports System.Globalization

Public Module StringConversion

   Public Function DoubleToString(ByVal dVal As Double, ByVal nNumDec As Integer) As String
      Dim sFormat As String = "F" + Math.Abs(nNumDec).ToString()
      Dim sVal As String = dVal.ToString(sFormat, CultureInfo.InvariantCulture)
      If nNumDec > 0 Then
         Return sVal.TrimEnd("0".ToCharArray()).TrimEnd(".".ToCharArray)
      Else
         Return sVal
      End If
   End Function

   Public Function StringToDouble(ByVal sVal As String, ByRef dVal As Double) As Boolean
      ' Return EgtLuaEvalNumExpr(sVal, dVal)
      Return Double.TryParse(sVal, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, dVal)
   End Function

   'Public Function StringToDoubleAdv(ByVal sVal As String, ByRef dVal As Double, Optional bEval As Boolean = False) As Boolean
   '   If bEval Then
   '      Return EgtLuaEvalNumExpr(sVal, dVal)
   '   Else
   '      Return Double.TryParse(sVal, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, dVal)
   '   End If
   'End Function

   Public Function StringToInt(sVal As String, ByRef nVal As Integer) As Boolean
      Dim dVal As Double = 0
      If Not StringToDouble(sVal, dVal) Then Return False
      nVal = CInt(Math.Round(dVal))
      Return True
   End Function

   'Public Function LenToString(ByVal dVal As Double, ByVal nNumDec As Integer) As String
   '   Return DoubleToString(EgtToUiUnits(dVal), nNumDec)
   'End Function

   'Public Function StringToLen(ByVal sVal As String, ByRef dVal As Double) As Boolean
   '   If EgtLuaEvalNumExpr(sVal, dVal) Then
   '      dVal = EgtFromUiUnits(dVal)
   '      Return True
   '   Else
   '      Return False
   '   End If
   'End Function

   'Public Function StringToLenAdv(ByVal sVal As String, ByRef dVal As Double, Optional bEval As Boolean = False) As Boolean
   '   If bEval Then
   '      If EgtLuaEvalNumExpr(sVal, dVal) Then
   '         dVal = EgtFromUiUnits(dVal)
   '         Return True
   '      Else
   '         Return False
   '      End If
   '   Else
   '      If Double.TryParse(sVal, NumberStyles.Float, CultureInfo.InvariantCulture.NumberFormat, dVal) Then
   '         dVal = EgtFromUiUnits(dVal)
   '         Return True
   '      Else
   '         Return False
   '      End If
   '   End If
   'End Function

End Module
