Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert StringVar to NumberVar

Status
Not open for further replies.

dbltt25

MIS
Nov 29, 2000
28
0
0
US
I am using Crystal 8.5 with an Access 2000 database.
We have medical software that calculates BMI values and saves them into an Access Database. This field is stored as a String value ( that is updated with each patient). I need to take that string value, place into a variable and covert that to a number (actually a number range array).

Once my value is a number, then I have do calculations on the value to display different text for each patient.

What is the best way to convert a stringvar to a numbervar?

Here is an example of what I am trying to accomplish:

If BMI <18.5 then display “See your primary care provider now about your weight”
If BMI =18.5 <25 then display” Your BMI is within the normal range”
If BMI =25 <30 then display “Utilize resources for information regarding you weight.


Does anyone know of the easiest way to do this conversion and then calculates based on those values?

Any help I appreciate!!

 
Dear dbltt25,

Have you tried:

//begin
numbervar BMI_2_NO := tonumber({table.string});
stringvar display;

If BMI_2_NO < 18.5 then
display := “See your primary care provider now about your weight.”
else
If BMI_2_NO in 18.5 to 24 then
display := ”Your BMI is within the normal range.”
else
If BMI_2_NO in 25 to 29 then
display := “Utilize resources for information regarding you weight.&quot;
//end

I haven't had a chance to test - but I think it is right.

ro
Rosemary Lieberman
rosemary@microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.
 
Thank-You very much!
I was working somewhat down that path, but went off the track. Another question, is there another function to use beside Tonumber that I am missing?

If the BMI value is 19.5-the tonumber function is rounding it to 20. I must be missing something in my conversion.

Thoughts??!!
 
Doesn't sound right to me, try placing a formula with:

tonumber(&quot;19.5&quot;)

in your report, it should produce 19.5.

You might check File->Options->Fields->Number for the default rounding being used.

If this is only occuring for 19.5, I doubt that it's related.

You can always try the val() function, it basically does the same thing, except that it will take just the numeric portion, as in:

val(&quot;123 Main Street&quot;) results in 123
val(&quot;Main Street&quot;) results in 0
val(&quot;123.55&quot;) results in 123.55

-k kai@informeddatadecisions.com
 
That's it!! Thank-You soo much. Sometimes it is the smallest things that you cannot figure out!

I knew that a straight Tonumber should not have been rounding anything.


T
[wink] or ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top