Jump to content


Photo
- - - - -

Stuck in a loop


5 replies to this topic

#1 anortonbk

anortonbk

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 17 March 2007 - 03:06 PM

Here's the situation - I'm reading a 500 character text field, and want to break it into individual 70 character chunks and write each 70 character chunk as a record in a lines file. I am trying to parse where there is a space ' ' so that I don't chop a word in half.

I've got myself in an endless loop, and I know it'll be obvious to someone else what I'm doing wrong, I've just been staring at it too long. Here's my code:

$$FIELD= FIELD
#LEN = LEN($$FIELD)
#BEG = 1
WHILE #Y < #LEN
#END = #BEG + 70
FOR #X = #END DOWNTO #BEG BY -1
IF $$FIELD(#X,1) = ' ' THEN
#A = #X
#X = #BEG
ENDIF
ENDFOR
$LINE = $$FIELD(#BEG,#A)
LSCALL $LNCMNTS $LNCMNTS will write this chunck of text the line the line file
#Y = #A + 1
$$FIELD= $$FIELD(#Y,#LEN)
#BEG = #Y
ENDWHILE

Edited by anortonbk, 17 March 2007 - 03:07 PM.


#2 anortonbk

anortonbk

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 17 March 2007 - 04:01 PM

In line 7, I actually had:

IF $$FIELD(#X,#X) = ' ' THEN

#3 andykay

andykay

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 204 posts
  • Gender:Male
  • Location:Cyberspace...looking for work

Posted 19 March 2007 - 05:33 AM

#BEG = 1
WHILE #Y < #LEN
#END = #BEG + 70
FOR #X = #END DOWNTO #BEG BY -1



Anortonbk,

Your FOR statement immediately stands out. Using your variable examples, by using a DOWNTO, the FOR loop will automatically go from 71 down to 1, 1 at a time automatically. I fail to see what you are trying to do with your BY statement and I'm not sure ProIV can handle even do it that way. I've never seen it done this way before and it appears to me to be a double negative. You want to step down 71 downto 1 by -1 which is actually an increase. Try removing the "BY -1" from your FOR loop and see what happens.


AK

Edited by andykay, 19 March 2007 - 05:36 AM.

THE LIGHT AT THE END OF THE TUNNEL IS THE HEADLAMP OF THE TRAIN THAT'S ABOUT TO HIT YOU!!!

#4 andykay

andykay

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 204 posts
  • Gender:Male
  • Location:Cyberspace...looking for work

Posted 19 March 2007 - 05:42 AM

IF $$FIELD(#X,1) = ' ' THEN
#A = #X
#X = #BEG
ENDIF


Try

IF $$FIELD(#X,#X) = ' ' THEN

instead.


AK
THE LIGHT AT THE END OF THE TUNNEL IS THE HEADLAMP OF THE TRAIN THAT'S ABOUT TO HIT YOU!!!

#5 Matthews Estrice

Matthews Estrice

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 241 posts
  • Gender:Male
  • Location:Henley-on-klip

Posted 19 March 2007 - 01:46 PM

LOOPEXIT transfers control from a block within a FOR or WHILE loop to the statement following the ENDFOR or ENDWHILE statement.

#6 anortonbk

anortonbk

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 19 March 2007 - 09:34 PM

Thanks, I actually ended up getting this all worked out fine, after a few UMSGs, and is working great.

Thanks!!



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users