Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with my Loop in FileRead()

275 views
Skip to first unread message

cto...@utilitieskingston.com

unread,
Nov 13, 2007, 10:28:26 AM11/13/07
to
Hey guys;

I'm having some problems with my loop for reading a file.

The loop is always running one more than expected. If there are 4
records in the file, then the loop runs 5 times.

I'm wondering how to get it to loop for only the amount of files in
the actual file.
Here is my code:


Do
ll_BytesRead = FileRead( li_Data_FileNum, ls_file_lines )


if ll_BytesRead <> -100 and Asc(ls_file_lines) <> 26 then
ll_FileLength += ll_BytesRead
li_count ++
else
ll_FileLength += Len( ls_file_lines )
end if


Loop Until ll_BytesRead <= 0 or Asc(ls_file_lines) = 26

Chris Pollach

unread,
Nov 13, 2007, 11:02:35 AM11/13/07
to

Suggestion ... Why not replace the FileRead with a the newer FileReadEX ( )
method - then you do not need to write any loop to get the whole file in one
command?


<cto...@utilitieskingston.com> wrote in message
news:1194967706.0...@v29g2000prd.googlegroups.com...

cto...@utilitieskingston.com

unread,
Nov 13, 2007, 11:15:26 AM11/13/07
to
On Nov 13, 11:02 am, "Chris Pollach" <cpoll...@travel-net.com> wrote:
> Suggestion ... Why not replace the FileRead with a the newer FileReadEX ( )
> method - then you do not need to write any loop to get the whole file in one
> command?
>
> <ctor...@utilitieskingston.com> wrote in message

>
> news:1194967706.0...@v29g2000prd.googlegroups.com...
>
>
>
> > Hey guys;
>
> > I'm having some problems with my loop for reading a file.
>
> > The loop is always running one more than expected. If there are 4
> > records in the file, then the loop runs 5 times.
>
> > I'm wondering how to get it to loop for only the amount of files in
> > the actual file.
> > Here is my code:
>
> > Do
> > ll_BytesRead = FileRead( li_Data_FileNum, ls_file_lines )
>
> > if ll_BytesRead <> -100 and Asc(ls_file_lines) <> 26 then
> > ll_FileLength += ll_BytesRead
> > li_count ++
> > else
> > ll_FileLength += Len( ls_file_lines )
> > end if
>
> > Loop Until ll_BytesRead <= 0 or Asc(ls_file_lines) = 26- Hide quoted text -
>
> - Show quoted text -

I'm only using Powerbuilder 9, so i don't think it can be used in that
one

Dean Jones

unread,
Nov 13, 2007, 11:27:51 AM11/13/07
to
might want to process each row as its read...

--
Dean Jones
CEO
PowerObjects
http://www.powerobjects.com
(612) 339-3355 Ext. 112

TeamSybase
* * Think Sybase * *


"Chris Pollach" <cpol...@travel-net.com> wrote in message
news:4739ca9b$1@forums-1-dub...

cto...@utilitieskingston.com

unread,
Nov 13, 2007, 11:48:05 AM11/13/07
to
On Nov 13, 11:27 am, "Dean Jones"

<dean_dot_jones_at_powerobjects_dot_com> wrote:
> might want to process each row as its read...
>
> --
> Dean Jones
> CEO
> PowerObjectshttp://www.powerobjects.com

> (612) 339-3355 Ext. 112
>
> TeamSybase
> * * Think Sybase * *
>
> "Chris Pollach" <cpoll...@travel-net.com> wrote in message

>
> news:4739ca9b$1@forums-1-dub...
>
>
>
>
>
> > Suggestion ... Why not replace the FileRead with a the newer FileReadEX
> > ( ) method - then you do not need to write any loop to get the whole file
> > in one command?
>
> > <ctor...@utilitieskingston.com> wrote in message

> >news:1194967706.0...@v29g2000prd.googlegroups.com...
> >> Hey guys;
>
> >> I'm having some problems with my loop for reading a file.
>
> >> The loop is always running one more than expected. If there are 4
> >> records in the file, then the loop runs 5 times.
>
> >> I'm wondering how to get it to loop for only the amount of files in
> >> the actual file.
> >> Here is my code:
>
> >> Do
> >> ll_BytesRead = FileRead( li_Data_FileNum, ls_file_lines )
>
> >> if ll_BytesRead <> -100 and Asc(ls_file_lines) <> 26 then
> >> ll_FileLength += ll_BytesRead
> >> li_count ++
> >> else
> >> ll_FileLength += Len( ls_file_lines )
> >> end if
>
> >> Loop Until ll_BytesRead <= 0 or Asc(ls_file_lines) = 26- Hide quoted text -
>
> - Show quoted text -

that's what i'm trying to do, but my problem comes up at the end, when
it still tries to process one extra blank row......


Actually, i have just figured it out.

thanks for the help and tips

Chris Pollach

unread,
Nov 13, 2007, 1:05:50 PM11/13/07
to

Yep ... too old a PB release for that - not to mention EOL'ed and
unsupported.


<cto...@utilitieskingston.com> wrote in message
news:1194970526.5...@s15g2000prm.googlegroups.com...

Arthur Hefti

unread,
Nov 14, 2007, 12:23:24 AM11/14/07
to
After reading the last line the FileRead is executed again and returns
-100. However the ls_file_lines stays the value from the read before.
This length will be added in the else clause to the ll_FileLength.
However the li_Count should be the number of lines.
You can set ls_file_lines to an empty string before reading. I'm also
quite sure that it will not include the file end marker in the data read.

Regards
Arthur

0 new messages