Announcement

Collapse
No announcement yet.

Eof Function

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Eof Function

    Please add your comments and suggestions as a Reply to this thread.





    PB/WIN - EOF function

    Purpose
    Return the end-of-file status of an opened file or TCP/UDP transmission.
    Syntax
    y = EOF([#] filenum&)
    Remarks
    Use EOF to determine when the end of a file has been reached while reading its data. filenum& is the file number specified when the file was Opened. EOF returns -1 (TRUE) if the end of the specified file has been reached, or if an error occurs trying to check for the end of the file. Otherwise, EOF returns 0 (FALSE).

    If filenum& is not a valid, open file, a run-time Error 53 will occur ("File not found"). If filenum& is for a binary file, EOF returns TRUE only if the most recent file operation was a read operation, and that operation could not read the requested number of bytes.

    The EOF function may also be used with the COMM LINE and TCP LINE statements to detect that an incomplete line was received. Normally, these statements read data until a $CRLF character pair is found, and in that case, EOF will return 0 (FALSE). However, even if no $CRLF has been found, the statements will end when no additional data is available. In that case, they will return whatever data has already been accumulated, and set EOF to -1 (TRUE).

    In many cases, it would be prudent to test EOF after every COMM LINE and TCP LINE to verify that a full line has been received. In some cases, you may wish to execute the statement one or more additional times, combining the data, in order to obtain a full line of text.
    See AlsoExamples
    Code:
    ' Open an ASCII text file and read it
    hFile = FREEFILE
    OPEN "TEXTFILE.TXT" FOR INPUT AS hFile
    WHILE ISFALSE EOF(hFile)
      LINE INPUT# hFile, x$
    WEND
    CLOSE hFile
    Last edited by Gary Beene; 28 Oct 2014, 06:54 PM.

  • #2
    The following code excerpt was working great until Friday AM, 07/27/2017, when it suddenly wasn't. The environment is a SUSE Linux Enterprise server v 11.3, running SAMBA 3. The program was compiled in PB/CC 6.02. It runs in a DOS window on Win 10 Pro workstations. The file that is opened, JOBLOOK.TXT is created by another PB/CC compiled program. No intentional changes have been made to the server or workstation OS, the program itself has not been modified since 2009.

    I am providing the original code with the only change being a comment added to the KILL line. I have modified another copy of the code to print the system ERR value, which is 62. This error occurs on file OPEN before the contents are read, so the IF statement is evaluated as FALSE. I have tried the suggestion above but have been unsuccessful in making it work. I modified the code to create the file in the local directory on the server and that did not help. I created the file from scratch in VI to make sure the other program wasn't adding any stray characters and that didn't work.

    To complicate matters, if I run the code from a workstation installation of the application, it works just fine. Any help or suggestions would be greatly appreciated!

    COLOR 15, 9
    CLS

    A$ = "ZZ999901010101"
    JobLookInType$ = "P"
    TypeByOper$ = "7020-01"

    Ecode% = 1 ' DO NOT LOOK FOR ERROR
    JL& = FREEFILE
    OPEN "C:\QDATALOG\JOBLOOK.TXT" FOR INPUT AS #JL&
    IF ERR = 0 THEN
    INPUT #JL&, A$ ' JOB NUMBER
    INPUT #JL&, JobLookInType$ ' JobLookInType$
    INPUT #JL&, TypeByOper$ ' TypeByOper$
    INPUT #JL&, DateByOper$ ' Pick-up or Delivery Date
    INPUT #JL&, QtyByOper$ ' Number to ADD or Service
    INPUT #JL&, PriceByOper$ ' Price charged per unit
    INPUT #JL&, PONByOper$ ' Purchase Order Number
    INPUT #JL&, JSTByOper$ ' Job Site Telephone
    CLOSE #JL&

    ' KILL "C:\QDATALOG\JOBLOOK.TXT"

    COLOR 15, 9

    The content of JOBLOOK.TXT follows:

    M0272507241138
    P
    7xxx-xx
    07-28-2017
    0
    00.00
    GEORGE
    5551212



    Comment


    • #3
      Hi

      This is the sort of error that I get - and usually the problem is obvious - only after you find it!

      Firstly your code is not complete. There is no END IF

      I always check for errors after every file instruction. After every open, close, kill and read - always helps find my programming errors. Check, display, WAITKEY$

      I think it is highly unlikely that you get ERR 62 on opening - very peculiar. I need to do an MCM on you - code which demonstrates that not shown!! Maybe you picked up and did not clear the error earlier in the program. Add an ERRCLEAR at the start of this routine to make sure this is not happening.

      It is quite a good idea to display the contents of each field after reading too.

      And why not try a FILESCAN too? Everything helps

      My best guess is that you are accessing the wrong copy of JOBLOOK.TXT because that is the kind of thing that I would be doing!

      So what I would do first is to change the data in the file and print out the fields and you will have learnt something.

      (btw You do not have to have the & and $ etc at the end of each file name. It took me a while to realize this as well)

      Frustrating ain't it?

      Kerry
      [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
      Kerry Farmer

      Comment


      • #4
        THANK YOU!!! I really appreciate the help. You were spot on. The problem was obvious, once I found it. Regarding your points, there was an END IF, I just didn't copy down far enough to show it. (Tunnel vision!) The check each part suggestion was the key. I added the extra code steps throughout the program and discovered a totally different file was missing field data. The read for that file was actually generating the error 62. Regarding the & and $, the code I've inherited is about 40 years old, originally written in BASIC. It was transitioned to MSBASIC and then PB/CC over the years. I'm still getting up to speed on all of it's idiosyncrasies. The still unanswered question, for me, is why did the program execute without any errors on a Win 10 Pro workstation but only act out when it was launched from a Linux server? I guess some things are just unknowable. Again, thanks for your quick and timely help. Now I can go virus hunting on my laptop!

        Comment

        Working...
        X