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

Formula causes crash

Status
Not open for further replies.

SteveW99

MIS
Joined
Mar 11, 2004
Messages
9
Location
GB
Using the following formula in Crystal 8.5 causes the program to crash. Does anybody have a solution?

ToNumber(
(if Left({Table1.Field1},1) in ["H"] then {Table1.Field1} [2 to 5] else
if Left({Table1.Field1},1) in ["U","F"] then {Table1.Field1} [2 to 4] else

ToText(
if (Val ( strreverse ({Table1.Field1})) ) < 0 then
int(Val ({Table1.Field1})) *-1 else
(Val({Table1.Field1}))))
)

Thanks
 
I'd suggest splitting up the code into several different formula fields, which would refer to each other.

I've never tried putting an IF.. ELSE.. choice inside of a 'ToNumber', as distinct from converting a formula field whose result is determined by such a choice.

Modularising is much better than trying to disentange 5 layers of bracketing.

PS, exactly what do you mean by 'crash'? Is there a specific error, or does Crystal 8.5 just give up? Either way, if the elements of the code were separate, it would be much clearer where the problem lay.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
Thanks, I'll try that. By 'crash', I mean Crystal closes and the Windows error regarding sending an error report appears. I am running XP Pro, incidentally.
 
Your rpt file may be corrupt, if you think your formula should be sound.

Create a new file, drop the formula into it, and see if you can replicate the problem.
 
I think you should show sample data that reflects the variation possible in the field and also explain what you are trying to do. There may be a better way of going about it.

-LB
 
I have split the code into modules and that solved the problem of crashing, and I also created a new report with the new code and both seem OK, except the results are not the same as using the 'full' version of the code, so I assume a mistake has been made in making the modules. Briefly, the point of the excercise is this: data entry in the source program is not consistent- entries such as 'H1342', 'H1342/', 'H1342-' are all supposed to be '1342' for sorting purposes. I am trying to remove the letter if there is one and the /or -.
Any suggestions would be appreciated and thank you all for the help so far.
 
This is really a new topic. Also you should try using SEARCH for existing answers.

For the cases you show, you could get rid of the leading character using If NumericText (left({field}, 1)) then {field} else mid({field}, 2, 10). Using the formula field as input to another you could say Replace(@TrimField, "/", "") and the same again for "-", or you could run the functions together. But it all depends on the range of possibilities.

[yinyang] Madawc Williams (East Anglia, UK) [yinyang]
 
You should find yourself in a better place with the following:
Code:
WhilePrintingRecords;
StringVar test := {Your.Field}
NumberVar string;
NumberVar max := Length(test);
StringVar end := "";

For string := 1 To max 
    Do
    (
    If Isnumeric(test[string])
    Then end := end + test[string] 
    Else end 
    );
end;
Naith
 
Yes is it is a new topic,but lbass requested data so I included it for convenience.
Thanks again to all for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top