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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Minimum Maximum weird error 1

Status
Not open for further replies.

AyJayEL

Technical User
Jan 30, 2001
425
GB
I have used a formula from FAQs to create an age field. I want to show the age range of children in the group. I have used a summary on the Age field using minimum and one using maximum. However, the minimum shows the higher age and the maximum shows the lower age. It also missed the first age in the list.

What am I doing wrong?

Learn something new every day *:->*
AyJayEl
 
Can we see the formula you have used for age?
Also, what is the min and max it is producing?
 
Age formula from FAQs. numbervar var_totalmonths := DateDiff ("m",{STUDENT.DOB},CurrentDate);
stringvar var_remainingmonths := Totext(var_totalmonths mod 12);
stringvar var_years := ToText(var_totalmonths/12);
stringvar var_yearstrimmed := If Length (var_years) = 5 Then (Left(var_years,2)) Else (Left(var_years,1));
stringvar var_remainingmonthstrimmed := If Length (var_remainingmonths) = 5
Then (Left(var_remainingmonths,2)) Else (Left(var_remainingmonths,1));

Cstr(var_yearstrimmed) + "yrs " + Cstr(var_remainingmonthstrimmed) + "mths"

The minimum and maximum are acting weirdly. If there are 6 ages i.e.

9 years 3 months
9 years 5 months
10 years 2 months
11 years 5 months
12 years 1 month
12 years 8 months

Maximum will show 9 years 5 months (missing the first in the group)
Minimum will show 12 years 8 months.

Learn something new every day *:->*
AyJayEl
 
I think what its possibly doing is that its basing the minimum and the first number and not the whole number i.e 1, and then vice versa the maximum will be 9, this could explain why your getting these results.
 
Ah yes of course. The field is converted to a string so that would account for the sorting! Back to the thinking board. Thank you.

Learn something new every day *:->*
AyJayEl
 
Change this:
Cstr(var_yearstrimmed) + "yrs " + Cstr(var_remainingmonthstrimmed) + "mths"

to:

Cstr(var_yearstrimmed,"00") + "yrs " + Cstr(var_remainingmonthstrimmed,"00") + "mths"

It adds a zero in front of the year and month if the are less than 10.

Your results will be

09 years 03 months
11 years 05 months

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top