Announcement

Collapse
No announcement yet.

FIELD variable problem

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

  • FIELD variable problem

    Hi All,

    Over the last 20 odd years I've developed a suite of programmes for our business, which handles stock, sales etc.etc. Buy we're now getting the absolute limit of what's possible with QBX Basic 7.1PDS, in that I need large arrays of numbers and strings, whilst it's possible to do everything I want with Basic, I'm spending more and more time just 'getting around' the limitations that I'm coming up against, so I've decided that after owning Powerbasic for nearly 6 years, I'm going to have to bite the bullet and convert all my code.

    When I've looked at this in the past, the biggest problem for me was that file handling required Type/End type - the prospect of having to recode ALL my file handling fills me with dread. But I now notice that in the later incarnations (version 4 onwards?) that you can use FIELD, but have to declare the variables used in the field statement as field variables (which I can live with), but I have FIELD statements that have subscripted variables in them.

    Is there an easy way to go about converting these, as PBCC complains that the variables are either not dimensioned, or not field variables, dependant on where or if I dimension the string array .

    Basically my code is currently:-

    FIELD #Filenum%, 10 as a$, 4 as b$, 4 as c$(1), 4 as c$(2), 4 as c$(3), 4 as c$(4), 10 as d$


    I realise I could change this to:-

    DIM C$(4)
    FIELD #Filenum%,10 as a$, 4 as b$, 16 as c$, 10 as d$
    and then use a FOR/NEXT loop to populate c$() EG:-

    FOR a%=1 to 4
    c$(a%)=CVS(MID$(c$,((a%-1)*4)+1,4)
    next a%

    But I'd much prefer it if there was some way to allow Field variables to cope with subscripts.

    I hope I've explained this well enough for you to understand - have I missed something fundamental?

    Thanks in advance, John

  • #2
    Have you tried using field variables?

    Dim c(4) as FIELD

    Bob Zale
    PowerBASIC Inc.

    Comment


    • #3
      I had never played with FIELD vars before, but you got me to try it... and this works as expected in PB/WIN 8.03

      Code:
      FUNCTION TestField () AS LONG
          
         LOCAL B() AS FIELD, s AS STRING, I AS LONG, W AS STRING
          
         REDIM B(3)
         
         S = "ABBCCC"
         
         FIELD S, 1 AS B(1), 2 AS b(2), 3 AS B(3)
         
         W =   USING$  ( "1 '&'  2 '&'  3 '&'",  B(1), B(2), B(3))
         
         MSGBOX W
         
       
      END FUNCTION
      
      FUNCTON PbMain() AS LONG
        CALL TestField
      END FUNCTION
      MCM
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        With FIELD vars now available, I guess I can drop my NFS for Flex-strings in the Windows compilers, huh?

        (Yeah, like I thought the idea was going anywhere after six years and 3 versions since I first suggested it).
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Fields

          John,

          Here is the the way I have been using FIELD

          Code:
          DIM MyField AS FIELD: REDIM MyData(256) AS LONG 
           OPEN "MyFile" for RANDOM ACCESS READ WRITE SHARED AS #1 LEN=1024
           GET #1,1:  w=1
             FOR x=1 to 256
             MyData(x)=CVL(MID$(MyField,w,4)): w=w+4
           NEXT
           CLOSE #1
          You can put any combinations you want in one FIELD and by using arrays you can have huge amounts of data with very little typing.
          I also use that trick for big alpha text with comma separators and use PARSE to read them back in arrays
          Last edited by Guy Dombrowski; 6 May 2008, 11:27 AM.
          Old QB45 Programmer

          Comment


          • #6
            Wow!

            Now that's really impressive - I leave a message about some spurious old Basic PDS 7.1 FIELD format, and within the hour I've got several sensible replies.

            Thanks Bob (yes, it works fine, that must be just about the only combination of field/dim etc. I'd failed to try! - must get another printed manual to pore over properly).

            Many thanks to everyone else for jumping in so quickly to my aid.

            Best regards, John

            Comment


            • #7
              Field array

              Bob,

              Thanks for your suggestion about field array as I did not know it could be done that way.

              I have re-written my former exemple using your trick
              Code:
              DIM MyBuffer(256) AS FIELD: REDIM MyData(256)
               OPEN "MyFile" FOR RANDOM ACCESS READ WRITE SHARED AS #1 LEN=1024
               GET#1,1
               FOR x=1 TO 256: MyData(x) = CVL(MyBuffer(x)): NEXT
               CLOSE #1
              Is is much neater and enable to get rid of the MID$ command.
              I will now use a mix of FIELD depending on the kind of data I need.
              But to read old mixed up files with differents data type, the one FIELD trick is the way to go.
              Last edited by Guy Dombrowski; 6 May 2008, 11:43 AM.
              Old QB45 Programmer

              Comment


              • #8
                You might find this interesting. 4 functions using FIELD in my posting.

                http://www.powerbasic.com/support/pb...ighlight=FIELD

                Comment


                • #9
                  > Is is much neater and enable to get rid of the MID$ command...

                  I almost hate to break your heart, but this gets you almost to the exact same place..
                  Code:
                   REDIM MyData (255) AS LONG
                   OPEN "MyFile" FOR BINARY ACCESS READ WRITE SHARED AS #1 
                   GET #1, ,MyData()   ' get 256 long integer elements
                   CLOSE #1
                  This ends up with data at array subscripts 0-255 instead of 1-256 and no null element zero.

                  (Using zero-based arrays with one-based data makes it a tad funky to use GET with the 'array' option).
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    I almost hate to break your heart.....

                    Michael,

                    On the contrary, I think you like it very much.

                    As for Binary access, I never used it as in the old slow computer days, the SEEK took too long if you had big files and I got used to the Random Access way.
                    Also, locking selected fields instead of the whole file was much simpler for multi-user programs.

                    Maybe, today, it could be a better way to read and write data.
                    Any benchmark on that subject ?
                    Old QB45 Programmer

                    Comment


                    • #11
                      Guy --

                      No difference in speed between Binary and Random. Identical.

                      Bob Zale
                      PowerBASIC Inc.

                      Comment


                      • #12
                        Binary access

                        Bob,

                        You are so right. I made a few quick tests and the speed is the same.

                        I also discovered with Michael example that you don't need to use MKL$ and CVL$ to Write and Read the data.
                        Fantastic, I will be using that technique from now on.

                        You can also LOCK any array items instead of the whole field.

                        Michael, you have my permission to break my heart anytime you teach me that kind of neat tricks.
                        Old QB45 Programmer

                        Comment


                        • #13
                          >that kind of neat tricks.

                          It's a "trick" when someone else does it.

                          As soon as you do it yourself it's a "technique."
                          Michael Mattias
                          Tal Systems (retired)
                          Port Washington WI USA
                          [email protected]
                          http://www.talsystems.com

                          Comment

                          Working...
                          X