Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function ConvertDecimalOrFractionString(ByVal s As String, ByRef value As Decimal) As Boolean
Dim result As Boolean = True
If (Regex.IsMatch(s, "\d+\.\d+")) Then 'Parameter has a decimal point
result = Decimal.TryParse(s, value)
ElseIf (Regex.IsMatch(s, "\d+/\d+")) Then 'Parameter is a fraction
Dim ixOp As Integer = s.IndexOf("/")
Dim numerator As Integer = Convert.ToInt32(s.Substring(0, ixOp))
Dim denominator As Integer = Convert.ToInt32(s.Substring(ixOp + 1, s.Length - ixOp - 1))
If (denominator <> 0) Then
value = Convert.ToDecimal(numerator / denominator)
Else
result = False
End If
End If
Return result
End Function
If (Regex.IsMatch(s, "\d*\.\d+")) Then 'Parameter has a decimal point
result = Decimal.TryParse(s, value)
ElseIf (Regex.IsMatch(s, "\d+/\d+")) Then 'Parameter is a fraction
Dim numer As Integer
Dim denom As Integer
Dim digits() As String = s.Split("/")
result = (Integer.TryParse(digits(0), numer) AndAlso Integer.TryParse(digits(1), denom) AndAlso denom > 0)
If (result = True) Then value = Convert.ToDecimal(numer / denom)
End If
[blue] Private Function Fraction(ByVal strSource As String) As String
Dim sc As New MSScriptControl.ScriptControl()
Dim RunningTotal As Double
Dim Component As String
sc.Language = "VBScript"
For Each Component In Split(TextBox1.Text, " ")
RunningTotal = RunningTotal + sc.Eval(Component)
Next
Fraction = RunningTotal.ToString
End Function[/blue]
sPattern = "((?<whole>\d+) (?<num>\d+)/(?<den>\d+))" ' 1 1/2 case
regExp = New System.Text.RegularExpressions.Regex(sPattern, RegexOptions.Compiled)
m = regExp.Match(dgvc.Value)
If m.Success Then
dDecValue = CInt(m.Groups("whole").Value) + CInt(m.Groups("num").Value) / CInt(m.Groups("den").Value)
Else
sPattern = "((?<num>\d+)/(?<den>\d+))" ' 3/4 case
regExp = New System.Text.RegularExpressions.Regex(sPattern, RegexOptions.Compiled)
m = regExp.Match(dgvc.Value)
If m.Success Then
dDecValue = CInt(m.Groups("num").Value) / CInt(m.Groups("den").Value)
Else
sPattern = "(?<dec>\d+\.?\d+)" ' 0.5 case
regExp = New System.Text.RegularExpressions.Regex(sPattern, RegexOptions.Compiled)
m = regExp.Match(dgvc.Value)
If m.Success Then
dDecValue = CDbl(m.Groups("dec").Value)
Else
sPattern = "(?<whole>\d+)" ' 2 case
regExp = New System.Text.RegularExpressions.Regex(sPattern, RegexOptions.Compiled)
m = regExp.Match(dgvc.Value)
If m.Success Then
dDecValue = CDbl(m.Groups("whole").Value)
Else
MsgBox("Error in value")
End If
End If
End If
End If