Announcement

Collapse
No announcement yet.

problems inserting records into an array

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

  • problems inserting records into an array

    I'm porting a program from windows to dos (yes, I know, odd, but true) I've got most of it compiling, after writing a couple functions to replace missing dos ones, to keep source code changes to a minimum.
    However, my current problem is that I can't get array insert to work properly.
    I'm getting an error 420, Relational operator expected.
    I have an array of records, and I'm trying to insert a record into the array.
    The line of code in question currently reads as:
    Code:
    array insert varlist(varindex),temp3
    Temp3 is a record of a user defined type.
    Code:
    type var1
    vname as string*40
    vvalue as string*40
    end type
    The original lines of code from the windows code was:
    Code:
    varlist(varindex).vname = temp1
    varlist(varindex).vvalue = temp2
    On windows, the values are inserted directly into the array automatically.
    On dos, apparently, I need to setup the record first, then insert it as a complete set.
    I'm getting errors which seem to indicate I need to define the type of item I'm inserting.
    Normally, I'd just add a $ % #, or whatever is necessary to identify the datatype being inserted into the array. However, in this case, since it's a record, there isn't really any type identifier (that I know of anyway), so what can I do here to get this record inserted into the array?
    Any suggestions/assistance would be much appreciated.
    http://www.softcon.com]


    for hosting/internet


    access.

  • #2
    Original code is not doing an ARRAY INSERT as far as I can tell, it's simply doing a replace of the element. Of course, what's not shown may make a liar of me.

    But bottom line, ARRAY INSERT works the same on PB/DOS as it does on PB/Windows. In either case, the replacement element (temp3) will be inserted "as it currently exists" meaning if it ain't been initialized with the correct values, it will go in in its default condition, which depends on its scope and prior use in the program and/or procedure. (Code not shown).

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      [QUOTE=Michael Mattias;305371]Original code is not doing an ARRAY INSERT as far as I can tell, it's simply doing a replace of the element. Of course, what's not shown may make a liar of me.

      But bottom line, ARRAY INSERT works the same on PB/DOS as it does on PB/Windows. In either case, the replacement element (temp3) will be inserted "as it currently exists" meaning if it ain't been initialized with the correct values, it will go in in its default condition, which depends on its scope and prior use in the program and/or procedure. (Code not shown).

      But, this is my problem, the array insert is not working, I get an error (mentioned above) when trying to do the insert.
      In the windows program, the array is initially dimensioned to 10 records, then another 10 records are added each time it runs out of usable records. Are you saying the same behavior is possible under dos, and therefore no array insert is necessary?
      I was unable to get this to behave, though I can certainly try again using the same approach used under windows, (I was under the impression you *had* to do an array insert to get the record in, but if modifying existing blank entries works, then I'll just do that, it will make things easier.
      But, I'm still puzzled why the array insert gives an error, but I guess it's not important if the other approach works.
      http://www.softcon.com]


      for hosting/internet


      access.

      Comment


      • #4
        the array is initially dimensioned to 10 records then another 10 records are added each time it runs out of usable records. Are you saying the same behavior is possible under dos, and therefore no array insert is necessary?
        Yes.

        REDIM PRESERVE is used to change the bounds of an array without discarding the existing elements.

        ARRAY INSERT/DELETE are used to "shift" elements within the current bounds, discarding the deleted element (ARRAY DELETE) or the element at the current upper bound (ARRAY INSERT).

        PB-DOS or PB-Windows, works the same. So, do you want to insert elements within the currrent array bounds or resize the array to hold additional elements?

        Under PB/DOS you have some restrictions when the total memory requirements for all array elements exceeds 128Kb, but other than that the code should be identical.

        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          [QUOTE=Michael Mattias;305383]Yes.

          REDIM PRESERVE is used to change the bounds of an array without discarding the existing elements.

          ARRAY INSERT/DELETE are used to "shift" elements within the current bounds, discarding the deleted element (ARRAY DELETE) or the element at the current upper bound (ARRAY INSERT).

          PB-DOS or PB-Windows, works the same. So, do you want to insert elements within the currrent array bounds or resize the array to hold additional elements?

          Under PB/DOS you have some restrictions when the total memory requirements for all array elements exceeds 128Kb, but other than that the code should be identical.

          I'm aware of all of this, but several things are an issue here.
          1. code is not identical, the windows code for adding records to the array did not work, it gave an error.
          2. adding the values to the record itself work fine, inserting that record into the array does not.
          3. trying to modify the entries in the array directly doesn't work either.


          Let me try again to explain what's happening (or not as the case may be)

          The array is made up of records.
          The records are made up of two string variables, both of which are 40 chars long.
          As mentioned before, when trying to insert a record into the array, pbdos gives me an error (already reported above), and I also get an error when trying to assign values to the record in an empty array as well.
          The windows code was something like this: (don't have it here, so can't copy/paste)
          Code:
          varlist(varindex).vname = temp1
          varlist(varindex).vvalue = temp2
          This code does not work in dos, it gives an error saying it's expecting a comma where the period is placed.
          Changing the code to read
          Code:
          temp3.vname = temp1
          temp3.vvalue = temp2
          varlist(varindex) = temp3
          sdoesn't work either.
          In this case, temp3 has been identified as type var1, which is what varlist is an array of (I.E. varlist is an array of var1 types)
          I'm obviously missing something, but I can't for the life of me figure out what.
          Why is the array insert giving an error?
          Why does the varlist(varindex).varname assignment give an error, what's the syntax for assigning a value under dos (it's not identical to the windows syntax as already mentioned above), so what is the proper syntax then?
          The dos help seems to indicate that at least one of these approaches should work, and as far as I can tell, it should, but it's expecting a type identifier such as $ # % or something else to tell it what kind of element the temp3 is.
          And, another (slightly) related question.
          Why do I need to identify some variables as strings and sometimes not.
          Code:
          temp1 as local string, temp2 as local string
          temp1 = "hello"
          temp1 = temp2
          sometimes works, and sometimes doesn't. Sometimes it's requiring the $ symbols on the temp1 and temp2 identifiers, but not always.
          Anyone know why this is, and how to make it consistent?


          http://www.softcon.com]


          for hosting/internet


          access.

          Comment


          • #6
            If it's this statement here causing a compile-time error....
            Code:
            array insert varlist(varindex),temp3
            ...and temp3 is the same datatype as array varlist() (insufficient code shown), then you have a support issue and should contact PB support, because that should work to insert "temp3' as the new "varindex-th" element of "varlist()", shifting all element numbers greater than or equal to varindex "up by one", discarding the element at varlist (UBOUND(varlist)).

            MCM
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Version of PB/DOS being used

              I'm not sure about something. What version of PB/DOS are you using for the rollback? (I'm wanting to go in the other direction.) I had the same problem and asked PB Support. I'm using PB/DOS Version 3.0c and was told that the ARRAY statement does not support UDTs. That could be your whole problem. You might have to go to PB/CC. An extreme solution would be to convert the UDT to a flex string, add the element, then convert back. The ARRAY statement should work normally when the array is of a PB predetermined type (BYTE, WORD, INTEGER, etc.) I'm not sure about Version 3.5. I was told PB/CC (and PB/Win) had added a custom feature to the ARRAY statement that would support UDTs. Just something else to consider.

              Comment


              • #8
                compiles fine with PB/DOS 3.5
                Code:
                TYPE FOO
                   A AS STRING * 40 
                   B AS STRING * 40 
                END TYPE
                FUNCTION  TESTER() AS INTEGER    
                 REDIM F (10) AS FOO  
                 DIM Foo1 AS FOO  
                 ARRAY INSERT F(5), Foo1  
                END FUNCTION
                Can't tell if it's working. MY PB/DOS stuff is in some kind of security lockdown on my system and I can't unset the 'read only' attribute in the working folder.

                But 'compile' gets as far as "desitnation file write error" which means the compiler liked it and TRIED to write the EXE...

                MCM
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  a simple test
                  Code:
                  TYPE FOO
                     A AS STRING * 4
                     B AS STRING * 4
                  END TYPE
                  FUNCTION  TESTER() AS INTEGER
                     REDIM F (10) AS FOO
                     DIM Foo1 AS FOO
                     F(10).A = "xxxx"
                     F(10).B = "XXXX"
                     PRINT F(10)
                     Foo1.A = "alfa"
                     Foo1.B = "beta"
                     ARRAY INSERT F(5), Foo1
                  END FUNCTION
                  DIM F(9) AS FOO
                  FOR I = 0 TO 9
                     J = I+48
                     F(I).A = STRING$(4,J)
                     F(I).B = STRING$(4,CHR$(J+16))
                  NEXT I
                  CLS
                  FOR I = 0 TO 9
                     PRINT I;">";F(I).A;F(I).B
                  NEXT I
                  PRINT : tester : PRINT
                  FOR I = 0 TO 10
                     PRINT I;">";F(I).A;F(I).B
                  NEXT I
                  END
                  a wrong result
                  0 >[email protected]@@@
                  1 >1111AAAA
                  2 >2222BBBB
                  3 >3333CCCC
                  4 >4444DDDD
                  5 >5555EEEE
                  6 >6666FFFF
                  7 >7777GGGG
                  8 >8888HHHH
                  9 >9999IIII

                  xxxxXXXX

                  0 >[email protected]@@@
                  1 >1111AAAA
                  2 >2222BBBB
                  3 >3333CCCC
                  4 >4444DDDD
                  5 >5555EEEE
                  6 >6666FFFF
                  7 >7777GGGG
                  8 >8888HHHH
                  9 >9999IIII
                  10 >yz
                  ]
                  "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

                  Comment


                  • #10
                    Invalid test. F() is not shared with function TESTER, which uses a LOCAL array.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Sure!
                      Code:
                      TYPE FOO
                         A AS STRING * 4
                         B AS STRING * 4
                      END TYPE
                      DIM F(9) AS FOO
                      FOR I = 0 TO 9
                         J = I+48
                         F(I).A = STRING$(4,J)
                         F(I).B = STRING$(4,CHR$(J+16))
                      NEXT I
                      CLS
                      FOR I = 0 TO 9
                         PRINT I;">";F(I).A;F(I).B
                      NEXT I
                      PRINT
                      
                      REDIM PRESERVE F(10)
                      DIM Foo1 AS FOO
                      Foo1.A = "alfa"
                      Foo1.B = "beta"
                      ARRAY INSERT F(5), Foo1
                      PRINT
                      
                      FOR I = 0 TO 10
                         PRINT I;">";F(I).A;F(I).B
                      NEXT I
                      END
                      result
                      0 >[email protected]@@@
                      1 >1111AAAA
                      2 >2222BBBB
                      3 >3333CCCC
                      4 >4444DDDD
                      5 >5555EEEE
                      6 >6666FFFF
                      7 >7777GGGG
                      8 >8888HHHH
                      9 >9999IIII

                      0 >[email protected]@@@
                      1 >1111AAAA
                      2 >2222BBBB
                      3 >3333CCCC
                      4 >4444DDDD
                      5 >alfabet <<<< ????
                      6 >5555EEEE
                      7 >6666FFFF
                      8 >7777GGGG
                      9 >8888HHHH
                      10 >9999IIII
                      "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

                      Comment


                      • #12
                        Same results here but...

                        that triggers a memory.... I seem to recall losing a character on ARRAY INSERT of UDT arrays like this was a known bug in some version(s?) of PB/DOS

                        Mine:
                        Code:
                        09/07/1998  11:44 AM           350,731 PB.EXE
                        Contact support.
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          If so, my copy has that bug!
                          Code:
                          19/12/1997  03:50           350.827 PB.EXE
                          Last edited by Arthur Gomide; 25 Dec 2008, 03:44 PM.
                          "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

                          Comment


                          • #14
                            Fortunately, there is a VERY simple workaround:
                            Code:
                            TYPE var1
                                vname as string*40
                                vvalue as string*40
                            [B][COLOR="Red"]    unused as integer [/COLOR][/B]
                            end type
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Another solution for circumvent the bug:
                              Code:
                              TYPE FOO
                                 A AS STRING * 4
                                 B AS STRING * 4
                              END TYPE
                              ...
                              ARRAY INSERT F(5) : REM , Foo1
                              
                              DEF SEG = VARSEG(F(5))
                              POKE$ VARPTR(F(5)), Foo1
                              DEF SEG
                              ...
                              or only
                              Code:
                              TYPE FOO
                                 A AS STRING * 4
                                 B AS STRING * 4
                              END TYPE
                              ...
                              ARRAY INSERT F(5) : REM , Foo1
                              F(5) = Foo1
                              ...
                              Last edited by Arthur Gomide; 27 Dec 2008, 04:50 AM.
                              "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

                              Comment

                              Working...
                              X