Announcement

Collapse
No announcement yet.

Milti DIM arrays??

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

  • Gösta H. Lovgren-2
    replied
    Robert,

    I took the liberty of pointing our a couple places where Loops are probably more appropriate to use, less prone to typos and easier to debug.

    '
    Code:
     
    ADSP_RESET:
     
      'try this instead
     
       Local ctr&
     
       For ctr = 1 To 5
         RC(I, ctr) = ""
       Next ctr        
     
     Return 'no need to go further
     
      '
    If I=1 Then RC(1,1)="": RC(1,2)="":RC(1,3)="": RC(1,4)="":RC(1,5)="": RC(1,6)="":RC(1,7)=""
    IF I=2 THEN RC(2,1)="": RC(2,2)="":RC(2,3)="": RC(2,4)="":RC(2,5)="": RC(2,6)="":RC(2,7)=""
    IF I=3 THEN RC(3,1)="": RC(3,2)="":RC(3,3)="": RC(3,4)="":RC(3,5)="": RC(3,6)="":RC(3,7)=""
    IF I=4 THEN RC(4,1)="": RC(4,2)="":RC(4,3)="": RC(4,4)="":RC(4,5)="": RC(4,6)="":RC(4,7)=""
    IF I=5 THEN RC(5,1)="": RC(5,2)="":RC(5,3)="": RC(5,4)="":RC(5,5)="": RC(5,6)="":RC(5,7)=""
    RETURN
     
     
    ADSP1:   
     
      'try this instead   'simpler to read and debug
     
      If TestNR > 0 Then
          RC([B]I[/B],1)=T1
          RC([B]I[/B],2)=T2
          RC([B]I[/B],3)=T3
          RC[B](I[/B],4)=T4
          RC([B]I[/B],5)=T5
          RC([B]I[/B],6)=T6
          RC([B]I,[/B]7)=T7
      End If
     Return 'no need to go further
     
     '
    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
    IF I=2 AND TestNR>0 THEN RC(2,1)=T1: RC(2,2)=T2: RC(2,3)=T3: RC(2,4)=T4: RC(2,5)=T5: RC(2,6)=T6: RC(2,7)=T7
    IF I=3 AND TestNR>0 THEN RC(3,1)=T1: RC(3,2)=T2: RC(3,3)=T3: RC(3,4)=T4: RC(3,5)=T5: RC(3,6)=T6: RC(3,7)=T7
    IF I=4 AND TestNR>0 THEN RC(4,1)=T1: RC(4,2)=T2: RC(4,3)=T3: RC(4,4)=T4: RC(4,5)=T5: RC(4,6)=T6: RC(4,7)=T7
    IF I=5 AND TestNR>0 THEN RC(5,1)=T1: RC(5,2)=T2: RC(5,3)=T3: RC(5,4)=T4: RC(5,5)=T5: RC(5,6)=T6: RC(5,7)=T7
    RETURN
     
    TestEND:
     
    END SUB
     
     
     
     
    Sub DSPRST_Test_AddEdit
    LOCAL Row&, Column&
      Row = 5: Column = 10
      DIM Lbl(Row, Column), RC(1:20, 1:20) AS STRING
     
    CALL DSP_Test_AddEdit
     
     
    'Ccode below could be more easily done this way:
      For Row = 1 To 5
         For Column = 1 To 7
             Control Set Text hDlg, LBL(Row, Column), RC(Row, Column)
         Next Column
      Next Row
     Exit Sub 'Exit here, no need of rest of Sub
     
     
     
    CONTROL SET TEXT hDlg, LBL(1,1), RC(1,1)
    CONTROL SET TEXT hDlg, LBL(1,2), RC(1,2)
    CONTROL SET TEXT hDlg, LBL(1,3), RC(1,3)
    CONTROL SET TEXT hDlg, LBL(1,4), RC(1,4)
    CONTROL SET TEXT hDlg, LBL(1,5), RC(1,5)
    CONTROL SET TEXT hDlg, LBL(1,6), RC(1,6)
    CONTROL SET TEXT hDlg, LBL(1,7), RC(1,7)
     
    CONTROL SET TEXT hDlg, LBL(2,1), RC(2,1)
    CONTROL SET TEXT hDlg, LBL(2,2), RC(2,2)
    CONTROL SET TEXT hDlg, LBL(2,3), RC(2,3)
    CONTROL SET TEXT hDlg, LBL(2,4), RC(2,4)
    CONTROL SET TEXT hDlg, LBL(2,5), RC(2,5)
    CONTROL SET TEXT hDlg, LBL(2,6), RC(2,6)
    CONTROL SET TEXT hDlg, LBL(2,7), RC(2,7)
     
    CONTROL SET TEXT hDlg, LBL(3,1), RC(3,1)
    ... 'Lots of lines in here
    CONTROL SET TEXT hDlg, LBL(5,7), RC(5,7)
     
    END SUB
     
    '
    =================================
    "Too many pieces of music finish
    too long after the end."
    Igor Stravinsky (1882-1971)
    =================================
    Last edited by Gösta H. Lovgren-2; 2 Aug 2008, 01:31 PM. Reason: Erudition (hopefully)

    Leave a comment:


  • Robert Alvarez
    replied
    "ridiculously easy" for MCM and other pro programmers but not for me and many others here just learning the basics.

    I have been fiddling with basic since the Atari basic and IBM xt basic came out and I am still just a novice at programming. The programs I make use the basics of basic code in PB, just enough to enter and process data and get data out the way I want. I have just made a small scratch in PB functions.

    Help was not to good compared to PB forms. I just relyed on two books: Quickbasic Advanced Techniques and The Power of Turbo Basic. And only study what was the most interest to me not from cover to cover.

    Basic progarmming help me solve the problem of good but bad software out there. Bought several finance software over many years only to be disappointed with bugs, bugs, and gone out of business. Then I did my own finance program and put an end to that. Also did not like their program interface to user.

    I only spent around 40 to 50 hour a week programming. I also have done some web programming and in the past spend a good amount of time with Alpha 4 database programming (decided basic prog. was better).

    I have learned what I wanted on arrays but will shelf the array sorting for now, have other programing to complete first. I do have my own sort routine not using arrays that sort by columns by the first and next column etc.

    Attached is the test program which I had modified but still have a minor bug for viewers who wish to check it out.
    Attached Files

    Leave a comment:


  • Michael Mattias
    replied
    I hate happy endings....
    Note this can also be used to sort numeric values via the PB Using$ function in the Sort_Field.
    Not if the numeric value is less than zero it can't!

    But..... a little bell is ringing.......

    A long time ago, far far away I wrote something for PB/DOS which DOES sort UDTs by member, even if those members are numeric, eg "AS INTEGER" ("AS INTEGER" was BIG in PB/DOS).

    Not that it would all that tough to adapt my six-year old demo to handle that.

    You'd have to add a parameter to tell the function "sort as <some datatype>" but after that it's more tedious than challenging.

    MCM

    Leave a comment:


  • Rodney Hicks
    replied
    Robert has thanked us for the help we offered, which to me indicates that he thinks he has enough to carry on in his style.
    If you're right Gosta, about English not being his first language, then PB will be at least his third, and good for Robert.
    Michael has provided some stones to our pebbles and with all help provided here, Robert can develop himself into the kind of 'painter' he wants to be, at his own speed of course.
    Methinks we have done well.

    Leave a comment:


  • Michael Mattias
    replied
    Until fairly deep in this thread, I did not infer that all those separate arrays were actually representing "columns of a row" or "fields of a record" and that all that sorting was being done so that ALL arrays would ALWAYS be exactly parallel.

    And the starting point, with its 1,280,000,000 element array only pushed me further away from that conclusion.

    It's a lot easier to create code given the application than to create the application given some code.

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    It seems to me Robert (and perhaps others) are having a little difficulty grasping the concept of sorting and keeping together multiple arrays. My guess is English is not his first language and that complicates things further. He would miss some of the subtle ironies posted. Heck, I miss them myself.

    I posted the humble example (clearly feeble, even laughable) using a UDT (as closely as I reasonably could) with Robert's own variables in hopes that may make things clearer for *him*. Not in any way implying it is a superior method, or even equal, or even remotely in the same league, or should in any way emulated. Only as a stepping pebble on the road to the high level of coding sophistication on display in this forum.

    ======================================
    "A miser isn't much fun to live with,
    but he makes a wonderful ancestor. "
    Anonymous
    ======================================

    Leave a comment:


  • Michael Mattias
    replied
    Of course, if you wanted to use an array of UDTs with variable-size members, sorting by one of those members is also ridiculously easy - assuming you can master 'cut and paste':

    CC3/Win7: ARRAY SORT UDT array on member name September 04, 2002

    MCM

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Robert, in a (probably feeble) attempt to atone for my previous egregious erudition, here is yet another way to sort multiple arrays (in addition to Ron's and Mike's fine examples).

    '
    Code:
     
    Type Sort_Type
      Sort_Field As String * 74 '<<- can be any length long enough to hold all fields
      Col1  AS STRING * 10  'Cols from Robert's program
      Col2  As String * 30
      Col3  As String * 8
      Col4  As String * 8
      Col5  As String * 8
      Col6  As String * 10
    End Type
     
     
    Sub Sort_Columns                           
      Local Srt() As Sort_Type, x&
      Dim Srt(20) '20 used in Robert's program
     
      For x = 1 To 20             
        Srt(x).Col1 = RC(1, x) 'Row Column Array holding string values
        Srt(x).Col2 = RC(2, x) '
        Srt(x).Col3 = RC(3, x) '
        Srt(x).Col4 = RC(4, x) '
        Srt(x).Col5 = RC(5, x) '
        Srt(x).Col6 = RC(6, x) '
     
        'now place in order of sort wanted
        Srt(x).Sort_Field = RC(3, x) & _
                            RC(4, x) & _
                            RC(1, x) & _
                            RC(2, x) & _
                            RC(6, x) & _
                            RC(5, x) 
      Next x                      
     
      'Sort the array 
      Array Sort  Srt()
     
      'Now put the sorted values back in Row Column Array
      For x = 1 To 20
         RC(1, x) = Srt(x).Col1
         RC(2, x) = Srt(x).Col2
         RC(3, x) = Srt(x).Col3
         RC(4, x) = Srt(x).Col4
         RC(5, x) = Srt(x).Col5
         RC(6, x) = Srt(x).Col6
      Next x
     
    End Sub
    '
    Note this can also be used to sort numeric values via the PB Using$ function in the Sort_Field.

    Not a painting perhaps, but ...

    =======================================
    "The great tragedy of science
    the slaying of a beautiful hypothesis
    by an ugly fact."
    Thomas Huxley
    =======================================

    Leave a comment:


  • Michael Mattias
    replied
    > it is not the language that is the problem, it is how the language is used

    You mean... "It's not the paintbrish, it's the artist?"

    My Brother!

    Leave a comment:


  • Rodney Hicks
    replied
    Michael has shown you two methods, and I showed you another.
    It can be done, and if it isn't being done in your code, it is because some other thing in your code is out of whack.

    The compiler will not find errors where wrong variables are used, if they are of the same type, and something that minor can hold up progress for a long time.

    In a case like that, it is not the language that is the problem, it is how the language is used. (It usually results in some foul language until solved.)

    Leave a comment:


  • Michael Mattias
    replied
    A good database or spread sheet program can sort a column bringing along other data columns, but PB array sort alone seems to not have that ability
    The reason you percieve some deficiency here is not because of a deficiency or defect in ARRAY SORT, it's because your design of seven or eight separate arrays is not really your best choice for "records with columns"

    You could use either....
    1. A single array of delimited strings (eg each element looks like one record from a comma-separated-values files)
    OR
    2. An array of UDTs with separate members for each 'column"

    You want to sort all "records" by some "column" amd have all the other columns come along? Use the single array of UDTs and it's ridiculously easy:

    Code:
    %SIZEOFCOLUMN   =  (some max size)
    TYPE MyRowType 
      Column (1: maxcolumns) AS ASCIIZ * %SIZEOFCOLUMN
    END TYPE 
    
      LOCAL/STATIC/GLOBAL/THREADED  MyRow () AS MyRowType 
      ..
      REDIM MyRow (number of rows to load  -1 ) 
    
      Fill MyRow () 
    
      SortColumnNo =  (pick one) 
    
      ARRAY SORT MyRow(), _ 
         FROM ( (SortColumnNo-1)* %SIZEOFCOLUMN + 1) _ 
            TO  (SortColumnNo *  %SIZEOFCOLUMN)
    Bingo, you're done.

    MCM
    Last edited by Michael Mattias; 1 Aug 2008, 04:06 PM.

    Leave a comment:


  • Robert Alvarez
    replied
    Fixed the routine on the "x", and it works better but some small bug is still there. I can now see that the sort only sorts the selected column and all the other array data do not follow the selected sorted array column.

    I will check out the link on index array.

    A good database or spread sheet program can sort a column bringing along other data columns, but PB array sort alone seems to not have that ability yet.

    This thrread has help me understand arrays better than what I knew, now I can set my program addresses using arrays to avoid errors and using the multi arrays for screen displays replaceing many global varibles, helped.

    Thank eveyone for your help.

    Code:
    'have been using this for a while, I will keep an eye on it and make a note on it for any problems
    
     CASE %WM_COMMAND AND CBCTL = %BU5
           CONTROL GET TEXT hDlg, %BU5 TO S: Z=1
    Last edited by Robert Alvarez; 1 Aug 2008, 03:26 PM.

    Leave a comment:


  • Michael Mattias
    replied
    Also FWIW, here's a current thread with an example of using an index array (the approach suggested by Mr. Hicks and endorsed by Mr. Lovgren)

    http://www.powerbasic.com/support/pb...ad.php?t=38085

    The index array ("subscript()" in linked post) is absolutely the way to go to keep multiple arrays "in synch" whilst sorting.

    MCM

    Leave a comment:


  • Michael Mattias
    replied
    Code:
    SELECT CASE CBMSG
     CASE %WM_COMMAND AND CBCTL = %BU5
           CONTROL GET TEXT hDlg, %BU5 TO S: Z=1
     CASE %WM_COMMAND AND CBCTL = %BU6
           CONTROL GET TEXT hDlg, %BU6 TO S: Z=2
     CASE %WM_COMMAND AND CBCTL = %BU7
           CONTROL GET TEXT hDlg, %BU7 TO S: Z=3
     CASE %WM_COMMAND AND CBCTL = %BU8
           CONTROL GET TEXT hDlg, %BU8 TO S: Z=4
     CASE %WM_COMMAND AND CBCTL = %BU9
           CONTROL GET TEXT hDlg, %BU9 TO S: Z=5
     CASE %WM_COMMAND AND CBCTL = %BU10
           CONTROL GET TEXT hDlg, %BU10 TO S: Z=6
     CASE %WM_COMMAND AND CBCTL = %BU11
           CONTROL GET TEXT hDlg, %BU11 TO S: Z=7
    END SELECT
    This cannot be correct.
    Code:
     SELECT CASE CBMSG
         CASE %WM_COMMAND AND CBCTL = %BU5
    I think what you mean here is "(If CBMSG = %WM_COMMAND) AND (CBCTL = %BU5)" but I have no clue how the compiler will interpret what you have coded.

    The 'standard' way to code the situation where you want to react to the WM_COMMAND notification, but what you need to do depends on which control generated that notification would be ...

    Code:
     
    
      SELECT CASE CBMSG 
           CASE %WM_COMMAND 
                 SELECT CASE CBCTL 
                        CASE %BU5 
                             do whatever
    
                        CASE %BU6 
                             do whatever
    
                        CASE %BU7 
                             do whatever
                        .....
                         CASE other control ID 
                             whatever
                END SELECT   ' of CBCTL (which control sent WM_COMMAND notification) 
    
      END SELECT   ' of CBMSG
    MCM

    Leave a comment:


  • Rodney Hicks
    replied
    This line
    Code:
    GET #5,TestRN,REC
    because TestRN doesn't change it will read the same record over and over.
    If you change TestRN to x, the loop variable, it will read the successive records.

    Gosta, I liked your erudition!

    Leave a comment:


  • Robert Alvarez
    replied
    Well here is my attempt at sorting, this code is not complete but it has the the code to check to see what happens. Redim will be in later.

    First problem is loading the RC arrays with the file data, that is not working right, when pressing the Col1 sort button I added in main dialog.

    The sorting also did not work, but first have to solve the data file to array problem.

    I will see if I can fix my sort code this weekend, if not by Monday. I will also wait for remarks on this code I wrote. Maybe someone will see something I missed.

    Maybe need to look at index concept or other.

    Code:
    CALLBACK FUNCTION File_ColumnSort()
    LOCAL x AS LONG, S AS STRING, Z AS LONG
    DIM FC1(TestNR),FC2(TestNR),FC3(TestNR),FC4(TestNR),FC5(TestNR),FC6(TestNR),FC7(TestNR), REC AS TYPEE
    
    SELECT CASE CBMSG
     CASE %WM_COMMAND AND CBCTL = %BU5
           CONTROL GET TEXT hDlg, %BU5 TO S: Z=1
     CASE %WM_COMMAND AND CBCTL = %BU6
           CONTROL GET TEXT hDlg, %BU6 TO S: Z=2
     CASE %WM_COMMAND AND CBCTL = %BU7
           CONTROL GET TEXT hDlg, %BU7 TO S: Z=3
     CASE %WM_COMMAND AND CBCTL = %BU8
           CONTROL GET TEXT hDlg, %BU8 TO S: Z=4
     CASE %WM_COMMAND AND CBCTL = %BU9
           CONTROL GET TEXT hDlg, %BU9 TO S: Z=5
     CASE %WM_COMMAND AND CBCTL = %BU10
           CONTROL GET TEXT hDlg, %BU10 TO S: Z=6
     CASE %WM_COMMAND AND CBCTL = %BU11
           CONTROL GET TEXT hDlg, %BU11 TO S: Z=7
    END SELECT
    
    
    FOR x = 1 TO TestNR       '..NR = number of records in file    ..RN = record number
    GET #5,TestRN,REC
    FC1(x)=REC.Col1: FC2(x)=REC.Col2: FC3(x)=REC.Col3: FC4(x)=REC.Col4: FC5(x)=REC.Col5
    FC6(x)=REC.Col6: FC7(x)=REC.Col7
    NEXT x
             MSGBOX FC2(1)                        '<<<<<<<<< FC2(1)= R6C2 SHOULD BE R1C2
    IF Z=1 THEN ARRAY SORT FC1(),TAGARRAY FC2() ,DESCEND
    IF Z=2 THEN ARRAY SORT FC2(),TAGARRAY FC1() ,DESCEND
    IF Z=3 THEN ARRAY SORT FC3(),TAGARRAY FC1() ,DESCEND
    IF Z=4 THEN ARRAY SORT FC4(),TAGARRAY FC1() ,DESCEND
    IF Z=5 THEN ARRAY SORT FC5(),TAGARRAY FC1() ,DESCEND
    IF Z=6 THEN ARRAY SORT FC6(),TAGARRAY FC1() ,DESCEND
    IF Z=7 THEN ARRAY SORT FC7(),TAGARRAY FC1() ,DESCEND
    
    FOR x = 1 TO TestNR       'NR = number of records in file    RN = record number
    REC.Col1=FC1(x): REC.Col2=FC2(x): REC.Col3=FC3(x): REC.Col4=FC4(x): REC.Col5=FC5(x)
    REC.Col6=FC6(x): REC.Col7=FC7(x)
    PUT #5,TestRN,REC
    NEXT x
    MSGBOX FC2(1)
    
    DSPRST_Test_AddEdit
    END FUNCTION

    Leave a comment:


  • Gösta H. Lovgren-2
    replied
    Originally posted by Rodney Hicks View Post
    I introduced the index concept because I have never been able to have more than one TAGARRAY. The line above gives a syntax error in my version of PB Win 8.04.

    ...
    My bad. I just typed without testing. No excuse. Just got carried away with "erudition". {sigh} Apologies to Robert and anyone else anyone who may have been misled. I must have been thinking of DosPlus Basic I used years ago that sorted on a() then b() then c() then ...

    I have seldom, if ever, used TagArray. In PB I usually use a TYPEd array when I sort with the first field as a large text field or use an Index array as Rodney so helpfully pointed out.


    ===============================================
    "Money doesn't make you happy.
    I now have $50 million but I was just as happy
    when I had $48 million."
    Arnold Schwarzenegger
    ===============================================

    Leave a comment:


  • Rodney Hicks
    replied
    Michael,
    I was explaining to Gosta why I used the index, hopefully so that Robert could understand why.
    If you look at Robert's code you'll see the line that gives the error comes from there.
    If you read Gosta's post, he doesn't take issue with the line in question.
    I know and I showed why it could not be done the way he had it in his code so that Robert could see that as well. And anyone else, and I guess you did.
    Some newbies have used other languages, some are new to programming.

    Leave a comment:


  • Michael Mattias
    replied
    I have never been able to have more than one TAGARRAY.
    Neither has anyone else here, because ARRAY SORT supports zero or one TAGARRAY arraynames.

    The line above gives a syntax error in my version of PB Win 8.04.
    I should sincerely hope so. Not that "syntax error" is terribly helpful text, but at least it tells you something is wrong.

    MCM

    Leave a comment:


  • Rodney Hicks
    replied
    Array Sort FC3(), TagArray FC1(), FC2()
    I introduced the index concept because I have never been able to have more than one TAGARRAY. The line above gives a syntax error in my version of PB Win 8.04.

    I also left the CALLBACK thing alone because he was providing us with selected text, and one thing at a time frame of mind was operative at my computer.

    Leave a comment:

Working...
X