Loading ...
Sorry, an error occurred while loading the content.

End of File Test

Expand Messages
  • Art Kocsis
    I ve been pulling my hair out (and I don t have much left to pull!), unsuccessfully trying to find a test for an EOF (end of file) condition. If I am at the
    Message 1 of 6 , Sep 24, 2008
    • 0 Attachment
      I've been pulling my hair out (and I don't have much left to pull!),
      unsuccessfully trying to find a test for an EOF (end of file) condition. If
      I am at the EOF I need to write a NL before writing other text.

      This is a most basic test for file operations so there must be one
      someplace but dammed if I can find it. Any suggestions?


      Namaste', Art

      For every expert, there is an equal and
      opposite expert. - Arthur C. Clarke
    • Sheri
      ... I think either of these would work. H= Test1EOF ^!If ^$GetSelSize$ 0 Error ^!SetScreenUpdate off ^!SelectTo 1:1 ^!Set %offset%=^$GetSelSize$ ^!Jump
      Message 2 of 6 , Sep 24, 2008
      • 0 Attachment
        Art Kocsis wrote:
        > I've been pulling my hair out (and I don't have much left to pull!),
        > unsuccessfully trying to find a test for an EOF (end of file) condition. If
        > I am at the EOF I need to write a NL before writing other text.
        >
        > This is a most basic test for file operations so there must be one
        > someplace but dammed if I can find it. Any suggestions?
        >
        I think either of these would work.

        H="Test1EOF"
        ^!If ^$GetSelSize$>0 Error
        ^!SetScreenUpdate off
        ^!SelectTo 1:1
        ^!Set %offset%=^$GetSelSize$
        ^!Jump Select_End
        ^!SetScreenUpdate on
        ^!If ^%offset%=^$GetTextSize$ Next Else End
        ^!InsertText ^P
        ^!Goto End
        :Error
        ^!Prompt There is a selection in the document, cannot test for end of file."
        ;end of clip

        H="Test2EOF"
        ^!If ^$GetSelSize$>0 Error
        ^!SetScreenUpdate off
        ^!Set %Pos%="^$GetRow$:^$GetCol$"
        ^!Jump Doc_End
        ^!Set %endpos%="^$GetRow$:^$GetCol$"
        ^!IfSame "^%endpos%" "^%Pos%" DoLine Else ReturnToPos
        :DoLine
        ^!SetScreenUpdate on
        ^!InsertText ^P
        ^!Goto End
        :ReturnToPos
        ^!SetCursor ^%Pos%
        ^!SetScreenUpdate on
        ^!Goto End
        :Error
        ^!Prompt There is a selection in the document, cannot test for end of file."
        ;end of clip
      • Larry Hamilton
        I seem to remember the EOF coming up before in years past, but it was several years ago. It may have even been when we were still eGroups. One of Sherri s or
        Message 3 of 6 , Sep 24, 2008
        • 0 Attachment
          I seem to remember the EOF coming up before in years past, but it was
          several years ago. It may have even been when we were still eGroups.

          One of Sherri's or my clips could be altered to return the cursor to the
          original position automatically, if not the EOF, and then become a
          custom function to test for EOL using the ^!Result command. However,
          these clips can't be run from the Clipbar. It would be just as easy to
          use a ^!Clip or ^!FarClip command to call such a clip like a function.

          Of course, you could just use ^!Jump TEXT_END to be at the end of the
          file, if all you needed was to insure you were at the end of the topic
          or document.

          All lines start with on of these four characters H ; ^ : the line I
          would worry about wrapping is the one with ^!Continue.

          <clip>
          H="EOF Test"
          ;09/24/2008 Larry Hamilton
          ;Test if current position EOF
          ^!Set %CursorOriginal%=^$getrow$:^$getcol$
          ;End of Text Document or Outline Topic
          ;Change to DOC_END to go to end of any document
          ^!Jump TEXT_END
          ^!Set %CursorEnd%=^$getrow$:^$getcol$
          ^!IfSame ^%CursorOriginal% ^%CursorEnd% NEXT ELSE NOT_EOF
          ^!Info The original cursor position is the EOF
          ^!GoTo END

          :NOT_EOF
          ;Long Line Follows
          ^!Continue The original cursor position was NOT the EOL. Yes to Return
          to original position Cancel to stay at EOF.
          ^!SetCursor ^%CursorOriginal%
          ^!Info The Cursor has returned to the original position.
          :END
          </clip>

          Here's a second clip to add a line, with option to return to original
          position. This time the long line starts with ^!Skip.

          <clip>
          EOF Test2
          ;09/24/2008 Larry Hamilton
          ;Test if current position EOF
          ;^!SetDebug ON
          ^!Set %CursorOriginal%=^$getrow$:^$getcol$
          ;End of Text Document or Outline Topic
          ;Change to DOC_END to go to end of any document
          ^!Jump TEXT_END
          ^!Set %CursorEnd%=^$getrow$:^$getcol$
          ^!IfSame ^%CursorOriginal% ^%CursorEnd% INSERT ELSE NEXT
          ^!Skip The original cursor position was NOT the EOL. Yes to Return to
          original position No to stay at EOF & add a line.
          ^!GoTo INSERT
          ^!SetCursor ^%CursorOriginal%
          ^!GoTo DONE

          :INSERT
          ^!InsertText ^P
          :DONE
          </clip>

          Larry Hamilton


          Sheri wrote:
          > Art Kocsis wrote:
          >
          >> I've been pulling my hair out (and I don't have much left to pull!),
          >> unsuccessfully trying to find a test for an EOF (end of file) condition. If
          >> I am at the EOF I need to write a NL before writing other text.
          >>
          >> This is a most basic test for file operations so there must be one
          >> someplace but dammed if I can find it. Any suggestions?
        • Michael Frascinella
          Art, I had this saved in my Notetab libraries folder. If the current row (line) number equals the total number of paragraphs (lines), then you are at the end
          Message 4 of 6 , Sep 24, 2008
          • 0 Attachment
            Art,

            I had this saved in my Notetab libraries folder. If the current row
            (line) number equals the total number of paragraphs (lines), then you
            are at the end of file. There are a few prompts to tell you where you
            are but they can be deleted.

            Yours,

            Michael F
            =======

            ^!Info you are on line ^$GetRow$
            ^!If ^$GetRow$=^$GetParaCount$ lastrow Else end

            :lastrow
            ^!Info this is the end of file
            ^!Goto Exit

            :End
            ^!Info this is not the last line


            [Non-text portions of this message have been removed]
          • Sheri
            ... Hi Michael, That only works if Wordwrap is Off, which you can set at the top using ^!SetWordwrap Off Also I would caution that Exit and End are special
            Message 5 of 6 , Sep 24, 2008
            • 0 Attachment
              --- In ntb-clips@yahoogroups.com, Michael Frascinella
              <mfrascinella@...> wrote:
              >

              > ^!Info you are on line ^$GetRow$
              > ^!If ^$GetRow$=^$GetParaCount$ lastrow Else end
              >
              > :lastrow
              > ^!Info this is the end of file
              > ^!Goto Exit
              >
              > :End
              > ^!Info this is not the last line
              >


              Hi Michael,

              That only works if Wordwrap is Off, which you can set at the top using

              ^!SetWordwrap Off

              Also I would caution that Exit and End are special label names. Other
              special label names are Next and Skip. I think actual named labels in
              the clip should not use any of the special names.

              ^!Goto Exit

              says not to return to the calling clip (if any), so to terminate a
              clip, you would normally want to use End (not Exit).

              Regards,
              Sheri
            • Art Kocsis
              Thanks Michael, It s almost what I was looking for. I guess I didn t make myself totally clear in my request but you picked up on it anyway. I was looking for
              Message 6 of 6 , Sep 29, 2008
              • 0 Attachment
                Thanks Michael,

                It's almost what I was looking for. I guess I didn't make myself totally
                clear in my request but you picked up on it anyway. I was looking for a
                simple command for an EOF test, not a clip, as it would be used in a loop
                to append a new line to the document if the cursor was at the EOF. It is
                such a standard test that thought it existed in Notetab and I just couldn't
                find it.

                However, you gave me the clue that I needed. Looking up ^$GetParaCount$ I
                found the ^$GetLineCount$ command which avoids the word wrap issue. So the
                EOF conditional becomes:

                ^!Set %EOF%=^$GetRow$ >= ^$GetLineCount$

                Hmmm. Well, it would be if logical expressions were allowed. (Note, even
                though the current row should never be greater than the total line count
                years of debugging taught me to be very cautious in testing for equality,
                hence the ">=" rather than "=".)

                However, restating it as conditional test:

                ^!If ^$GetRow$ < ^$GetLineCount$ NotEOF_Label EOF_Label

                is almost as good as a direct EOF test. And, in looking back, almost
                identical to what you suggested (except for the change of function)

                So thanks again for the tip. Sorry I didn't respond earlier - I got waylaid
                by other projects and couldn't get back to this until now.

                Namaste', Art

                At 9/24/2008 05:58 PM, you wrote:
                >I had this saved in my Notetab libraries folder. If the current row
                >(line) number equals the total number of paragraphs (lines), then you
                >are at the end of file. There are a few prompts to tell you where you
                >are but they can be deleted.
                >
                >Yours, Michael F
                >=======
                >^!Info you are on line ^$GetRow$
                >^!If ^$GetRow$=^$GetParaCount$ lastrow Else end
                >
                >:lastrow
                >^!Info this is the end of file
                >^!Goto Exit
                >
                >:End
                >^!Info this is not the last line
              Your message has been successfully submitted and would be delivered to recipients shortly.