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

Expand Messages
  • Keith Nance
    Stefan Pendl got me started with the idea of retrieving data from a random access file by opening the file as sequential and reading it into a single variable.
    Message 1 of 3 , May 29 2:25 PM
      Stefan Pendl got me started with the idea of retrieving data from a
      random access file by opening the file as sequential and reading it
      into a single variable. I wanted to be able to open a file that was
      actually created as random and copied to a CD-ROM, and retrieve it's
      information. Unfortunately, this is not the type of sub statement
      that could be used for any random file without a bit of re-adjusting,
      but it works.

      Keith

      'customGet.bas retrieves records from a random
      'file by opening the file as sequential instead
      'of random.

      global RAF$,Holiday$,Month$,Day$
      RAF$ = "holidays.dat"
      gosub [writeRandomFile]

      [loop]
      print ""
      print "Enter 0 to quit."
      input "Enter record number: ";recNum
      if recNum < 1 then end
      call getRecord$ recNum

      print ""
      print "Holiday = ";Holiday$
      print "Month = ";Month$
      print "Day = ";Day$

      goto [loop]

      sub getRecord$ recordNumber
      recordLength = 32
      OPEN RAF$ FOR input AS #ranFile
      numberOfRecords = lof(#ranFile) / recordLength
      dim recordStack$(numberOfRecords)
      line input #ranFile, fileData$
      close #ranFile

      if recordNumber > numberOfRecords then
      recordNumber = numberOfRecords
      end if

      for x = 1 to numberOfRecords
      if x > 1 then
      recordStack$(x) = mid$(fileData$,_
      ((x-1)*recordLength)+1,recordLength)
      else
      recordStack$(x) = mid$(fileData$,_
      (x-1)*recordLength,recordLength)
      end if
      next x

      Holiday$ = mid$(recordStack$(recordNumber),1,20)
      Month$ = mid$(recordStack$(recordNumber),21,10)
      Day$ = mid$(recordStack$(recordNumber),31,2)
      end sub

      [writeRandomFile]
      OPEN RAF$ FOR RANDOM AS #ranFile LEN=32
      FIELD #ranFile,20 AS Holiday$,10 AS Month$,2 AS Day$

      Holiday$ = "New Year's Day"
      Month$ = "January"
      Day$ = "1"
      put #ranFile, 1

      Holiday$ = "Independence Day"
      Month$ = "July"
      Day$ = "4"
      put #ranFile, 2

      Holiday$ = "Halloween"
      Month$ = "October"
      Day$ = "31"
      put #ranFile, 3

      Holiday$ = "Christmas"
      Month$ = "December"
      Day$ = "25"
      put #ranFile, 4

      print "Number of records: 4"
      print ""
      for x = 1 to 4
      get #ranFile, x
      print "Record "; str$(x);": ";Holiday$;Month$;Day$
      next x

      close #ranFile
      return
    • pendl2megabit
      Keith, I am happy that you got it working ;-) There is nothing that can t be done if you can imagine it ;-)) ... Stefan Pendl
      Message 2 of 3 , May 29 2:40 PM
        Keith,
        I am happy that you got it working ;-)
        There is nothing that can't be done if you can imagine it ;-))

        ---
        Stefan Pendl


        > -----Urspr√ľngliche Nachricht-----
        > Von: Keith Nance
        >
        >
        > Stefan Pendl got me started with the idea of retrieving data from a
        > random access file by opening the file as sequential and reading it
        > into a single variable. I wanted to be able to open a file that was
        > actually created as random and copied to a CD-ROM, and retrieve it's
        > information. Unfortunately, this is not the type of sub statement
        > that could be used for any random file without a bit of re-adjusting,
        > but it works.
        >
        > Keith
      • Keith Nance
        ... Stefan, thanks for pointing me in the right direction. Keith
        Message 3 of 3 , May 29 7:36 PM
          --- In libertybasic@yahoogroups.com, "pendl2megabit"
          <pendl2megabit@y...> wrote:
          > Keith,
          > I am happy that you got it working ;-)
          > There is nothing that can't be done if you can imagine it ;-))
          >
          > ---
          > Stefan Pendl
          >

          Stefan, thanks for pointing me in the right direction.

          Keith
        Your message has been successfully submitted and would be delivered to recipients shortly.