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

random access files help

Expand Messages
  • Marc
    Good Morning everybody, I was hoping someone could help me with these random access files I am using. When I use Sequential files the program works fine but
    Message 1 of 5 , Dec 1, 2011
    • 0 Attachment
      Good Morning everybody,
      I was hoping someone could help me with these random access files I am using.
      When I use Sequential files the program works fine but when I use the followinf I can't get a value into the variable.

      code is next>>
      wholefile$ = "c:\currentprog\" + carf$

      open wholefile$ for random as #car Len = 300
      FIELD #car , 50 as enum, 50 as dat1$ , 50 as miles, 50 as ppgal, 50 as tprice, 50 as gallonsfill ' get info from disk
      get #car, 1
      close #car
      rem assignment to array
      for j = 1 to dcount
      entrynum(j) = enum
      dat$(j) = trim$(dat1$)
      mileage(j) = miles
      ppgallon(j) = ppgal
      totalprice(j) = tprice
      galused(j) = gallonsfill


      next j
      for h = 1 to 1 ' display the info
      print #first.tbox11, "Entry Number:";entrynum(h)
      print #first.tbox11, "Date:";trim$(dat$(h))
      print #first.tbox11, "Price per Gallon:"
      #first.tbox11 using("##.###",ppgallon(h))
      print #first.tbox11, "Total Price:$";totalprice(h)
      print #first.tbox11, "Gallons Pumped:";
      #first.tbox11 using( "###.###",galused(h))
      print #first.tbox11, "----------------------------------------"
      next h

      wait
      Thanks,
      Marc Roossi
    • Rod
      I think you have a fundamental problem in understanding what a RAF is. You have no need of creating these additional arrays to hold data. You simply move the
      Message 2 of 5 , Dec 1, 2011
      • 0 Attachment
        I think you have a fundamental problem in understanding what a RAF is. You have no need of creating these additional arrays to hold data. You simply move the data pointer and use the data directly.

        So don't try to create secondary arrays to hold the data use the RAF and don't close it immediately after you open it,

        Try the RAF tutorials again.


        --- In libertybasic@yahoogroups.com, "Marc" <mrossi8888@...> wrote:
        >
        > Good Morning everybody,
        > I was hoping someone could help me with these random access files I am using.
        > When I use Sequential files the program works fine but when I use the followinf I can't get a value into the variable.
        >
        > code is next>>
        > wholefile$ = "c:\currentprog\" + carf$
        >
        > open wholefile$ for random as #car Len = 300
        > FIELD #car , 50 as enum, 50 as dat1$ , 50 as miles, 50 as ppgal, 50 as tprice, 50 as gallonsfill ' get info from disk
        > get #car, 1
        > close #car
        > rem assignment to array
        > for j = 1 to dcount
        > entrynum(j) = enum
        > dat$(j) = trim$(dat1$)
        > mileage(j) = miles
        > ppgallon(j) = ppgal
        > totalprice(j) = tprice
        > galused(j) = gallonsfill
        >
        >
        > next j
        > for h = 1 to 1 ' display the info
        > print #first.tbox11, "Entry Number:";entrynum(h)
        > print #first.tbox11, "Date:";trim$(dat$(h))
        > print #first.tbox11, "Price per Gallon:"
        > #first.tbox11 using("##.###",ppgallon(h))
        > print #first.tbox11, "Total Price:$";totalprice(h)
        > print #first.tbox11, "Gallons Pumped:";
        > #first.tbox11 using( "###.###",galused(h))
        > print #first.tbox11, "----------------------------------------"
        > next h
        >
        > wait
        > Thanks,
        > Marc Roossi
        >
      • Harry
        Marc, Unless I m reading hyou wrong, you aren t understanding and using the FIELD statement correctly. In FIELD #car , 50 as enum, 50 as dat1$ , 50 as miles,
        Message 3 of 5 , Dec 1, 2011
        • 0 Attachment
          Marc,

          Unless I'm reading hyou wrong, you aren't understanding and using the FIELD statement correctly. In

          "FIELD #car , 50 as enum, 50 as dat1$ , 50 as miles, 50 as ppgal, 50 as tprice, 50 as gallonsfill"

          "50" is not the number of records, but the number of bytes in each record devoted to the "field" of the record named after "as". Your statement says that each record in your file is 300 bytes long and will have a numeric value, enum, up to 50 bytes long (that's a REALLY long number, gazillions even), a string, dat1$, up to 50 bytes long, another numeric value, miles, up to 50 bytes long, and so on. When you ask the program to "get #car, 1", it gets the first 300 bytes of the file and tries to evaluate the first 50 of those bytes as a number, the next 50 as a string, and so forth, and puts whatever that turns out to be into the specified fields of that 1st record (enum, dat1$, etc.) But then you close the file, so whatever that interpretation of the 300 bytes turned out to be is lost, and there's nothing to put into your array variables

          My guess is that your sequential files holds 50 records with, sequentially, a number, a string, another number, etc., completing a record, then the next record with those values PRINTed to the file sequentially and so on. That might be got out randomly, but only if each of those elements of the record were each of the same relative length in each record, and you defined your FIELDs relative to the length of each value, not the number of records. What you really have to do to successfully have random input from a file is PUT the records into the file under a defined FIELD statement, and then GET them out using the same defined FIELD statement.

          The other way to do it is to open the file for INPUT, as a sequential file, and retireve the data the same way you PRINTed it. You'd have to choose, on PRINTing, what delimites the various values, one from the other, so that you could correctly get them back, but that's a matter of design.

          Hope that's helpful. Read the help for OPEN Random, Field, Get, and Put, and maybe look at a book that explains it all in detail.

          Harry

          --- In libertybasic@yahoogroups.com, "Marc" <mrossi8888@...> wrote:
          >
          > Good Morning everybody,
          > I was hoping someone could help me with these random access files I am using.
          > When I use Sequential files the program works fine but when I use the followinf I can't get a value into the variable.
          >
          > code is next>>
          > wholefile$ = "c:\currentprog\" + carf$
          >
          > open wholefile$ for random as #car Len = 300
          > FIELD #car , 50 as enum, 50 as dat1$ , 50 as miles, 50 as ppgal, 50 as tprice, 50 as gallonsfill ' get info from disk
          > get #car, 1
          > close #car
          > rem assignment to array
          > for j = 1 to dcount
          > entrynum(j) = enum
          > dat$(j) = trim$(dat1$)
          > mileage(j) = miles
          > ppgallon(j) = ppgal
          > totalprice(j) = tprice
          > galused(j) = gallonsfill
          >
          >
          > next j
          > for h = 1 to 1 ' display the info
          > print #first.tbox11, "Entry Number:";entrynum(h)
          > print #first.tbox11, "Date:";trim$(dat$(h))
          > print #first.tbox11, "Price per Gallon:"
          > #first.tbox11 using("##.###",ppgallon(h))
          > print #first.tbox11, "Total Price:$";totalprice(h)
          > print #first.tbox11, "Gallons Pumped:";
          > #first.tbox11 using( "###.###",galused(h))
          > print #first.tbox11, "----------------------------------------"
          > next h
          >
          > wait
          > Thanks,
          > Marc Roossi
          >
        • Marc
          Thanks everybody. I now understand they are records. Rod could you send me a link in which to study these further since I am using them in my program Thanks,
          Message 4 of 5 , Dec 3, 2011
          • 0 Attachment
            Thanks everybody. I now understand they are records. Rod could you send me a link in which to study these further since I am using them in my program
            Thanks,
            Marc

            --- In libertybasic@yahoogroups.com, "Marc" <mrossi8888@...> wrote:
            >
            > Good Morning everybody,
            > I was hoping someone could help me with these random access files I am using.
            > When I use Sequential files the program works fine but when I use the followinf I can't get a value into the variable.
            >
            > code is next>>
            > wholefile$ = "c:\currentprog\" + carf$
            >
            > open wholefile$ for random as #car Len = 300
            > FIELD #car , 50 as enum, 50 as dat1$ , 50 as miles, 50 as ppgal, 50 as tprice, 50 as gallonsfill ' get info from disk
            > get #car, 1
            > close #car
            > rem assignment to array
            > for j = 1 to dcount
            > entrynum(j) = enum
            > dat$(j) = trim$(dat1$)
            > mileage(j) = miles
            > ppgallon(j) = ppgal
            > totalprice(j) = tprice
            > galused(j) = gallonsfill
            >
            >
            > next j
            > for h = 1 to 1 ' display the info
            > print #first.tbox11, "Entry Number:";entrynum(h)
            > print #first.tbox11, "Date:";trim$(dat$(h))
            > print #first.tbox11, "Price per Gallon:"
            > #first.tbox11 using("##.###",ppgallon(h))
            > print #first.tbox11, "Total Price:$";totalprice(h)
            > print #first.tbox11, "Gallons Pumped:";
            > #first.tbox11 using( "###.###",galused(h))
            > print #first.tbox11, "----------------------------------------"
            > next h
            >
            > wait
            > Thanks,
            > Marc Roossi
            >
          • Stefan Pendl
            ... You can start with a working example at http://basic.wikispaces.com/SimpleDatabaseFrameworkRAF , which you can further change or use as a hint for your
            Message 5 of 5 , Dec 3, 2011
            • 0 Attachment
              Am 03.12.2011 12:00, schrieb Marc:
              > Thanks everybody. I now understand they are records. Rod could you send me a link in which to study these further since I am using them in my program
              > Thanks,
              > Marc
              >

              You can start with a working example at
              http://basic.wikispaces.com/SimpleDatabaseFrameworkRAF , which you can
              further change or use as a hint for your project needs.

              --
              Stefan Pendl
              http://stefanpendl.runbasichosting.com/

              Liberty BASIC 4.04 Pro ... http://www.libertybasic.com/assist.html
              Liberty BASIC 4.04 ....... http://www.libertybasic.com/lb404setup.exe

              Liberty BASIC Community Wiki .............. http://basic.wikispaces.com/
              Liberty BASIC Programmer's Encyclopedia ... http://lbpe.wikispaces.com/
              Liberty BASIC Bug Tracker .................
              http://libertybasicbugs.wikispaces.com/

              Books at http://www.lulu.com/ and http://www.amazon.com/
              Alyce Watson ... APIs for Liberty BASIC
              Carl Gundel .... Beginning Programming with Liberty BASIC

              Windows 7 Home Premium 64-bit SP1
              AMD Turion X2 RM-70 2GHz, 4GB RAM
            Your message has been successfully submitted and would be delivered to recipients shortly.