|
|
Question : Crystal Reports, ver 8.5, extract portion of text field as number
|
|
Hi, I need to extract a portion of a text field (not memo) as a number. Example:
Dust all rooms, 6 minutes per day, 5 times per week. I want the 6 only
Dishwashing, 20 minutes per meal per day I want the 20
Errand. Pick up clients prescriptions from pharmacy. 15 minutes per week. I want the 15 only
I will need to total these numbers as minutes. The phrases can have more than one number, it can be preceded by a comma, period or whatever. The only thing consistent is the word "minutes" in the field. The field name is task.des. Also not every field has minutes in it so I received an error unless I tested the field first like:
if {task.des} like "* minutes *"then...
and return blank or zero if there are no "minutes" if instr() is used.
Tried this from this forum:
stringvar sentence := {PwHcTelRptTasks.TskDes}; stringvar array words := split(sentence," "); numbervar i; stringvar result := "";
for i := 1 to ubound(words) do ( if (left(words[i],1) = "(" and right(words[i],1) = ")") then (i := i + 1; "") else if isnumeric(words[i]) then result := words[i] ); result;
it worked fine until the first example above of "6 minutes per day, 5 times per week" in this case the 5 was returned not the 6.
Any help would be appreciated!
Open in New Window
Select All
|
Answer : Crystal Reports, ver 8.5, extract portion of text field as number
|
|
IN this line you uppercase the string but test against lowercase values If UpperCase(Words[i]) in ['minutes','minutes.','minutes,','extra minutes'] then Sorry, I didn't fully think through the EXTRA issue. Since the formula splits the text into words the value of one of them will never be "EXTRA MINUTES" In my new formula this line should be
If UpperCase(Words[i]) IN ['MINUTES', 'MINUTES.', 'MINUTES,'] then If IsNumeric(Words[i-1]) then MinutesValue := MinutesValue + Val(Words[i-1]) Else if UpperCase(Words[i-1]) = 'EXTRA' then If IsNumeric(Words[i-2]) then MinutesValue := MinutesValue + Val(Words[i-2])
mlmcc
|
|
|
|
|