|
|
|
@@ -47,7 +47,7 @@ Public Module FractionStringConverter
|
|
|
|
|
sFraction = DoubleToString(dRound, 0) & "/" & DoubleToString(dBase, 0)
|
|
|
|
|
End If
|
|
|
|
|
' sVal: dFeet'dInteger"sFraction --- dInteger sFraction
|
|
|
|
|
Return WriteFraction(dInteger, sFraction)
|
|
|
|
|
Return WriteFraction(sSign, dInteger, sFraction)
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
' trasforma il valore da pollici a piedi
|
|
|
|
@@ -60,27 +60,38 @@ Public Module FractionStringConverter
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
' stampa dati in funzione del pattern dichiarato
|
|
|
|
|
Private Function WriteFraction(ByVal dInches As Double, sFraction As String) As String
|
|
|
|
|
Private Function WriteFraction(ByVal sSign As String, ByVal dInches As Double, sFraction As String) As String
|
|
|
|
|
Dim sVal As String = String.Empty
|
|
|
|
|
Select Case nCurrFractionPattern
|
|
|
|
|
Case FractionPattern.Feet_Inches
|
|
|
|
|
Dim dFeet As Double = 0
|
|
|
|
|
ConvertInchesToFeet(dFeet, dInches)
|
|
|
|
|
If dFeet > 0 Then
|
|
|
|
|
If dFeet <> 0 Then
|
|
|
|
|
sVal = String.Format("{0}'{1}""{2}", DoubleToString(dFeet, 0), DoubleToString(dInches, 0), sFraction).Trim
|
|
|
|
|
Else
|
|
|
|
|
sVal = String.Format("{0}""{1}", DoubleToString(dInches, 0), sFraction).Trim
|
|
|
|
|
If dInches <> 0 Then
|
|
|
|
|
sVal = String.Format("{0}""{1}", DoubleToString(dInches, 0), sFraction).Trim
|
|
|
|
|
Else
|
|
|
|
|
sVal = String.Format("{0}", sFraction).Trim
|
|
|
|
|
End If
|
|
|
|
|
End If
|
|
|
|
|
Case FractionPattern.Inches
|
|
|
|
|
sVal = DoubleToString(dInches, 0) & " " & sFraction
|
|
|
|
|
sVal = String.Format("{0}""{1}", DoubleToString(dInches, 0), sFraction).Trim
|
|
|
|
|
If dInches <> 0 Then
|
|
|
|
|
sVal = String.Format("{0}""{1}", DoubleToString(dInches, 0), sFraction).Trim
|
|
|
|
|
Else
|
|
|
|
|
sVal = String.Format("{0}", sFraction).Trim
|
|
|
|
|
End If
|
|
|
|
|
End Select
|
|
|
|
|
If Not String.IsNullOrEmpty(sVal) Then
|
|
|
|
|
sVal = sSign & sVal
|
|
|
|
|
End If
|
|
|
|
|
Return sVal
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
' riceve la stringa sorgente e restituisce la nuova strunga in formato decimale (senza eseguire conversioni di unità)
|
|
|
|
|
Public Function StringFractionToStringDecimal(sVal As String, ByRef sValConverted As String) As Boolean
|
|
|
|
|
Public Function OldStringFractionToStringDecimal(sVal As String, ByRef sValConverted As String) As Boolean
|
|
|
|
|
Dim dVal As Double = 0
|
|
|
|
|
Dim bNegativeValue As Boolean = False
|
|
|
|
|
' dato in ingresso: sVal = 2'3"23/32
|
|
|
|
|
Dim sFeet As String = String.Empty
|
|
|
|
|
Dim sFeetPattern As String = "(.*?)(?=')"
|
|
|
|
@@ -159,7 +170,11 @@ Public Module FractionStringConverter
|
|
|
|
|
|
|
|
|
|
' calcolo il valore decimale dell'espressione
|
|
|
|
|
If bOkFeet And bOkInch And bOkFraction Then
|
|
|
|
|
dVal = dFeet * 12 + dInch + dFraction
|
|
|
|
|
If dFeet < 0 OrElse dInch < 0 Or dFraction < 0 Then
|
|
|
|
|
dVal = -(Math.Abs(dFeet) * 12 + Math.Abs(dInch) + Math.Abs(dFraction))
|
|
|
|
|
Else
|
|
|
|
|
dVal = dFeet * 12 + dInch + dFraction
|
|
|
|
|
End If
|
|
|
|
|
sValConverted = DoubleToString(dVal, 4)
|
|
|
|
|
Return True
|
|
|
|
|
Else
|
|
|
|
@@ -167,31 +182,82 @@ Public Module FractionStringConverter
|
|
|
|
|
End If
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
Public Function MyStringFractionToStringDecimal(sVal As String, ByRef sValConverted As String) As Boolean
|
|
|
|
|
Dim sPattern As String = "(-?) *(\d+ */? *\d*')? *(\d* */? *\d+-)? *(\d+ */? *\d* *"")?(\d+ */? *\d*)?"
|
|
|
|
|
Public Function StringFractionToStringDecimal(sVal As String, ByRef sValConverted As String) As Boolean
|
|
|
|
|
sValConverted = sVal
|
|
|
|
|
' (-?) *(\d */? *\d*')? *(\d* */? *\d+-)? *(\d */? *\d* *""?)? *(\d */? *\d*)?
|
|
|
|
|
Dim sPattern As String = "(-?) *(\d */? *\d*')?( *(?(?=\d+ */ *\d+)\d+ */ *\d+|\d+)""?)*"
|
|
|
|
|
Dim MyMatchCollection As MatchCollection = Regex.Matches(sVal, sPattern)
|
|
|
|
|
|
|
|
|
|
For Each MyMatch As Match In MyMatchCollection
|
|
|
|
|
' Loop over captures.
|
|
|
|
|
Dim bValueExists As Boolean = False
|
|
|
|
|
Dim bNegative As Boolean = False
|
|
|
|
|
Dim dFeet As Double = 0
|
|
|
|
|
Dim bFeet As Boolean = True
|
|
|
|
|
Dim dInch As Double = 0
|
|
|
|
|
Dim bInch As Boolean = True
|
|
|
|
|
Dim dFraction As Double = 0
|
|
|
|
|
Dim bFraction As Boolean = True
|
|
|
|
|
Dim sCurrValue As String = String.Empty
|
|
|
|
|
Dim sCurrValueConverted As String = String.Empty
|
|
|
|
|
Dim dCurrValueConverted As Double = 0
|
|
|
|
|
|
|
|
|
|
For Each MyGroup As Capture In MyMatch.Captures
|
|
|
|
|
For GroupIndex As Integer = 0 To MyMatch.Groups.Count - 1
|
|
|
|
|
Dim MyGroup As Group = MyMatch.Groups(GroupIndex)
|
|
|
|
|
Dim sGroupVal As String = MyGroup.Value
|
|
|
|
|
Select Case MyGroup.Index
|
|
|
|
|
Case 1
|
|
|
|
|
' riconosco il segno "-" ad inizio stringa
|
|
|
|
|
Case 2
|
|
|
|
|
' riconosco il valore di Feet " ' "
|
|
|
|
|
Case 3
|
|
|
|
|
' ...?...
|
|
|
|
|
Case 4
|
|
|
|
|
' riconosco il valore di Inch " "" "
|
|
|
|
|
Case 5
|
|
|
|
|
' riconosco il valore di frazione
|
|
|
|
|
End Select
|
|
|
|
|
|
|
|
|
|
' verifico che il gruppo non sia vuoto
|
|
|
|
|
If Not String.IsNullOrEmpty(sGroupVal) Or Not String.IsNullOrWhiteSpace(sGroupVal) Then
|
|
|
|
|
Select Case GroupIndex
|
|
|
|
|
Case 0
|
|
|
|
|
' se il valore è vuoto allora passo a prossimo Match
|
|
|
|
|
If String.IsNullOrEmpty(sGroupVal.Trim) Or String.IsNullOrWhiteSpace(sGroupVal.Trim) Then
|
|
|
|
|
Exit For
|
|
|
|
|
End If
|
|
|
|
|
' salvo il valore del membro dell'espressione che deve essere valutato
|
|
|
|
|
sCurrValue = sGroupVal
|
|
|
|
|
bValueExists = True
|
|
|
|
|
Case 1
|
|
|
|
|
' riconosco il segno "-" ad inizio stringa
|
|
|
|
|
bNegative = True
|
|
|
|
|
Case 2
|
|
|
|
|
' riconosco il valore di Feet " ' "
|
|
|
|
|
sGroupVal = sGroupVal.Replace("'"c, "")
|
|
|
|
|
bFeet = StringToDouble(sGroupVal, dFeet)
|
|
|
|
|
Case 3
|
|
|
|
|
For CaptureIndex As Integer = 0 To MyGroup.Captures.Count - 1
|
|
|
|
|
Dim MyCapture As Capture = MyGroup.Captures(CaptureIndex)
|
|
|
|
|
Dim sCapture As String = MyCapture.Value
|
|
|
|
|
Select Case CaptureIndex
|
|
|
|
|
Case 0
|
|
|
|
|
' riconosco il valore in pollici
|
|
|
|
|
sCapture = sCapture.Replace(""""c, "")
|
|
|
|
|
bInch = StringToDouble(sCapture, dInch)
|
|
|
|
|
Case 1
|
|
|
|
|
' riconosco il valore di frazione
|
|
|
|
|
bFraction = StringToDouble(sCapture, dFraction)
|
|
|
|
|
End Select
|
|
|
|
|
Next
|
|
|
|
|
End Select
|
|
|
|
|
End If
|
|
|
|
|
Next
|
|
|
|
|
Next
|
|
|
|
|
|
|
|
|
|
If bValueExists And bFeet And bInch And bFraction Then
|
|
|
|
|
' ricavo il valore decimale
|
|
|
|
|
dCurrValueConverted = dFeet * 12 + dInch + dFraction
|
|
|
|
|
If bNegative Then dCurrValueConverted = -dCurrValueConverted
|
|
|
|
|
sCurrValueConverted = DoubleToString(dCurrValueConverted, 4)
|
|
|
|
|
' sostituisco il valore calcolato nell'espressione iniziale
|
|
|
|
|
Dim nStartIndex As Integer = sValConverted.IndexOf(sCurrValue)
|
|
|
|
|
sValConverted = sValConverted.Remove(nStartIndex, sCurrValue.Count).Insert(nStartIndex, sCurrValueConverted)
|
|
|
|
|
End If
|
|
|
|
|
' passo allavalutazione del prossimo membro dell'espressione
|
|
|
|
|
Next
|
|
|
|
|
Dim dValueConverted As Double = 0
|
|
|
|
|
If StringToDouble(sValConverted, dValueConverted) Then
|
|
|
|
|
sValConverted = DoubleToString(dValueConverted, 4)
|
|
|
|
|
Else
|
|
|
|
|
' Errore lettura stringa: sCurrVal non è convertibile
|
|
|
|
|
Return False
|
|
|
|
|
End If
|
|
|
|
|
Return True
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|