Announcement

Collapse
No announcement yet.

Milti DIM arrays??

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

  • Milti DIM arrays??

    Arrays. I am starting this new post from one I posted "Control Set Test????...." , to learn about mult dim arrays with the help of members.

    On the last posting I did I was shown an example on multi array, by Gösta for my test program.


    Problem, I plugged in the sample code and got error 414. Looked up format for "GLOBAL Label_Addresses(5, 1 TO 10)" function and could not see anything wrong.

    Attached is sample program.


    I hope to develope this program using all the functions available with the multi dim array function.
    Attached Files
    Robert

  • #2
    GLOBAL does not create the array. You still must DIM the array somewhere in one of your procedures, preferably PBMAIN. Speaking of which, you need to have either PBMAIN or WINMAIN somewhere in there for Windows to run your application.

    Be careful with the global array. It can be modified from within any procedure in your code.

    Stan
    Do not go quiet into that good night,
    ... Rage, rage against the dark.

    Comment


    • #3
      I don't think the problem is failure to DIM/REDIM....
      414 ")" expected - The statement's syntax requires a right parenthesis ()). The compiler encountered text or symbols where a right parenthesis was expected, or a parenthesis is missing.
      This error means, uh, what it says.

      Code:
        GLOBAL Label_Addresses(5, 1 TO 10) '6 rows, 10 columns       ,<<<<<<<<< ERROR 414 <<<<<<
      Well, it's missing an "AS datatype" but that didn't help, I still get the error.

      :doh: .... Wait a minute..... you don't specify subscripts in a GLOBAL statement. When the compiler wanted ")" it's because it did not want subscripts; The GLOBAL|LOCAL|STATIC statement wants only a set of empty parens.

      You need two statements.
      Code:
        GLOBAL Label_Addresses() AS LONG
        REDIM  Label_Addresses(5, 1 TO 10)  '6 rows, 10 columns
      Now you have an undeclared variable error later in your source code, but you can solve that.

      I think you will also have a maintenance nightmare with all those GLOBAL statements buried deep in the code within procedures, but we're all entitled to our own dreams.

      So I guess the the problem would have been a lack of a DIM/REDIM, after all.. once you got past the syntax error in the GLOBAL statement

      MCM
      Last edited by Michael Mattias; 24 Jul 2008, 09:04 AM.
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Originally posted by Michael Mattias View Post
        ....
        So I guess the the problem would have been a lack of a DIM/REDIM, after all.. once you got past the syntax error in the GLOBAL statement

        MCM
        Does this mean we actually agreed on something after examining the code in question? Maybe there's hope for me too.

        Stan
        Do not go quiet into that good night,
        ... Rage, rage against the dark.

        Comment


        • #5
          The error in question was on the GLOBAL statement, meaning "No [RE]DIM" was NOT this particular problem's solution.

          However, "No [RE]DIM statement " would have been the correct solution to what would have been Mr. Alvarez' followup post had I not preempted it.

          Therfore you have more than hope: you have prescience.


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

          Comment


          • #6
            Originally posted by Robert Alvarez View Post
            Arrays. I am starting this new post from one I posted "Control Set Test????...." , to learn about mult dim arrays with the help of members.

            On the last posting I did I was shown an example on multi array, by Gösta for my test program.
            ...

            I hope to develope this program using all the functions available with the multi dim array function.
            The fault was mine Robert. When I gave the example I didn't run it first. All I did was type it to to demonstrate the principle of multi dimentional arrays. I didn't check to see if it would run.

            Code:
            'corrections Bolded
            'replace all of the above with this:
              GLOBAL Label_Addresses() As Long '6 rows, 10 columns       ,<<<<<<<<< ERROR 414 <<<<<<
             Local Row&, Column&, Counter&
              DIM Label_Addresses(5, 1 TO 10)
              Counter = 200 'start addresses from here
              FOR Row = 0 TO 5
                 FOR Column = 1 TO 10
                   INCR Counter
                   Label_Addresses(Row, Column) = Counter
                 NEXT Column
              NEXT Row
            At this stage, I wouldn't worry about where a Global is located (or even whether to use one or not). Just concentrate on the concept of multi dimensional arrays. Once it clicks (and it will pretty quickly I bet) that other stuff can come later.

            ========================================
            "A lie is terminological inexactitude."
            Churchill
            ========================================
            Last edited by Gösta H. Lovgren-2; 24 Jul 2008, 11:21 PM. Reason: yet more corrections
            It's a pretty day. I hope you enjoy it.

            Gösta

            JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
            LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

            Comment


            • #7
              a few days ago update this posting but it did not happen. must have click wrong button.
              thanks everyone for you response.


              Gösta H. Lovgren-2

              I have update my test program and got the "SUB Setup_Arrays" working.
              After that worked, I attempted to do the RC() array for the data to read from disk file to screen display.
              Results CRASH. window does not like something in my program after I edited code for RC() array.
              PB does not even display an error code.

              I read my PB/DLL book on array and dim for a solution. Always have trouble understanding option or no options
              with () {} []. (note: I am using the current PBwin8 program)
              ARRAY SORT darray([index]) [FOR count] [,TAGARRAY tarray()] [,{ASCEND | DESCEND}]

              Here is what I would like to do in arrays for the screen display.

              'R1C1 R1C2 R1C3 R1C4 R1C5 R1C6 R1C7 R1C1 TO R5C1 IS THE LINE NUMBER IN DISPLAY
              'R2C1 R2C2 R2C3 R2C4 R2C5 R2C6 R2C7 ALL OTHER COLUMNS ARE DATA READ FROM FILE
              'R3C1 R3C2 R3C3 R3C4 R3C5 R3C6 R3C7 R1C2....R5C7
              'R4C1 R4C2 R4C3 R4C4 R4C5 R4C6 R4C7
              'R5C1 R5C2 R5C3 R5C4 R5C5 R5C6 R5C7


              From my partial understand I can do arrays:
              RC(1:20, 1:20, 1:20, 1:20, 1:20, 1:20, 1:20)
              or
              RC1(1:20), RC2(1:20) .......
              or
              Arrays within User-Defined Types
              Which would be best?

              I hope to have this test program as a model for using arrays (sort, scan, delete,insert assign)
              with the help of PB members.

              I last thing that I would like to learn about arrays is "COLLATE string options"

              Attached is my crashing program. (note: this is a partial code of my large program that I have where I use only global varibles with no arrays. this program works fine but wourld like to use array sort, etc)
              Attached Files
              Robert

              Comment


              • #8
                Robert, the arrays are not DIMed correctly. You haven't assigned values to the variables Row & Column yet so the array is dimensioned to zeros. The array is always out of bounds when you access it.

                Code:
                SUB Setup_Arrays      
                  LOCAL Row&, Column&, Counter&
                  Row = 5: Column = 10 '<<- assign values to dimension variables
                  Dim Lbl(Row, 1 to Column) '<<- Row & Column now have values
                =================================
                Each year,
                one vicious habit rooted out,
                in time
                ought to make the worst man good.
                Ben Franklin
                =================================
                It's a pretty day. I hope you enjoy it.

                Gösta

                JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                Comment


                • #9
                  Gösta H. Lovgren-2

                  Added the code: Row = 5: Column = 10
                  No change still crash. This "SUB Setup_Arrays" was not the problem. It worked fine before I added the RC()
                  array code.

                  The program crashes after I add the RC() array code. So the error must be in one of the following lines:

                  GLOBAL RC() AS STRING <<<< ??

                  SUB DSP_Test_AddEdit
                  DIM CNT AS LONG, I AS LONG, REC AS TYPEE
                  DIM RC(1:20, 1:20, 1:20, 1:20, 1:20, 1:20, 1:20) AS STRING <<<<<<< ??

                  ADSP1:
                  IF I=1 AND TestNR>0 THEN RC(1,1)=T1: RC(1,2)=T2: RC(1,3)=T3: RC(1,4)=T4: RC(1,5)=T5: RC(1,6)=T6: RC(1,7)=T7 <<< ??

                  SUB DSPRST_Test_AddEdit
                  LOCAL Row&, Column& <<<<<< ??
                  DIM Lbl(Row, Column) <<<<<< ??
                  CALL DSP_Test_AddEdit

                  FUNCTION PBMAIN () AS LONG
                  CALL Setup_Arrays
                  'GOTO EXITT
                  LOCAL result AS LONG
                  DIM REC AS TYPEE, RC(1:20, 1:20, 1:20, 1:20, 1:20, 1:20, 1:20) <<<<<< ??
                  Robert

                  Comment


                  • #10
                    Robert
                    It helps to use the code brackets for code, makes it more clear. It's the # symbol above the edit box when preparing your post.
                    This line DIMensions a 7 dimension string array
                    Code:
                    DIM RC(1:20, 1:20, 1:20, 1:20, 1:20, 1:20, 1:20) AS STRING
                    If you want to use your array as you do in this line:
                    Code:
                    IF I=1 AND TestNR>0 THEN RC(1,1)=T1: RC(1,2)=T2: RC(1,3)=T3: RC(1,4)=T4: RC(1,5)=T5: RC(1,6)=T6: RC(1,7)=T7
                    then your DIM statement should be
                    Code:
                    DIM RC(1:20, 1:20) AS STRING    'try this instead
                    This gives you 20 rows of 20 columns

                    It is easier to find your exact problem if all your code is shown.

                    Rod
                    Last edited by Rodney Hicks; 28 Jul 2008, 11:14 PM. Reason: somebody spelled something wrong.
                    Rod
                    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                    Comment


                    • #11
                      Originally posted by Robert Alvarez View Post
                      Gösta H. Lovgren-2

                      Added the code: Row = 5: Column = 10
                      No change still crash. This "SUB Setup_Arrays" was not the problem. It worked fine before I added the RC()
                      array code.
                      You can BE SURE that accessing an Array Out of Bounds (OOB), as you had to be doing the way RC() was dimensioned would be a problem. A thirny stickler with OOB errors is often don't surface when they occur but somewhere else in the program run as memory is corrupted in unpredictable areas.




                      The program crashes after I add the RC() array code. So the error must be in one of the following lines:

                      GLOBAL RC() AS STRING <<<< ??

                      SUB DSP_Test_AddEdit
                      DIM CNT AS LONG, I AS LONG, REC AS TYPEE
                      DIM RC(1:20, 1:20, 1:20, 1:20, 1:20, 1:20, 1:20) AS STRING <<<<<<< ??
                      As Rodney pointed out what you actually did was DIM RC() to 7 dimensions where what you apparently want is 2 dimensions of 7 Rows and 20 Columns - RC(7, 20).

                      Maybe this code snippet will give you a better visualization:

                      Code:
                      Dim RC(7, 20)
                      RC(1, 1) = 1 '<<--- Row 1 Column 1
                      RC(1, 2) = 1 '<<--- Row 1 Column 2
                      RC(1, 3) = 1 '<<--- Row 1 Column 3
                      ...          '<<--- Continue filling in Column values
                      RC(1, 20) = 1 '<<--- Row 1 Column 20
                       
                      ...          '<<--- Continue with succeeding rows 
                      RC(7, 1) = 1 '<<--- Row 7 Column 1
                      RC(7, 2) = 1 '<<--- Row 7 Column 2
                      RC(7, 3) = 1 '<<--- Row 7 Column 3
                      ...
                      RC(7, 20) = 1 '<<--- Row 7 Column 20
                      ======================================================
                      Lost Illusion is the undisclosed title of every novel.
                      André Maurois
                      ======================================================
                      It's a pretty day. I hope you enjoy it.

                      Gösta

                      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                      Comment


                      • #12
                        OK, my test program is now back in order, no more crashes.

                        Reason I had 7 dim was because I was going to be attempt to figuire out sorting by column (col 2 to col 7).

                        Reading the sorting a multi-dim array I do not understand:
                        (0,0), …, (n,0), (0,1), …, (n,1), …, (0,x), …, (n,x)
                        or

                        ARRAY SORT RC(1,2) FOR n+1 ( FOR n+1 ???)

                        Also still have not figured out code for handing the file on disk.


                        would this code be:
                        1. make another array to put all of my data on file to fdata(row, column)
                        2. sort the array by column 1 or 2 or 3 .....
                        3. put the sorted array data back in to the disk file, sorted.

                        looks like I wll have to add another data for record number to my UDT as Col1
                        Attached Files
                        Robert

                        Comment


                        • #13
                          Originally posted by Robert Alvarez View Post
                          ...
                          2. sort the array by column 1 or 2 or 3 .....
                          ...
                          I don't think multi dimmed arrays can be sorted that way. Probably the best bet would be to just use 7 separate arrays (RC1(), RC2(), ... RC7() ), then sort them according to the order you'd like (using TAGARRAY).

                          Dunno how much you are handling the array RC() but it might pay to copy the multi dimmed RC() into to individual single arrays (RC1(0, RC2(0, ...), sort the single arrays then copy them back into RC(Row, Col).

                          Code:
                          Sub Sort_Arrays
                           
                          DELETED on account of DUMBNESS
                           
                          See post 36 (http://www.powerbasic.com/support/pb...t=38027&page=2) for a multi array sort that works.
                          That way you could retain the ease of use of the multi dim in the rest of the program and just call the Sub when you want to sort. Just a thought.

                          =====================================
                          Life — the way it really is a battle
                          not between Bad and Good
                          but between Bad and Worse.
                          Joseph Brodsky
                          =====================================
                          Last edited by Gösta H. Lovgren-2; 2 Aug 2008, 10:27 AM. Reason: Clearing some fud mud
                          It's a pretty day. I hope you enjoy it.

                          Gösta

                          JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                          LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                          Comment


                          • #14
                            Code:
                               (0,0), …, (n,0), (0,1), …, (n,1), …, (0,x), …, (n,x)    
                             from the manual means
                            
                            
                                col       0     1     2   ...   6       7 ...   x
                             row
                              0        (0,0)  (0,1) (0,2) ... (0,6)  (0,7) ... (0,x)
                              1        (1,0)  (1,1) (1,2) ... (1,6)  (1,7) ... (1,x)
                              2        (2,0)  (2,1) (2,2) ... (2,6)  (2,7) ... (2,x)
                              .           .      .     .        .      .        .
                              .           .      .     .        .      .        .
                              .           .      .     .        .      .        .
                              6        (6,0)  (6,1) (6,2) ... (6,6)  (6,7) ... (6,x)
                              7        (7,0)  (7,1) (7,2) ... (7,6)  (7,7) ... (7,x)
                              .           .      .     .        .      .        .
                              .           .      .     .        .      .        .
                              .           .      .     .        .      .        .
                              n        (n,0)  (n,1) (n,2) ... (n,6)  (n,7) ... (n,x)
                              
                            '  your array is DIMmed as follows in this example:
                            DIM myarray(0 TO n,0 TO x)
                            The underlined pairs indicate the named pairs in the manual.
                            When sorting multi dimension arrays it treats the dimensions as if they were one moving from (0,0) to (n,x) hitting each of the others in the order so proscribed.
                            Hope this helps to clarify the issue for you.

                            postscript
                            Each of the underlined pairs is referred to as an element
                            Understanding arrays is important, and Gosta suggestion using the TAGARRAY has a lot of merit.
                            Once you get the grasp of arrays, you'll wonder how you ever did without them.
                            Last edited by Rodney Hicks; 30 Jul 2008, 01:54 AM. Reason: add postscript
                            Rod
                            I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                            Comment


                            • #15
                              I forgot about the n+1 question

                              DIM myarray(0 to 20, 0 to 25)
                              if n=20 and x=25
                              then the following DIM is equal to the previous
                              DIM myarray(n,x)
                              because you are using 0, the default lower bound of the array it is not necessary to declare it.
                              There are 21 by 26 elements in the array
                              0 TO 20 by 0 TO 26 'count them 0 is 1, 1 is 2, 2 is 3....20 is 21:2nd dimension-0 is 1, 1 is 2, 2 is 3,....24 is 25, 25 is 26
                              or
                              n+1 by x+1
                              To use the array sort with this array you could use
                              ARRAY SORT myarray(0,0) FOR 21
                              or
                              ARRAY SORT myarray(0,0) FOR n+1 'because n is equal to 20 and you need 21 because of the zero.

                              Clear as mud, yeah??
                              Rod
                              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                              Comment


                              • #16
                                This line DIMensions a 7 dimension string array
                                Code:
                                DIM RC(1:20, 1:20, 1:20, 1:20, 1:20, 1:20, 1:20) AS STRING
                                No it doesn't. That wants to create 1,280,000,000 four byte elements.

                                You can do the math or you can add the error-checking you should have added when you started having problems at the latest.

                                Code:
                                DIM RC(1:20, 1:20, 1:20, 1:20, 1:20, 1:20, 1:20) AS STRING
                                    
                                MSGBOX USING$ ("Error #  &", ERR, ERROR$(ERR)),,"After DIM"
                                MCM
                                Michael Mattias
                                Tal Systems Inc. (retired)
                                Racine WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment


                                • #17
                                  While your take on the problem is accurate in the 'what is happening sense' it doesn't clearly help with 'the how to prevent it'. Misunderstanding how to construct arrays was the problem that led to errors.
                                  You have given him a valuable tool to check his own work once he links the size of his arrays to memory constraints as any programmer should.

                                  All things in due time, we hope.
                                  Rod
                                  I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                  Comment


                                  • #18
                                    Originally posted by Rodney Hicks View Post
                                    While your take on the problem is accurate in the 'what is happening sense' it doesn't clearly help with 'the how to prevent it'. Misunderstanding how to construct arrays was the problem that led to errors.
                                    You have given him a valuable tool to check his own work once he links the size of his arrays to memory constraints as any programmer should.

                                    All things in due time, we hope.
                                    Can I get an "Amen, Brother".

                                    ==============================
                                    "Everybody pities the weak;
                                    jealousy you have to earn."
                                    Arnold Schwarzenegger (1947-)
                                    ==============================
                                    It's a pretty day. I hope you enjoy it.

                                    Gösta

                                    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                    Comment


                                    • #19
                                      it doesn't clearly help with 'the how to prevent it'.
                                      Code:
                                      LOCAL Z() AS theTypeIWant 
                                      nElement = %IN_MY_WILDEST_DREAMS_VALUE + 1  ' large number 
                                      DO
                                        DecrNElement     
                                        ERRCLEAR 
                                        REDIM Z(1:nnElement) 
                                      LOOP UNTIL ERR=0
                                      Values may be only temporarily valid. Void where prohibited. Your mileage may vary. Winner responsible for all taxes.
                                      Michael Mattias
                                      Tal Systems Inc. (retired)
                                      Racine WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        Michael,

                                        While you and I and Gosta( having been programmers of various ability for x^N years) may understand what the significance of "%IN_MY_WILDEST_DREAMS_VALUE + 1" is,
                                        I am not sure the originator of this thread does at this stage of the game.
                                        I like the way you post this though, for it shows him there's something simple to learn to help with the issue in the future.
                                        Rod
                                        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                        Comment

                                        Working...
                                        X