Function Frac2Num(x)
'
' Parses a standard fraction of the form "a/b" or "a b/c" and returns a number.
' e.g. "2/5" or "3 1/2" are valid input.
'
Dim Temp As String, P As Integer, N As Double, Num As Double, Den As Double
If VarType(x) < 2 Or VarType(x) = 7 Then
Frac2Num = Null
ElseIf VarType(x) <> 8 Then
Frac2Num = x
Else
Temp = Trim$(x)
P = InStr(Temp, " ")
If P = 0 Then
If InStr(Temp, "/") = 0 Then
N = Val(Temp)
Else
N = 0
End If
Else
N = Val(left$(Temp, P - 1))
Temp = Mid$(Temp, P + 1)
End If
P = InStr(Temp, "/")
If P <> 0 Then
Num = Val(left$(Temp, P - 1))
Den = Val(Mid$(Temp, P + 1))
If Den <> 0 Then
N = N + Num / Den
End If
End If
Frac2Num = N
End If
End Function