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!

Mental Bloc - if then statements in CRW

Status
Not open for further replies.

mrmtek

Programmer
Oct 13, 2002
109
AU
The following is insterted into a formula and biulds a string: For the life of me I cant figure out what I have done wrong????.

WhilePrintingRecords;
local StringVar txt;
local StringVar tx;
txt:="";
tx:="";
if not isnull({database.value}) then
tx:=tx+MID(totext({data.minvalue}),1,length(totext({data.minvalue}))-1)+"/";
if not isnull({data.maxvalue}) then
tx:=tx+MID(totext({data.maxvalue}),LENGTH(totext({data.maxvalue}))-1);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if not isnull({data.tminvalue}) then
tx:=tx+MID(totext({data.tminvalue}),1,length(totext({data.tminvalue}))-1)+&quot;/&quot;;
if not isnull({data.tmaxvalue}) then
tx:=tx+MID(totext({data.tmaxvalue}),1,length(totext({data.tmaxvalue}))-1);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
 
Neither can we, since you don't say what the error you're getting is, or what the output is that you're trying to achieve.
 
If this is your entire formula, it will always display &quot;&quot; because you're resetting yout tx variable as your last line.



Mike
 
As mbarron says you are constantly resetting the value of &quot;tx&quot;...which seems to be a temporary variable of some sort.

You also say this is &quot;PART OF THE FORMULA&quot;...I think you should give us the whole formula so we can judge the problem better...and as Naith said above &quot;what is the problem&quot;??

I do see one potential error though it may just be a typo on your part.

*********************
if not isnull({database.value}) then
tx:=tx+MID(totext({data.minvalue}),1,length(totext({data.minvalue}))-1)+&quot;/&quot;;
*******************

should this not be

if not isnull({data.minvalue}) then
tx:=tx+MID(totext({data.minvalue}),1,length(totext({data.minvalue}))-1)+&quot;/&quot;;

There also seems to be a problem here

***************
if not isnull({data.maxvalue}) then
tx:=tx+MID(totext({data.maxvalue}),LENGTH(totext({data.maxvalue}))-1);
**************

to be consistant and frankly functional this should be

if not isnull({data.maxvalue}) then
tx:=tx+MID(totext({data.maxvalue}),1,LENGTH(totext({data.maxvalue}))-1);

Perhaps these are your errors....It looks to me as though you are knockly off the last digit on the right of a number for whatever reason. DO YOU WANT TO ELIMINATE THE SIGN OF THE NUMBER??? if so you are attacking the wrong end

instead of using MID why not use simply LEFT? since you are starting at the first character anyway.




Jim Broadbent
 
Well, mid/left doesn't really matter. But like Jim and Mike have said, the constant resetting of tx to an empty string is odd. It leads me to believe that this formula is not a display formula. But if it is, ending with tx := ''; is going to result in an empty output all the time.

Also txt:=txt+space(9-length(tx))+tx; seems to be asking for trouble, if you cannot guarantee that tx will never be more than 9 chars in length. If it is, the formula will fold.

If you state what it is you're trying to achieve, someone will be able to help you with the best solution.

Naith
 
Good feed back - teaches me not to be in a rush!

This formula creates a display string where it reads database fields - and appends the values together to form a string where the value of the field is not null. I have to convert numeric values to text and then supress decimal places depending on predefined method (which is hard coded) hence the use of MID statement.

The full formula is as follows : problem is I end up with a blank formula , however if I comment out the last bit of code it seams to work:

WhilePrintingRecords;
local StringVar txt;
local StringVar tx;
txt:=&quot;&quot;;
tx:=&quot;&quot;;
if not isnull({RECIPE.RECIPE_MICRON_CV_MIN}) then
tx:=tx+MID(totext({RECIPE.RECIPE_MICRON_CV_MIN}),1,length(totext({RECIPE.RECIPE_MICRON_CV_MIN}))-1)+&quot;/&quot;;
if not isnull({RECIPE.RECIPE_MICRON_CV_MAX}) then
tx:=tx+MID(totext({RECIPE.RECIPE_MICRON_CV_MAX}),1,LENGTH(totext({RECIPE.RECIPE_MICRON_CV_MAX}))-1);
if length(tx)<> 0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if not isnull({RECIPE.RECIPE_YIELD_MIN}) then
tx:=tx+MID(totext({RECIPE.RECIPE_YIELD_MIN}),1,length(totext({RECIPE.RECIPE_YIELD_MIN}))-1)+&quot;/&quot;;
if not isnull({RECIPE.RECIPE_YIELD_MAX}) then
tx:=tx+MID(totext({RECIPE.RECIPE_YIELD_MAX}),1,length(totext({RECIPE.RECIPE_YIELD_MAX}))-1);
if length(tx)<> 0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_VM1_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_VM1_MIN}),1,length(totext({RECIPE.RECIPE_VM1_MIN}))-1)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_VM1_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_VM1_MAX}),1,length(totext({RECIPE.RECIPE_VM1_MAX}))-1);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_VM2_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_VM2_MIN}),1,length(totext({RECIPE.RECIPE_VM2_MIN}))-2)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_VM2_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_VM2_MAX}),1,length(totext({RECIPE.RECIPE_VM2_MAX}))-2);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_VM3_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_VM3_MIN}),1,length(totext({RECIPE.RECIPE_VM3_MIN}))-2)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_VM3_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_VM3_MAX}),1,length(totext({RECIPE.RECIPE_VM3_MAX}))-2);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_EST_CARDING_LENGTH_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_EST_CARDING_LENGTH_MIN}),1,length(totext({RECIPE.RECIPE_EST_CARDING_LENGTH_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_EST_CARDING_LENGTH_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_EST_CARDING_LENGTH_MAX}),1,length(totext({RECIPE.RECIPE_EST_CARDING_LENGTH_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_EST_HMA_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_EST_HMA_MIN}),1,length(totext({RECIPE.RECIPE_EST_HMA_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_EST_HMA_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_EST_HMA_MAX}),1,length(totext({RECIPE.RECIPE_EST_HMA_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_STAPLE_LENGTH_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_STAPLE_LENGTH_MIN}),1,length(totext({RECIPE.RECIPE_STAPLE_LENGTH_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_STAPLE_LENGTH_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_STAPLE_LENGTH_MAX}),1,length(totext({RECIPE.RECIPE_STAPLE_LENGTH_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_STAPLE_LENGTH_CV_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_STAPLE_LENGTH_CV_MIN}),1,length(totext({RECIPE.RECIPE_STAPLE_LENGTH_CV_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_STAPLE_LENGTH_CV_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_STAPLE_LENGTH_CV_MAX}),1,length(totext({RECIPE.RECIPE_STAPLE_LENGTH_CV_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_STAPLE_STRENGTH_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_STAPLE_STRENGTH_MIN}),1,length(totext({RECIPE.RECIPE_STAPLE_STRENGTH_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_STAPLE_STRENGTH_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_STAPLE_STRENGTH_MAX}),1,length(totext({RECIPE.RECIPE_STAPLE_STRENGTH_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_POB_BASE_MIN})=false) then
tx:=txt+MID(totext({RECIPE.RECIPE_POB_BASE_MIN}),1,length(totext({RECIPE.RECIPE_POB_BASE_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_POB_BASE_MAX})=false) then
tx:=txt+MID(totext({RECIPE.RECIPE_POB_BASE_MAX}),1,length(totext({RECIPE.RECIPE_POB_BASE_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_POB_MID_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_POB_MID_MIN}),1,length(totext({RECIPE.RECIPE_POB_MID_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_POB_MID_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_POB_MID_MAX}),1,length(totext({RECIPE.RECIPE_POB_MID_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_POB_TIP_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_POB_TIP_MIN}),1,length(totext({RECIPE.RECIPE_POB_TIP_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_POB_TIP_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_POB_TIP_MAX}),1,length(totext({RECIPE.RECIPE_POB_TIP_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_HAUT_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_HAUT_MIN}),1,length(totext({RECIPE.RECIPE_HAUT_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_HAUT_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_HAUT_MAX}),1,length(totext({RECIPE.RECIPE_HAUT_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_CVH_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_CVH_MIN}),1,length(totext({RECIPE.RECIPE_CVH_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_CVH_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_CVH_MAX}),1,length(totext({RECIPE.RECIPE_CVH_MAX}))-3);
if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;
tx:=&quot;&quot;;
if (isnull({RECIPE.RECIPE_NOIL_MIN})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_NOIL_MIN}),1,length(totext({RECIPE.RECIPE_NOIL_MIN}))-3)+&quot;/&quot;;
if (isnull({RECIPE.RECIPE_NOIL_MAX})=false) then
tx:=tx+MID(totext({RECIPE.RECIPE_NOIL_MAX}),1,length(totext({RECIPE.RECIPE_NOIL_MAX}))-3);
//if length(tx)<>0 then
txt:=txt+space(9-length(tx))+tx;

 
Seems there's a bit of a Catch 22 situation here.

If, when you say it works when you comment out the last line, you mean this

//if length(tx)<>0 then txt:=txt+space(9-length(tx))+tx;

it would suggest that both {RECIPE.RECIPE_NOIL_MIN} and {RECIPE.RECIPE_NOIL_MAX} are null, meaning that the last line is not executed. I would suggest adding Else txt; to the end of your code.

However, if you get a value returned when you comment out the last line, as your post suggests, then you would be returning the value of tx - not of txt - which means that tx cannot be null at the last stage, because of your constant resetting.

Does commenting out the last line actually give you the output you want - or does it simply return a value?

Naith
 
I agree with Naith...

I do see that you changed your If-condition in midstream from

if not isnull({RECIPE.RECIPE_YIELD_MIN}) then (Which I like)

to

if (isnull({RECIPE.RECIPE_CVH_MIN})=false) then (Which I don't like)

I would make them consistantly based on the first method which I think is a better one. On the surface there is no difference but I know the first method works.

Then I would start at the bottom and comment out a whole section

************
//tx:=&quot;&quot;;
//if (isnull({RECIPE.RECIPE_NOIL_MIN})=false) then
// tx:=tx+MID(totext({RECIPE.RECIPE_NOIL_MIN}),1,length
//(totext({RECIPE.RECIPE_NOIL_MIN}))-3)+&quot;/&quot;;
//if (isnull({RECIPE.RECIPE_NOIL_MAX})=false) then
// tx:=tx+MID(totext({RECIPE.RECIPE_NOIL_MAX}),1,length
//(totext({RECIPE.RECIPE_NOIL_MAX}))-3);
//if length(tx)<>0 then
// txt:=txt+space(9-length(tx))+tx;

************

I would also have

txt;

as my last statement.

If you still have a blank then comment out another section until you get a reasonable answer to find the bad guy.



Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top