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!

Loop parsing out leading 0's

Status
Not open for further replies.

JodyAmy

Programmer
Feb 12, 2001
21
US
Using Crystal 8.0 in PeopleSoft 8.8 and have used Crystal since Ver. 5. Trying to get rid of leading zeroes in a field that is stored as a character in an Oracle database. Here is the code:

Local Stringvar x := totext({N87CM607.N_CHKGM_AMT});
Local Numbervar i;
Local Numbervar y;
Local Numbervar z;

if {N87CM607.N_CHKG_MO_AMT_STAT} = '1' then
'CASH DEP'
else if {N87CM607.N_CHKG_MO_AMT_STAT} = '3' then
(
y := length(totext({N87CM607.N_CHKGM_AMT}));
Local Numbervar z;
z := Instr(x,'0');

for i:= 1 to y do
(
if z = 1 then
x := Right({N87CM607.N_CHKGM_AMT},Length(x)-1);
z := Instr(x,'0');
else
exit for
)
)

~~~~~~~~~~~~~~~~~~
I'm getting an error as CR is expecting a ")" on the else w/in the for loop. I'm not sure of the syntax used to exit the for loop.
 
You forgot using brackets in your if-then block within the loop....and I added a couple of semi-colons at the end that I think are needed.


Local Stringvar x := totext({N87CM607.N_CHKGM_AMT});
Local Numbervar i;
Local Numbervar y;
Local Numbervar z;

if {N87CM607.N_CHKG_MO_AMT_STAT} = '1' then
'CASH DEP'
else if {N87CM607.N_CHKG_MO_AMT_STAT} = '3' then
(
y := length(totext({N87CM607.N_CHKGM_AMT}));
Local Numbervar z;
z := Instr(x,'0');

for i:= 1 to y do
(
if z = 1 then
(
x := Right({N87CM607.N_CHKGM_AMT},Length(x)-1);
z := Instr(x,'0');
)
else
exit for;
);
);

Jim Broadbent
 
Thanks Jim, but now I get an error at the "exit for;" line stating a number is required. If I throw down "tonumber(x);" just to see what happens, I get an error on this line (else if {N87CM607.N_CHKG_MO_AMT_STAT} = '3' ) requiring a string.......I'm a little flumoxed.

Jody
 
Ahhhh...I know the cause of that....sorry

You see an if-then block requires that the results of the block be the same datatype on either side of the Else

So since the result of the first parrt is a number then the second part must be as well....it is no problem though

Try this version

Local Stringvar x := totext({N87CM607.N_CHKGM_AMT});
Local BooleanVar flag := False;
Local Numbervar i;
Local Numbervar y;
Local Numbervar z;

if {N87CM607.N_CHKG_MO_AMT_STAT} = '1' then
'CASH DEP'
else if {N87CM607.N_CHKG_MO_AMT_STAT} = '3' then
(
y := length(totext({N87CM607.N_CHKGM_AMT}));
Local Numbervar z;
z := Instr(x,'0');

for i:= 1 to y do
(
if z = 1 then
(
x := Right({N87CM607.N_CHKGM_AMT},Length(x)-1);
z := Instr(x,'0');
flag := False;
)
else
flag := True;
if flag then exit for;

);
);

Now both sides of the if-then block evaluate to a Boolean

hope this de-flumoxes you :)


Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top