I need to do is convert a formula to a string, without evaluating it first
ie.
cstr(2-3/8) converts to 1.625, when what I need it to be is "2-3/8"
Any ideas?
I need to do is convert a formula to a string, without evaluating it first
ie.
cstr(2-3/8) converts to 1.625, when what I need it to be is "2-3/8"
Any ideas?
Where is 2-3/8 coming from?
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
Its a user entered value representing inches; its entered into a table with a field type string/text.
User has options to enter 2.375, 2-3/8, or 2 3/8, all should evaluate to 60.33mm in the function, but 2-3/8 does the math, then converts to 41.28mm
The format is borrowed from Autocad, and is familliar to all users of this database, so I'd like to keep it.
Textbox bound to text field, then the value should be treated as text string. Where are you using it that does calc? Post the function code.
Are they entering/selecting from a combobox?
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.
The values are entered either on a textbox on the main form, or on a subform in datasheet view. (Both of which are bound to text fields)
They're passed into the following function as strImpIn and the ouput is added to a double field.
Code:Public Function getMetric(strImpIn As String) As Double Dim Result As Double If InStr(CStr(strImpIn), "-") = 0 Then Result = CDbl(strImpIn) * 25.4 Else Dim wholeNum, leftFraction, rightFraction, decNum As Double Dim dashLoc, slashLoc As Integer dashLoc = InStr(CStr(strImpIn), "-") slashLoc = InStr(CStr(strImpIn), "/") wholeNum = CDbl(Left(CStr(strImpIn), dashLoc - 1)) leftFraction = CDbl(Mid(strImpIn, dashLoc + 1, CInt((Len(strImpIn) - slashLoc)))) rightFraction = CDbl(Right(strImpIn, (Len(strImpIn) - slashLoc))) decNum = CDbl(leftFraction / rightFraction) Result = Round((wholeNum + decNum) * 25.4, 2) End If getMetric = Result End Function
Last edited by tkilback; 05-15-2015 at 02:42 PM. Reason: Missing some info
I tested your function with: getMetric("2-3/8")
It returns 60.32.
However, unbound textbox with default value of 2-3/8 displays 1.625 and returns 41.275 when referenced in function. BUT, with default value of "2-3/8" (including the quote marks) returns 60.32.
Then I tried binding textbox to text field and entered value of 2-3/8. Function returns 60.32.
I cannot replicate the issue with bound textbox.
Why don't you use combobox for input? It can have columns that show the English and metric equivalents but save the metric if that's what you want. No function needed to convert. That's what I've done.
Be aware that type for variables must each be individually declared or will default to Variant type.
How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.