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

Help with Infinite Loops and STR$

Expand Messages
  • Gordon Sweet
    Talking about infinite loops, why does my Windows XP setup go into one if I accidentally or otherwise attempt to use zero with PUT #3, 0 in the Random Access
    Message 1 of 8 , Nov 1, 2003
    • 0 Attachment
      Talking about infinite loops, why does my Windows XP setup go into one if I accidentally or otherwise attempt to use zero with PUT #3, 0 in the Random Access demo below. The only way I can stop it is the drastic step of using the RESET button on the console, to finish up with a TEST.RAN file of many Mb

      Also why does the Random Access file below refuse to recognise A$ = str$(z), thus preventing us using PUT #3, 1 to keep an essential record of the number of data entries. How else can we store the COUNT to prevent an Exceeding the end of File error if anyone attempt to read beyond the last entry. I doubt if we can mix Strings with variables in the FIELD statement.

      nomainwin
      notice "Sequential test file ok"
      OPEN "test.dat" FOR output AS #3
      for z = 1 to 4
      A$ = str$(z)
      #3 A$
      print A$
      next z
      close #3
      run "notepad.exe test.dat", restore
      kill "test.dat"

      notice "Random Access test file ok"
      OPEN "test.ran" FOR RANDOM AS #3 LEN=10
      FIELD #3,10 AS A$
      for z = 1 to 4
      A$ = str$(z)
      PUT #3, z
      print A$
      next z
      close #3
      run "notepad.exe test.ran", restore
      kill "test.ran"


      [Non-text portions of this message have been removed]
    • J. Brossman
      ... Hi Gordon First I don t believe you can use record number 0 in a random file, only an array. This is what cause your machine to crash. Second, you can
      Message 2 of 8 , Nov 1, 2003
      • 0 Attachment
        Gordon Sweet wrote:

        >Talking about infinite loops, why does my Windows XP setup go into one if I accidentally or otherwise attempt to use zero with PUT #3, 0 in the Random Access demo below. The only way I can stop it is the drastic step of using the RESET button on the console, to finish up with a TEST.RAN file of many Mb
        >
        >Also why does the Random Access file below refuse to recognise A$ = str$(z), thus preventing us using PUT #3, 1 to keep an essential record of the number of data entries. How else can we store the COUNT to prevent an Exceeding the end of File error if anyone attempt to read beyond the last entry. I doubt if we can mix Strings with variables in the FIELD statement.
        >
        >

        Hi Gordon

        First I don't believe you can use record number 0 in a random file, only
        an array. This is what cause your machine to crash. Second, you can
        mix alpha and numeric in a Random file as shown by the following code.
        Third, for some reason, notepad doesn't show the contents of a random
        file correctly but wordpad does. In a random file, you use the lof
        command to find the end of file. LOF is the number of bytes in the file
        so dividing by the length of each record gives you the number of records
        in the file. Finally, for some reason, if I attempt to kill the
        text.ran file immediately after the run "write.exe c:\test.ran" line,
        wordpad says it can't find the file.

        Random access files are so versatile, I hardly ever use a sequential
        file except for an initialization file .

        notice "Random Access test file ok"
        OPEN "c:\test.ran" FOR RANDOM AS #3 LEN=15
        FIELD #3,10 AS A$, 5 AS B
        for z = 1 to 4
        A$ = str$(z)
        B=z
        PUT #3, z
        next z
        lastrecord=lof(#3)/15 '15 is the length of each record
        for x=1 to lastrecord
        get #3,x
        print A$;B
        next
        close #3
        run "write.exe c:\test.ran"


        --
        Jim & Jan Brossman - Sno-Dragon Siberians - Durango, Colorado
        Show Secretary Web Site - http://users.sisna.com/jbross/showsec.html
        Brossman Family Tree Web Site - http://users.sisna.com/jbross
      • Bill Beasley
        ... Stopping program through task manager resulted in a 0 byte file. Program errored out at runtime. I suspect a pointer in the overlapped structure is getting
        Message 3 of 8 , Nov 1, 2003
        • 0 Attachment
          > -----Original Message-----
          > From: Gordon Sweet [mailto:gordon@...]
          > Sent: Saturday, November 01, 2003 2:06 AM
          > To: libertybasic@yahoogroups.com
          > Subject: [libertybasic] Help with Infinite Loops and STR$
          >
          >
          > Talking about infinite loops, why does my Windows XP setup go
          > into one if I accidentally or otherwise attempt to use zero with
          > PUT #3, 0 in the Random Access demo below. The only way I can
          > stop it is the drastic step of using the RESET button on the
          > console, to finish up with a TEST.RAN file of many Mb

          Stopping program through task manager resulted in a 0 byte file.
          Program errored out at runtime. I suspect a pointer in the overlapped
          structure is getting stepped on and the small talk routine isn't handling it
          correctly. Possibly Carl could do something with this if you let him know.
          Since the help file says "Records in RANDOM files are numbered beginning at
          1, not 0", it's sort of like telling the doctor, "It only hurts when...".
          Don't do that.


          > Also why does the Random Access file below refuse to recognise A$
          > = str$(z), thus preventing us using PUT #3, 1 to keep an
          > essential record of the number of data entries.

          It worked fine here using LB4.0beta. Record 1 contained the "1" character
          padded with spaces to a record length of 10. With random access files, you
          don't have to keep track of the number of records. it's a simple matter to
          determine the number of records with lof(file)/recordlength because each
          record is the same length and the eof pointer is moved around based on
          recordlength.

          > How else can we
          > store the COUNT to prevent an Exceeding the end of File error if
          > anyone attempt to read beyond the last entry. I doubt if we can
          > mix Strings with variables in the FIELD statement.

          something like this: (pseudo code, won't actually run)
          while count > 0 and < lof(file)/recordlength get file, count

          >
          > nomainwin
          > notice "Sequential test file ok"
          > OPEN "test.dat" FOR output AS #3
          > for z = 1 to 4
          > A$ = str$(z)
          > #3 A$
          > print A$
          > next z
          > close #3
          > run "notepad.exe test.dat", restore
          > kill "test.dat"
          >
          > notice "Random Access test file ok"
          > OPEN "test.ran" FOR RANDOM AS #3 LEN=10
          > FIELD #3,10 AS A$
          > for z = 1 to 4
          > A$ = str$(z)
          > PUT #3, z
          > print A$
          > next z
          > close #3
          > run "notepad.exe test.ran", restore
          > kill "test.ran"

          By the way, your test programs tell me they were successful before they even
          run and your print A$ statements will never show because of the nomainwin
          statement. Commenting out the two kill statements and looking at the
          resultant files with a hex viewer showed them to be constructed just as they
          should be. The sequential file had character followed by linefeed/carriage
          return and the random access file had character followed by padding spaces.

          Have fun.

          Regards,

          Bill Beasley
        • Bill Beasley
          ... In this case, notepad works because the file contents are displayable. The sequential file looked like this: (as it should) 1 2 3 4 And the random file
          Message 4 of 8 , Nov 1, 2003
          • 0 Attachment
            > -----Original Message-----
            > From: J. Brossman [mailto:jbross@...]
            > Sent: Saturday, November 01, 2003 9:44 AM
            > To: libertybasic@yahoogroups.com
            > Subject: Re: [libertybasic] Help with Infinite Loops and STR$
            >
            > Third, for some reason, notepad doesn't show the contents of a random
            > file correctly but wordpad does.

            In this case, notepad works because the file contents are displayable. The
            sequential file looked like this: (as it should)
            1
            2
            3
            4
            And the random file looked like this:
            1 2 3 4
            again as it should.

            >Finally, for some reason, if I attempt to kill the
            > text.ran file immediately after the run "write.exe c:\test.ran" line,
            > wordpad says it can't find the file.

            I'd guess that the "text.ran" file was created in your LB default directory
            since at it's creation a short file name was used. Your run statement is
            pointing to the C:\ root directory. I suspect your default LB directory is
            probably around /settings...//program files/lbxxx/ etc.

            Regards,

            Bill Beasley
          • J. Brossman
            ... Bill If I didn t define the directory in all the statements, wordpad didn t know where the file was. Try running the following code as is then remark out
            Message 5 of 8 , Nov 1, 2003
            • 0 Attachment
              Bill Beasley wrote:

              >>Finally, for some reason, if I attempt to kill the
              >>text.ran file immediately after the run "write.exe c:\test.ran" line,
              >>wordpad says it can't find the file.
              >>
              >>
              >
              >I'd guess that the "text.ran" file was created in your LB default directory
              >since at it's creation a short file name was used. Your run statement is
              >pointing to the C:\ root directory. I suspect your default LB directory is
              >probably around /settings...//program files/lbxxx/ etc.
              >
              Bill
              If I didn't define the directory in all the statements, wordpad didn't
              know where the file was. Try running the following code as is then
              remark out the line for wordpad and unremark the line for notepad.
              Interestingly, notepad can read my version but wouldn't read Gordan's
              version correctly.

              notice "Random Access test file ok"
              OPEN "c:\test.ran" FOR RANDOM AS #3 LEN=15
              FIELD #3,10 AS A$, 5 AS B
              for z = 1 to 4
              A$ = str$(z)
              B=z
              PUT #3, z
              next z
              z=lof(#3)/15 '15 is the length of each record
              for x=1 to z
              get #3,x
              print A$;B
              next
              close #3
              'run "notepad.exe c:\test.ran
              run "write.exe c:\test.ran"
              kill "c:\test.ran"





              --
              Jim & Jan Brossman - Sno-Dragon Siberians - Durango, Colorado
              Show Secretary Web Site - http://users.sisna.com/jbross/showsec.html
              Brossman Family Tree Web Site - http://users.sisna.com/jbross



              [Non-text portions of this message have been removed]
            • Ken Lewis, Sr.
              ... From: Gordon Sweet ... have you tried A$=str$(val(z)) if this isn t it then perhaps z should be Z Ken Lewis, Sr.
              Message 6 of 8 , Nov 1, 2003
              • 0 Attachment
                ----- Original Message -----
                From: "Gordon Sweet" <gordon@...>

                > A$ = str$(z)

                have you tried A$=str$(val(z))

                if this isn't it then perhaps 'z' should be 'Z'

                Ken Lewis, Sr.
              • Bill Beasley
                ... Jim, Try running this code unchanged. It should run just fine with both notepad and wordpad finding and displaying the file. The file will have been
                Message 7 of 8 , Nov 1, 2003
                • 0 Attachment
                  > -----Original Message-----
                  > From: J. Brossman [mailto:jbross@...]
                  > Sent: Saturday, November 01, 2003 11:59 AM
                  > To: libertybasic@yahoogroups.com
                  > Subject: Re: [libertybasic] Help with Infinite Loops and STR$
                  >
                  > If I didn't define the directory in all the statements, wordpad didn't
                  > know where the file was. Try running the following code as is then
                  > remark out the line for wordpad and unremark the line for notepad.
                  > Interestingly, notepad can read my version but wouldn't read Gordan's
                  > version correctly.
                  >
                  > notice "Random Access test file ok"
                  > OPEN "c:\test.ran" FOR RANDOM AS #3 LEN=15
                  > FIELD #3,10 AS A$, 5 AS B
                  > for z = 1 to 4
                  > A$ = str$(z)
                  > B=z
                  > PUT #3, z
                  > next z
                  > z=lof(#3)/15 '15 is the length of each record
                  > for x=1 to z
                  > get #3,x
                  > print A$; B
                  > next
                  > close #3
                  > 'run "notepad.exe c:\test.ran
                  > run "write.exe c:\test.ran"
                  > kill "c:\test.ran"
                  >

                  Jim,

                  Try running this code unchanged. It should run just fine with both notepad
                  and wordpad finding and displaying the file. The file will have been created
                  in the default directory. It will be opened from the default directory. The
                  reason wordpad is not finding the file in your version, and my version if
                  you uncomment the "kill" line, is the overhead time to open wordpad is too
                  long. The file will have been deleted before wordpad looks for it in the
                  default directory. Then uncomment the "kill" line and you'll get the "File
                  not found" error.

                  '----- Code Starts -----
                  notice "Random Access test file ok"
                  OPEN "test.ran" FOR RANDOM AS #3 LEN=15
                  FIELD #3,10 AS A$, 5 AS B
                  for z = 1 to 4
                  A$ = str$(z)
                  B=z + 90
                  PUT #3, z
                  next z
                  z=lof(#3)/15 '15 is the length of each record
                  for x=1 to z
                  get #3,x
                  print A$;B
                  next
                  close #3
                  print DefaultDir$
                  run "notepad.exe test.ran"
                  run "write.exe test.ran"
                  ' kill "test.ran"
                  end
                  '----- Code Ends -----

                  Regards,
                  Bill Beasley
                • Gordon Sweet
                  Thanks for everyone s Help. I must admit when I wrote DB programs in the past using Random Access in Qbasic, and earlier Basic, I employed the simple step of
                  Message 8 of 8 , Nov 2, 2003
                  • 0 Attachment
                    Thanks for everyone's Help. I must admit when I wrote DB programs in the past using Random Access in Qbasic, and earlier Basic, I employed the simple step of using a separate Sequential file to keep details of the sizes and titles of all fields, especially where the user is allowed to chose these such as in Microsoft's Access etc. Gordon Sweet

                    [Non-text portions of this message have been removed]
                  Your message has been successfully submitted and would be delivered to recipients shortly.