Another approach if you want the same behavior as Val is to use Val but preprocess the string sent to it.
Code:Function Val#(ByVal txt$) 'Wraps VBA.Val ' enables handling of decimal point chars other than "." ' VBA val only works on decimals when the decimal char is "." Static normal As Boolean, init As Boolean, dp$ If Not init Then dp$ = dpChar() normal = (dp$ = ".") init = True End If If normal Then Val = VBA.Val(txt$) Else Val = VBA.Val(Replace$(txt$, dp$, ".")) End If 'VB help recommends CDbl but.. 'the following dos'nt work with strings that contain numbers and text ' like eg. "5.4 mp" because the error is tripped and 0 is returned 'On Error Resume Next 'Val = CDbl(txt$) End Function Function dpChar$() dpChar$ = Mid$(Format$(0.1, "fixed"), 2, 1) End Function




Reply With Quote