Announcement

Collapse
No announcement yet.

Dim At

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

  • Dim At

    I just noticed something in the Array Passing code discussion (http:// www.powerbasic.com/support/pbforums/showthread.php?t=39196) and thought it worth a separate thread.

    {Thinking out loud here}
    In the code snippet below (part of Profile_Ordered_with_Variables.Inc - in Source Forum). str1 is Dimmed At (pointing to) an existing array that's part of a Type. In the cases shown here, the VarPtr(pfi.Bytes(1)) is actually 50 chars long per element (as defined by an Equate ), but the first Macro sends a 255 byte element array (address) to the Function. It should have been 'VarPtr(pfi.Procedures(1))
    '
    The Function works (I'm guessing) because the area pointed to is a pretty large chunk of (contiguous?) memory taken up by the UDT pfi (which has a lot of string arrays in it). And just lucky happenstance it didn't mess up any of the other pfi arrays.
    '
    I have seldom used Dim At myself and never really thought much about the concept before this. I understand it better now (I think & hope anyway). If anyone sees a flaw or misdirection in the rationale, I would certainly appreciate straightening it out (even if you have to rub it in. {grin}).
    Code:
    'Macro which calls "Profile_ProcessAnyArray_Procedures"                                  'VarPtr(pfi.Procedures(1)) Should be    
      ReDim srt1(1 To %Profile_Array_Elements) As String * %Profile_Procedure_Name_Length  At VarPtr(pfi.Bytes(1)) 
             Profile_ProcessAnyArray_Procedures(VarPtr(pfi.Procedures(1))) '255 byte elements
             Profile_ProcessAnyArray_Procedures(VarPtr(pfi.Macros(1)))     '      ""
    'End Macro
    '                
    Function Profile_ProcessAnyArray_Procedures (pZ As Dword) As Long 'Sort the array point at by pz
     ReDim  Z(1 To %Profile_Array_Elements)  As String * %Profile_Procedure_Name_Length At pZ '255 bytes long   
       Array Sort z() 'effectively sorts the array pointed to by pz
    End Function 
    '
    'Macro which calls "Profile_ProcessAnyArray_Variable"
      ReDim srt1(1 To %Profile_Array_Elements) As String * %Profile_Variable_Name_Length  At VarPtr(pfi.Bytes(1)) 
             Profile_ProcessAnyArray_Variable(VarPtr(pfi.Bytes(1)))        '50 byte elements
             Profile_ProcessAnyArray_Variable(VarPtr(pfi.Integers(1)))
    ' and so on for 10 more identically sized UDT arrays
    'end macro                
    Function Profile_ProcessAnyArray_Variable (pZ As Dword) As Long 
     ReDim  Z(1 To %Profile_Array_Elements)  As String * %Profile_Variable_Name_Length At pZ '50 bytes long    
       Array Sort z()'effectively sorts the array pointed to by pz
    End Function 
    '------------------/ProcessAnyArray'
    ==================================
    "The difference between
    'involvement' and 'commitment'
    is like a ham-and-eggs breakfast:
    the chicken was 'involved'
    the pig was 'committed'."
    unknown
    ==================================
    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/

  • #2
    The Function works (I'm guessing) because the area pointed to is a pretty large chunk of (contiguous?) memory
    Actually, it works because both DIM AT and PB array data storage work as documented.

    What you do with those capabilities is up to you.

    The absolute array in its simplest form:
    Code:
      H$ = "Hello, World" 
      REDIM cH(LEN(H$)-1) AS STRING * 1 AT STRPTR(H$) 
      FOR X = LBOUND (cH, 1) TO UBOUND (ch,1)
        PRINT    ch(X) 
      NEXT
    That is, because the "DIM AT" capability exists, you can choose to consider "Hello, World" as either a single 12-character string or as a 12-element array of single characters.... whichever suits your application.

    MCM
    (I have loved absolute arrays ever since PB/DOS).
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      You've been around a while so you've probably seen the equivalent COBOL code...

      Code:
       WORKING-STORAGE SECTION. 
      
        01  HELLO-WORLD    PIC X(12) 
        01  CH-ARRAY  REDEFINES HELLO-WORLD
             05 LETTER   PIC X(01) OCCURS 12 TIMES.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Originally posted by Michael Mattias View Post
        You've been around a while...
        Level 66?

        Comment


        • #5
          '66' is the renames? Or is 66 the MF constants?

          I think I only used renames once... where someone had created a 'library' copybook - inaccessible to us 'peon' contractors - which was put together really, really silly. Code ended up something like
          Code:
             Copy sillylib. 
             66 (?)  USEFUL-GROUP-ITEM RENAMES  X THRU Y.
          I used '88' (condition) a lot... except I had one client who forbade the use of '88' level datanames. (Go figger that one!)

          '77' was always popular but for the most part I just put the disjoint W-S vars into a single '01' group item.

          What's the other special one? 49, I think... what's used for ESQL working storage to create the "bind" variables used in
          Code:
           
             EXEC SQL 
                SELECT   name INTO :WS-NAME from table where ...
             END-EXEC
          I think that's all the 'specials'... 66,77,88 and 49. But not having written a line of COBOL since '01 I'm sure I've forgotten something by now...
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Originally posted by Michael Mattias View Post
            What's the other special one? 49
            49 new to me. My last serious COBOL 1979.

            Comment


            • #7
              Originally posted by Michael Mattias View Post
              Actually, it works because both DIM AT and PB array data storage work as documented.
              Which tells me nothing, or at least anything I recognize. Presumably PB documentation is accurate (until demonstrated otherwise). As for being illuminating, in my case anyway, that's not always or even often the case. Which is a/the reason I started this thread.
              That is, because the "DIM AT" capability exists, you can choose to consider "Hello, World" as either a single 12-character string or as a 12-element array of single characters.... whichever suits your application.
              MCM
              (I have loved absolute arrays ever since PB/DOS).
              The advantage of which escapes me as well.

              As for COBOL, I have (next to) zero knowledge or experience. COBOL examples help me little in understanding PB. A discussion of which is better suited in a separated thread.

              My interest here is in what advantage/disadvatage does Dim At offer over a dynamic array. In the example above, the advantage of overlaying one array with another is obvious. Are there any others?

              And the other point I wanted to make was the routine worked despite the fact I VarPtr'ed to the wrong area. (Note - Profile_Ordered_with_Variables.Inc in the Source Forum has been corrected). It seems to me that could lead to disasterous consequences (if the area pointed to was near the boundry of a data area segment and te overlay went beyond it and corrupted another program or something). It's a good example of Michael's proviso the compiler doesn't check for programmer stupidity/serendipity.

              =========================================
              "Life is pleasant.
              Death is peaceful.
              It's the transition that's troublesome."
              Isaac Asimov
              =========================================
              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


              • #8
                My interest here is in what advantage/disadvatage does Dim At offer over a dynamic array. In the example above, the advantage of overlaying one array with another is obvious. Are there any others?
                The advantage is, you can look at a block of memory different ways... it's kind of like a UNION on steroids. It's a source-code level tool to be used as desired.

                In your specific case... it allows you to use the ARRAY functions (SORT/SCAN) on data which is otherwise not an array:

                Code:
                TYPE   FOO
                      X (1:100) AS STRING * 2 
                END TYPE
                Since Foo.X() is NOT an array, you can't:
                Code:
                ARRAY SORT Foo.x()    <<<  compile time error 423 array variable expected
                But if you create a genuine real array on top of that data...
                Code:
                  REDIM  X(1:100) AS STRING * 2  AT VARPTR (FOo.X(1))
                ...now you CAN sort it:
                Code:
                 ARRAY SORT X()
                Complete explanation and examples under 'restrictions' of ARRAY SORT in help file.

                Compilable example:
                Code:
                TYPE FOO
                  X(1 TO 5) AS STRING * 2
                END TYPE
                
                FUNCTION PBMAIN () AS LONG
                    
                    LOCAL F AS FOO, S AS STRING, Z AS LONG
                    F.X(1) = "ZZ"
                    F.X(2) = "YY"
                    F.X(3) = "XX"
                    F.X(4) = "WW"
                    F.X(5) = "VV"
                    
                    'ARRAY SORT F.X()  ' error 423 Array variable expected
                    
                    REDIM X(1 TO 5) AS STRING * 2 AT VARPTR (F.X(1))
                    
                    ARRAY SORT X()
                    
                    FOR Z = 1 TO 5
                        S = S & F.X(Z) & "***"
                    NEXT
                    MSGBOX S
                   
                END FUNCTION
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Originally posted by Gösta H. Lovgren-2 View Post
                  It seems to me that could lead to disasterous consequences (if the area pointed to was near the boundry of a data area segment and te overlay went beyond it and corrupted another program or something).
                  Data segments disapeared with 16 bit, but you are correct, they can be very dangerous as it is up to the programmer to ensure the the amount of memory required for the array has already been allocated as the compiler does not check so easy to cause GPF's. If you think of it in terms of redfining a Union the the memory space must have already been allocated as some other data type such as a String or Array of another type and your absolute Array must not be defined to use more bytes than already allocated, nor can it be later redimmed larger. If redimmed smaller it will not erase or change the contents of the now unused bytes.
                  I use them all the time, my main use is if I want to do a lot of (exclusive) work on a large file of fixed length records which are defined with a UDT. I read the whole file into memory as a String with GET$, Dim an Array of the UDT's equal to the number of records AT the STRPTR, when finished just write the whole String back to the file in one go. Can give dramatic speed increases.
                  John

                  Comment


                  • #10
                    Okay, I think I'm getting a better picture now. In other terms, Dim AT sets aside a block of memory whose address doesn't change as long as the array is "in effect". The programmer can manipulate the contents of that memory block using other techniques such as assigning another array name to that block address and sorting it (as is done in M's ProcessAnyArray procedure.).

                    I think it also gives an insight into how Unions work although I've never used one.

                    Thanks John and all.

                    ==================================
                    "Where are we going,
                    and why am I in this handbasket?"
                    Bumper Sticker
                    ==================================
                    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


                    • #11
                      I think it also gives an insight into how Unions work although I've never used one.
                      Today's bonus... if you learn absolute arrays you just learned UNIONs... and vice-versa.

                      Yesterdays example using a UNION...
                      Code:
                      UNION Foo
                        HELLO_WORLD           AS STRING * 12 
                        CH (1 to 12)              AS STRING *  1
                      END UNION
                      
                      FUNCTION PbMain() AS LONG 
                         LOCAL  F AS Foo, S AS STRING , Z AS LONG
                         F.Hello_World = "Hello, World" 
                         FOR Z = 1 TO 12 
                             S = S & CH (Z)
                        NEXT
                        MSGBOX F.HELLO_WORLD & $CRLF & S 
                      END FUNCTION
                      Last edited by Michael Mattias; 29 Nov 2008, 05:45 PM.
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Originally posted by Gösta H. Lovgren-2 View Post
                        Okay, I think I'm getting a better picture now. In other terms, Dim AT sets aside a block of memory whose address doesn't change as long as the array is "in effect".
                        Close but still not quite correct. DIM AT never sets aside the memory, it expects that memory to have already been set aside, and importantly that it will never change location as long as the DIM AT array is being used.
                        Taking Michaels earlier example and adding a line should explain
                        Code:
                          H$ = "Hello, World" 
                          REDIM cH(LEN(H$)-1) AS STRING * 1 AT STRPTR(H$)
                          H$ = "New Hello, World" 'added line which will almost gaurantee a GPF later
                          FOR X = LBOUND (cH, 1) TO UBOUND (ch,1)
                            PRINT    ch(X) 
                          NEXT
                        So the memory was allocated for the dynamic string H$ and the absolute array cH dimmed at its STRPTR, changing the contents of H$ will cause the string engine to invalidate the originally allocated memory and store the string most likely at a different location. The array cH does not track the change so will now be addressing invalid memory.
                        This is a big difference from a Union as with a Union all the different definitions of the memory space know if the location of the Union variable has moved.
                        John

                        Comment


                        • #13
                          Originally posted by John Petty View Post
                          Close but still not quite correct. DIM AT never sets aside the memory, it expects that memory to have already been set aside, and importantly that it will never change location as long as the DIM AT array is being used.
                          Okay John, I see the distinction and your example clarifies it even further for me.

                          Thanks all for helping me limp along the road.

                          =============================
                          A language is a more ancient
                          and inevitable
                          thing than any state.
                          Joseph Brodsky
                          =============================
                          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
                            Gösta, sometimes it helps to look at the data in a kind of table-like way, so here is a little demo you can watch change as you use it.
                            Code:
                            #PBFORMS Created
                            '--------------------------------------------------------------------------------
                            ' The first line in this file is a PBForms metastatement.
                            ' It should ALWAYS be the first line of the file. Other
                            ' PBForms metastatements are placed at the beginning and
                            ' ending of blocks of code that should be edited using
                            ' PBForms only. Do not edit or delete these
                            ' metastatements or PBForms will not be able to reread
                            ' the file correctly. See the PBForms documentation for
                            ' more information.
                            ' Beginning blocks begin like this: #PBForms Begin ...
                            ' Ending blocks begin like this:    #PBForms End ...
                            ' Other PBForms metastatements such as:
                            '     #PBForms Declarations
                            ' are used to tell PBForms where to insert additional
                            ' code. Feel free to make changes anywhere else in the file.
                            '--------------------------------------------------------------------------------
                            
                            #COMPILE EXE
                            #DIM ALL
                            
                            '--------------------------------------------------------------------------------
                            '   ** Includes **
                            '--------------------------------------------------------------------------------
                            #PBFORMS Begin Includes
                            #IF NOT %DEF(%WINAPI)
                                #INCLUDE "WIN32API.INC"
                            #ENDIF
                            #INCLUDE "PBForms.INC"
                            #PBFORMS End Includes
                            '--------------------------------------------------------------------------------
                            
                            '--------------------------------------------------------------------------------
                            '   ** Constants **
                            '--------------------------------------------------------------------------------
                            #PBFORMS Begin Constants
                            %IDD_DIALOG1    = 101
                            %IDC_BUTTON1    = 1001
                            %IDC_BUTTON2    = 1002
                            %IDC_BUTTON3    = 1003
                            %IDC_BUTTON4    = 1004
                            %IDC_BUTTON5    = 1005
                            %IDC_BUTTON6    = 1006
                            %IDC_BUTTON7    = 1007
                            %IDC_BUTTON8    = 1008
                            %IDC_BUTTON9    = 1009
                            %IDC_LABEL1     = 1010
                            %IDC_LABEL2     = 1011
                            %IDC_LABEL3     = 1012
                            %IDC_LABEL4     = 1013
                            %IDC_LABEL5     = 1014
                            %IDC_LABEL6     = 1015
                            %IDC_LABEL7     = 1016
                            %IDC_LABEL8     = 1017
                            %IDC_LABEL9     = 1018
                            %IDC_BUTTON10   = 1019
                            %IDC_LABEL10    = 1020
                            #PBFORMS End Constants
                            '--------------------------------------------------------------------------------
                            
                            '--------------------------------------------------------------------------------
                            '   ** Declarations **
                            '--------------------------------------------------------------------------------
                            DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
                            DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                            #PBFORMS Declarations
                            '--------------------------------------------------------------------------------
                            
                            '--------------------------------------------------------------------------------
                            FUNCTION PBMAIN()
                                ShowDIALOG1 %HWND_DESKTOP
                            END FUNCTION
                            '--------------------------------------------------------------------------------
                            
                            '--------------------------------------------------------------------------------
                            '   ** CallBacks **
                            '--------------------------------------------------------------------------------
                            CALLBACK FUNCTION ShowDIALOG1Proc()
                             STATIC memStr AS STRING, oSeq() AS LONG, oLseq() AS LONG, oQseq() AS LONG, oSseq() AS LONG
                             STATIC b() AS BYTE, L() AS LONG, q() AS QUAD
                             STATIC sorted, sortedL, sortedQ, sortedS, bAlloc, Lalloc, qAlloc, sAlloc AS LONG
                             LOCAL  showStr AS STRING
                             LOCAL ii AS LONG
                            
                                SELECT CASE CBMSG
                                    CASE %WM_COMMAND
                                        SELECT CASE CBCTL
                                            CASE %IDC_BUTTON1
                                               EXIT FUNCTION
                                            CASE %IDC_BUTTON2
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                   REDIM b(19) AS STATIC BYTE AT STRPTR(memStr)
                                                   FOR ii = 0 TO 19
                                                      showStr = showStr & MKBYT$(b(ii)) & " "
                                                   NEXT
                                                   showStr = showStr & "  ||" & RIGHT$(memStr, 20)
                                                   bAlloc = 1
                                                   CONTROL SET TEXT CBHNDL, %IDC_LABEL2, " " & showStr
                                                   CONTROL SET TEXT CBHNDL, %IDC_LABEL3, " " & showStr
                                                END IF
                                            CASE %IDC_BUTTON3
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                   IF bAlloc = 0 THEN
                                                      ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                      EXIT FUNCTION
                                                   END IF
                                                  IF sorted = 0 THEN
                                                     REDIM oSeq(19) AS STATIC LONG
                                                     FOR ii = 0 TO 19
                                                        oSeq(ii) = ii
                                                     NEXT
                                                     ARRAY SORT b(), TAGARRAY oSeq()
                                                     FOR ii = 0 TO 19
                                                        showStr = showStr & MKBYT$(b(ii)) & " "
                                                     NEXT
                                                     showStr = showStr & "  ||" & RIGHT$(memStr, 20)
                                                     sorted = 1
                                                  ELSE
                                                     ARRAY SORT oSeq(), TAGARRAY b()
                                                     FOR ii = 0 TO 19
                                                        showStr = showStr & MKBYT$(b(ii)) & " "
                                                     NEXT
                                                     showStr = showStr & "  ||" & RIGHT$(memStr, 20)
                                                     sorted = 0
                                                  END IF
                                                     GOSUB update
                                                END IF
                                            CASE %IDC_BUTTON4
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                   REDIM L(9) AS STATIC LONG AT STRPTR(memStr)
                                                   FOR ii = 0 TO 9
                                                      showStr = showStr & MKL$(L(ii)) & " "
                                                   NEXT
                                                   LAlloc = 1
                                                   CONTROL SET TEXT CBHNDL, %IDC_LABEL4, " " & showStr
                                                   CONTROL SET TEXT CBHNDL, %IDC_LABEL5, " " & showStr
                                                END IF
                                            CASE %IDC_BUTTON5
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                   IF LAlloc = 0 THEN
                                                      ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                      EXIT FUNCTION
                                                   END IF
                                                  IF sortedL = 0 THEN
                                                     REDIM oLseq(9) AS STATIC LONG
                                                     FOR ii = 0 TO 9
                                                        oLseq(ii) = ii
                                                     NEXT
                                                     ARRAY SORT L(), TAGARRAY oLseq()
                                                     FOR ii = 0 TO 9
                                                        showStr = showStr & MKL$(L(ii)) & " "
                                                     NEXT
                                                     sortedL = 1
                                                  ELSE
                                                     ARRAY SORT oLseq(), TAGARRAY L()
                                                     FOR ii = 0 TO 9
                                                        showStr = showStr & MKL$(L(ii)) & " "
                                                     NEXT
                                                     sortedL = 0
                                                  END IF
                                                     GOSUB update
                                                END IF
                                            CASE %IDC_BUTTON6
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                   REDIM q(4) AS STATIC QUAD AT STRPTR(memStr)
                                                   FOR ii = 0 TO 4
                                                      showStr = showStr & MKQ$(q(ii)) & " "
                                                   NEXT
                                                   qAlloc = 1
                                                   CONTROL SET TEXT CBHNDL, %IDC_LABEL6, " " & showStr
                                                   CONTROL SET TEXT CBHNDL, %IDC_LABEL7, " " & showStr
                                                END IF
                                            CASE %IDC_BUTTON7
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                   IF qAlloc = 0 THEN
                                                      ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                      EXIT FUNCTION
                                                   END IF
                                                  IF sortedq = 0 THEN
                                                     REDIM oQseq(4) AS STATIC LONG
                                                     FOR ii = 0 TO 4
                                                        oQseq(ii) = ii
                                                     NEXT
                                                     ARRAY SORT q(), TAGARRAY oQseq()
                                                     FOR ii = 0 TO 4
                                                        showStr = showStr & MKQ$(q(ii)) & " "
                                                     NEXT
                                                     sortedQ = 1
                                                  ELSE
                                                     ARRAY SORT oQseq(), TAGARRAY q()
                                                     FOR ii = 0 TO 4
                                                        showStr = showStr & MKQ$(q(ii)) & " "
                                                     NEXT
                                                     sortedQ = 0
                                                  END IF
                                                     GOSUB update
                                                END IF
                                            CASE %IDC_BUTTON8
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                   REDIM s(3) AS STATIC STRING * 10 AT STRPTR(memStr)
                                                   FOR ii = 0 TO 3
                                                      showStr = showStr & s(ii) & " "
                                                   NEXT
                                                   sAlloc = 1
                                                   CONTROL SET TEXT CBHNDL, %IDC_LABEL8, " " & showStr
                                                   CONTROL SET TEXT CBHNDL, %IDC_LABEL9, " " & showStr
                                                END IF
                                            CASE %IDC_BUTTON9
                                                IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                                   IF sAlloc = 0 THEN
                                                      ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                      EXIT FUNCTION
                                                   END IF
                                                  IF sorteds = 0 THEN
                                                     REDIM oSseq(3) AS STATIC LONG
                                                     FOR ii = 0 TO 3
                                                        oSseq(ii) = ii
                                                     NEXT
                                                     ARRAY SORT s(), TAGARRAY oSseq()
                                                     FOR ii = 0 TO 3
                                                        showStr = showStr & s(ii) & " "
                                                     NEXT
                                                     sorteds = 1
                                                  ELSE
                                                     ARRAY SORT oSseq(), TAGARRAY s()
                                                     FOR ii = 0 TO 3
                                                        showStr = showStr & s(ii) & " "
                                                     NEXT
                                                     sorteds = 0
                                                  END IF
                                                     GOSUB update
                                                END IF
                            
                                            CASE %IDC_BUTTON10
                                               RESET oSeq(), oLseq(), oQseq(), oSseq(), b(), L(), q()
                                               RESET sorted, sortedL, sortedQ, sortedS, bAlloc, Lalloc, qAlloc, sAlloc
                                               CONTROL SET TEXT CBHNDL, %IDC_LABEL2, ""
                                               CONTROL SET TEXT CBHNDL, %IDC_LABEL3, ""
                                               CONTROL SET TEXT CBHNDL, %IDC_LABEL4, ""
                                               CONTROL SET TEXT CBHNDL, %IDC_LABEL5, ""
                                               CONTROL SET TEXT CBHNDL, %IDC_LABEL6, ""
                                               CONTROL SET TEXT CBHNDL, %IDC_LABEL7, ""
                                               CONTROL SET TEXT CBHNDL, %IDC_LABEL8, ""
                                               CONTROL SET TEXT CBHNDL, %IDC_LABEL9, ""
                                               memStr = "1234567890123456789012345678901234567890"       'make string mem block
                                               CONTROL SET TEXT CBHNDL, %IDC_LABEL1, " " & memStr
                                        END SELECT
                            
                                    CASE %WM_INITDIALOG
                                        memStr = "1234567890123456789012345678901234567890"       'make string mem block
                                        CONTROL SET TEXT CBHNDL, %IDC_LABEL1, " " & memStr
                                END SELECT
                                EXIT FUNCTION
                                
                               update:
                                IF bAlloc THEN DIALOG POST CBHNDL, %WM_COMMAND, MAKLNG(%IDC_BUTTON2, %BN_CLICKED), 0
                                IF LAlloc THEN DIALOG POST CBHNDL, %WM_COMMAND, MAKLNG(%IDC_BUTTON4, %BN_CLICKED), 0
                                IF QAlloc THEN DIALOG POST CBHNDL, %WM_COMMAND, MAKLNG(%IDC_BUTTON6, %BN_CLICKED), 0
                                IF sAlloc THEN DIALOG POST CBHNDL, %WM_COMMAND, MAKLNG(%IDC_BUTTON8, %BN_CLICKED), 0
                                CONTROL SET TEXT CBHNDL, %IDC_LABEL1, " " & memStr
                               RETURN
                            END FUNCTION
                            '--------------------------------------------------------------------------------
                            
                            '--------------------------------------------------------------------------------
                            '   ** Dialogs **
                            '--------------------------------------------------------------------------------
                            FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
                                LOCAL lRslt AS LONG
                            #PBFORMS Begin Dialog %IDD_DIALOG1->->
                                LOCAL hDlg AS DWORD
                                LOCAL hFont1 AS DWORD
                            
                            
                                DIALOG NEW hParent, "DIM AT Demo", 47, 103, 584, 169, %WS_POPUP OR _
                                    %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR _
                                    %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR %DS_NOFAILCREATE OR _
                                    %DS_SETFONT, %WS_EX_WINDOWEDGE OR %WS_EX_CONTROLPARENT OR %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg
                                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON2, "DIM b(19) AS BYTE AT " + _
                                    "STRPTR(string)", 15, 25, 170, 15
                                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON3, "SORT or re-sort b() (BYTE)", 15, _
                                    40, 170, 15
                                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON4, "DIM L(9) AS LONG AT " + _
                                    "STRPTR(string)", 15, 55, 170, 15
                                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON5, "SORT or re-sort L() (LONG)", 15, _
                                    70, 170, 15
                                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON6, "DIM Q(4) AS QUAD AT " + _
                                    "STRPTR(string)", 15, 85, 170, 15
                                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON7, "SORT or re-sort Q() (QUAD)", 15, _
                                    100, 170, 15
                                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON8, "DIM s(3) AS STRING * 10 AT " + _
                                    "STRPTR(string)", 15, 115, 170, 15
                                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON9, "SORT or re-sort s() (STRING)", 15, _
                                    130, 170, 15
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL1, " ", 190, 10, 380, 15, %WS_CHILD OR _
                                    %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING
                                CONTROL SET COLOR hDlg, %IDC_LABEL1, -1, %WHITE
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL2, " ", 190, 25, 380, 15, %WS_CHILD OR _
                                    %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING
                                CONTROL SET COLOR hDlg, %IDC_LABEL2, -1, %WHITE
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL3, " ", 190, 40, 380, 15, %WS_CHILD OR _
                                    %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING
                                CONTROL SET COLOR hDlg, %IDC_LABEL3, -1, %WHITE
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL4, " ", 190, 55, 380, 15, %WS_CHILD OR _
                                    %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING
                                CONTROL SET COLOR hDlg, %IDC_LABEL4, -1, %WHITE
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL5, " ", 190, 70, 380, 15, %WS_CHILD OR _
                                    %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING
                                CONTROL SET COLOR hDlg, %IDC_LABEL5, -1, %WHITE
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL6, " ", 190, 85, 380, 15, %WS_CHILD OR _
                                    %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING
                                CONTROL SET COLOR hDlg, %IDC_LABEL6, -1, %WHITE
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL7, " ", 190, 100, 380, 15, %WS_CHILD OR _
                                    %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING
                                CONTROL SET COLOR hDlg, %IDC_LABEL7, -1, %WHITE
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL8, " ", 190, 115, 380, 15, %WS_CHILD OR _
                                    %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING
                                CONTROL SET COLOR hDlg, %IDC_LABEL8, -1, %WHITE
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL9, " ", 190, 130, 380, 15, %WS_CHILD OR _
                                    %WS_VISIBLE OR %WS_BORDER OR %SS_LEFT OR %SS_CENTERIMAGE, %WS_EX_LEFT _
                                    OR %WS_EX_LTRREADING
                                CONTROL SET COLOR hDlg, %IDC_LABEL9, -1, %WHITE
                                CONTROL ADD BUTTON, hDlg, %IDC_BUTTON10, "Reset", 55, 150, 85, 15
                                CONTROL ADD LABEL, hDlg, %IDC_LABEL10, "Current string in allocated memory", _
                                    15, 10, 170, 15, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %SS_CENTER _
                                    OR %SS_CENTERIMAGE, %WS_EX_LEFT OR %WS_EX_LTRREADING
                            
                                hFont1 = PBFormsMakeFont("Courier New", 10, 400, %FALSE, %FALSE, %FALSE, %ANSI_CHARSET)
                            
                                CONTROL SEND hDlg, %IDC_LABEL1, %WM_SETFONT, hFont1, 0
                                CONTROL SEND hDlg, %IDC_LABEL2, %WM_SETFONT, hFont1, 0
                                CONTROL SEND hDlg, %IDC_LABEL3, %WM_SETFONT, hFont1, 0
                                CONTROL SEND hDlg, %IDC_LABEL4, %WM_SETFONT, hFont1, 0
                                CONTROL SEND hDlg, %IDC_LABEL5, %WM_SETFONT, hFont1, 0
                                CONTROL SEND hDlg, %IDC_LABEL6, %WM_SETFONT, hFont1, 0
                                CONTROL SEND hDlg, %IDC_LABEL7, %WM_SETFONT, hFont1, 0
                                CONTROL SEND hDlg, %IDC_LABEL8, %WM_SETFONT, hFont1, 0
                                CONTROL SEND hDlg, %IDC_LABEL9, %WM_SETFONT, hFont1, 0
                            
                            #PBFORMS End Dialog
                            
                                DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
                            
                                FUNCTION = lRslt
                            END FUNCTION
                            '--------------------------------------------------------------------------------

                            Comment


                            • #15
                              Gösta, sometimes it helps to look at the data in a kind of table-like way, so here is a little demo you can watch change as you use it.
                              Neat example John. I'll play around with it a little. Thanks.

                              =====================================================
                              "There are some experiences in life
                              which should not be demanded twice from any man,
                              and one of them is listening to the Brahms Requiem."
                              George Bernard Shaw (1856-1950)
                              =====================================================
                              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


                              • #16
                                puzzle solved

                                I don't know if it will lead to a deeper understanding of DIM AT, but while you're messing around with it, see if you can solve it too (fully sort it). It can be done as shown in the screenshot below. I took the screenshot 'cause I may not be able to repeat the solution.
                                Attached Files

                                Comment


                                • #17
                                  Originally posted by John Gleason View Post
                                  I don't know if it will lead to a deeper understanding of DIM AT, but while you're messing around with it, see if you can solve it too (fully sort it). It can be done as shown in the screenshot below. I took the screenshot 'cause I may not be able to repeat the solution.
                                  No solving of "John's" Cube Puzzle, but I did play around with the code John. Took me a little while (what doesn't anymore) but once I chgd the starting string to letters from numbers, much became clear. Changing the Button & Label Ids to more human intelligible names was a BIG help as well.

                                  Code:
                                  'http://www.powerbasic.com/support/pbforums/showthread.php?p=303453#post303453
                                  'John Gleason
                                  #PBForms Created
                                  '--------------------------------------------------------------------------------
                                  ' The first line in this file is a PBForms metastatement.
                                  ' It should ALWAYS be the first line of the file. Other
                                  ' PBForms metastatements are placed at the beginning and
                                  ' ending of blocks of code that should be edited using
                                  ' PBForms only. Do not edit or delete these
                                  ' metastatements or PBForms will not be able to reread
                                  ' the file correctly. See the PBForms documentation for
                                  ' more information.
                                  ' Beginning blocks begin like this: #PBForms Begin ...
                                  ' Ending blocks begin like this:    #PBForms End ...
                                  ' Other PBForms metastatements such as:
                                  '     #PBForms Declarations
                                  ' are used to tell PBForms where to insert additional
                                  ' code. Feel free to make changes anywhere else in the file.
                                  '--------------------------------------------------------------------------------
                                  #Compile Exe
                                  #Dim All
                                  '--------------------------------------------------------------------------------
                                  '   ** Includes **
                                  '--------------------------------------------------------------------------------
                                  #PBForms Begin Includes
                                  #If Not %Def(%WINAPI)
                                      #Include "WIN32API.INC"
                                  #EndIf
                                  #Include "PBForms.INC"
                                  #PBForms End Includes
                                  '--------------------------------------------------------------------------------
                                  '--------------------------------------------------------------------------------
                                  '   ** Constants **
                                  '--------------------------------------------------------------------------------
                                  #PBForms Begin Constants
                                  %IDD_DIALOG1    = 101
                                  %IDC_BUTTON1    = 1001
                                  %Dim_Byte_Btn    = 1002
                                  %Sort_Byte_Btn    = 1003
                                  %Dim_Long_Btn    = 1004
                                  %Sort_Long_Btn    = 1005
                                  %Dim_Quad_Btn    = 1006
                                  %Sort_Quad_Btn    = 1007
                                  %Dim_Single_Btn    = 1008
                                  %Sort_Single_Btn    = 1009
                                  %IDC_LABEL1     = 1010
                                  %Dim_Byte_Lbl     = 1011
                                  %Sort_Byte_Lbl     = 1012
                                  %Dim_Long_Lbl     = 1013
                                  %Sort_Long_Lbl     = 1014
                                  %Dim_Quad_Lbl     = 1015
                                  %Sort_Quad_Lbl     = 1016
                                  %Dim_String_Lbl     = 1017
                                  %Sort_String_Lbl     = 1018
                                  %Reset_Btn   = 1019
                                  %IDC_LABEL10    = 1020
                                  #PBForms End Constants
                                  '--------------------------------------------------------------------------------
                                  %John_Btn = 1021
                                  '--------------------------------------------------------------------------------
                                  '   ** Declarations **
                                  '--------------------------------------------------------------------------------
                                  Declare CallBack Function ShowDIALOG1Proc()
                                  Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
                                  #PBForms Declarations
                                  '--------------------------------------------------------------------------------
                                  '--------------------------------------------------------------------------------
                                  Function PBMain()
                                      ShowDIALOG1 %HWND_DESKTOP
                                      'Call Resort_For_John
                                  End Function
                                  '--------------------------------------------------------------------------------
                                  '--------------------------------------------------------------------------------
                                  '   ** CallBacks **
                                  '--------------------------------------------------------------------------------
                                  CallBack Function ShowDIALOG1Proc()
                                   Static memStr As String, oSeq() As Long, oLseq() As Long, oQseq() As Long, oSseq() As Long
                                   Static b() As Byte, L() As Long, q() As Quad
                                   Static sorted, sortedL, sortedQ, sortedS, bAlloc, Lalloc, qAlloc, sAlloc As Long
                                   Local  showStr As String
                                   Local Start_String As String
                                   Local ii As Long
                                      Select Case CbMsg
                                          Case %WM_INITDIALOG
                                              Start_String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 'try this
                                              memStr = "1234567890123456789012345678901234567890"       'make string mem block
                                              memstr = Start_String
                                              Control Set Text CbHndl, %IDC_LABEL1," " &  memStr
                                          Case %WM_COMMAND
                                              Select Case CbCtl
                                                  Case %IDC_BUTTON1
                                                     Exit Function
                                                  Case %Dim_Byte_Btn
                                                      If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                         ReDim b(19) As Static Byte At StrPtr(memStr)
                                                         For ii = 0 To 19
                                                            showStr = showStr & MkByt$(b(ii)) & " "
                                                         Next
                                                         showStr = showStr & "  ||" & Right$(memStr, 20)
                                                         bAlloc = 1
                                                         Control Set Text CbHndl, %Dim_Byte_Lbl, " " & showStr
                                                         Control Set Text CbHndl, %Sort_Byte_Lbl, " " & showStr
                                                      End If
                                                  Case %Sort_Byte_Btn
                                                      If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                         If bAlloc = 0 Then
                                                            ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                            Exit Function
                                                         End If
                                                        If sorted = 0 Then
                                                           ReDim oSeq(19) As Static Long
                                                           For ii = 0 To 19
                                                              oSeq(ii) = ii
                                                           Next
                                                           Array Sort b(), TagArray oSeq()
                                                           For ii = 0 To 19
                                                              showStr = showStr & MkByt$(b(ii)) & " "
                                                           Next
                                                           showStr = showStr & "  ||" & Right$(memStr, 20)
                                                           sorted = 1
                                                        Else
                                                           Array Sort oSeq(), TagArray b()
                                                           For ii = 0 To 19
                                                              showStr = showStr & MkByt$(b(ii)) & " "
                                                           Next
                                                           showStr = showStr & "  ||" & Right$(memStr, 20)
                                                           sorted = 0
                                                        End If
                                                           GoSub update
                                                      End If
                                                  Case %Dim_Long_Btn
                                                      If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                         ReDim L(9) As Static Long At StrPtr(memStr)
                                                         For ii = 0 To 9
                                                            showStr = showStr & Mkl$(L(ii)) & " "
                                                         Next
                                                         LAlloc = 1
                                                         Control Set Text CbHndl, %Dim_Long_Lbl, " " & showStr
                                                         Control Set Text CbHndl, %Sort_Long_Lbl, " " & showStr
                                                      End If
                                                  Case %Sort_Long_Btn
                                                      If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                         If LAlloc = 0 Then
                                                            ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                            Exit Function
                                                         End If
                                                        If sortedL = 0 Then
                                                           ReDim oLseq(9) As Static Long
                                                           For ii = 0 To 9
                                                              oLseq(ii) = ii
                                                           Next
                                                           Array Sort L(), TagArray oLseq()
                                                           For ii = 0 To 9
                                                              showStr = showStr & Mkl$(L(ii)) & " "
                                                           Next
                                                           sortedL = 1
                                                        Else
                                                           Array Sort oLseq(), TagArray L()
                                                           For ii = 0 To 9
                                                              showStr = showStr & Mkl$(L(ii)) & " "
                                                           Next
                                                           sortedL = 0
                                                        End If
                                                           GoSub update
                                                      End If
                                                  Case %Dim_Quad_Btn
                                                      If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                         ReDim q(4) As Static Quad At StrPtr(memStr)
                                                         For ii = 0 To 4
                                                            showStr = showStr & Mkq$(q(ii)) & " "
                                                         Next
                                                         qAlloc = 1
                                                         Control Set Text CbHndl, %Dim_Quad_Lbl, " " & showStr
                                                         Control Set Text CbHndl, %Sort_Quad_Lbl, " " & showStr
                                                      End If
                                                  Case %Sort_Quad_Btn
                                                      If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                         If qAlloc = 0 Then
                                                            ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                            Exit Function
                                                         End If
                                                        If sortedq = 0 Then
                                                           ReDim oQseq(4) As Static Long
                                                           For ii = 0 To 4
                                                              oQseq(ii) = ii
                                                           Next
                                                           Array Sort q(), TagArray oQseq()
                                                           For ii = 0 To 4
                                                              showStr = showStr & Mkq$(q(ii)) & " "
                                                           Next
                                                           sortedQ = 1
                                                        Else
                                                           Array Sort oQseq(), TagArray q()
                                                           For ii = 0 To 4
                                                              showStr = showStr & Mkq$(q(ii)) & " "
                                                           Next
                                                           sortedQ = 0
                                                        End If
                                                           GoSub update
                                                      End If
                                                  Case %Dim_Single_Btn
                                                      If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                         ReDim s(3) As Static String * 10 At StrPtr(memStr)
                                                         For ii = 0 To 3
                                                            showStr = showStr & s(ii) & " "
                                                         Next
                                                         sAlloc = 1
                                                         Control Set Text CbHndl, %Dim_String_Lbl, " " & showStr
                                                         Control Set Text CbHndl, %Sort_String_Lbl, " " & showStr
                                                      End If
                                                  Case %Sort_Single_Btn
                                                      If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                         If sAlloc = 0 Then
                                                            ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                            Exit Function
                                                         End If
                                                        If sorteds = 0 Then
                                                           ReDim oSseq(3) As Static Long
                                                           For ii = 0 To 3
                                                              oSseq(ii) = ii
                                                           Next
                                                           Array Sort s(), TagArray oSseq()
                                                           For ii = 0 To 3
                                                              showStr = showStr & s(ii) & " "
                                                           Next
                                                           sorteds = 1
                                                        Else
                                                           Array Sort oSseq(), TagArray s()
                                                           For ii = 0 To 3
                                                              showStr = showStr & s(ii) & " "
                                                           Next
                                                           sorteds = 0
                                                        End If
                                                           GoSub update
                                                      End If
                                                  Case %Reset_Btn
                                                     Reset oSeq(), oLseq(), oQseq(), oSseq(), b(), L(), q()
                                                     Reset sorted, sortedL, sortedQ, sortedS, bAlloc, Lalloc, qAlloc, sAlloc
                                                     Control Set Text CbHndl, %Dim_Byte_Lbl, ""
                                                     Control Set Text CbHndl, %Sort_Byte_Lbl, ""
                                                     Control Set Text CbHndl, %Dim_Long_Lbl, ""
                                                     Control Set Text CbHndl, %Sort_Long_Lbl, ""
                                                     Control Set Text CbHndl, %Dim_Quad_Lbl, ""
                                                     Control Set Text CbHndl, %Sort_Quad_Lbl, ""
                                                     Control Set Text CbHndl, %Dim_String_Lbl, ""
                                                     Control Set Text CbHndl, %Sort_String_Lbl, ""
                                                     memStr = "1234567890123456789012345678901234567890"       'make string mem block
                                                     Control Set Text CbHndl, %IDC_LABEL1, "" & memStr & "********"
                                                  '
                                                  Case %John_Btn   
                                                    Call Resort_for_John(CbHndl)
                                              End Select                 
                                   
                                      End Select
                                      Exit Function
                                   
                                     update:
                                      If bAlloc Then Dialog Post CbHndl, %WM_COMMAND, MakLng(%Dim_Byte_Btn, %BN_CLICKED), 0
                                      If LAlloc Then Dialog Post CbHndl, %WM_COMMAND, MakLng(%Dim_Long_Btn, %BN_CLICKED), 0
                                      If QAlloc Then Dialog Post CbHndl, %WM_COMMAND, MakLng(%Dim_Quad_Btn, %BN_CLICKED), 0
                                      If sAlloc Then Dialog Post CbHndl, %WM_COMMAND, MakLng(%Dim_Single_Btn, %BN_CLICKED), 0
                                      Control Set Text CbHndl, %IDC_LABEL1, " " & memStr
                                     Return
                                  End Function
                                  '--------------------------------------------------------------------------------
                                  '--------------------------------------------------------------------------------
                                  '   ** Dialogs **
                                  '--------------------------------------------------------------------------------
                                  Function ShowDIALOG1(ByVal hParent As Dword) As Long
                                      Local lRslt As Long
                                  #PBForms Begin Dialog %IDD_DIALOG1->->
                                      Local hDlg As Dword
                                      Local hFont1 As Dword
                                   
                                      Dialog New hParent, "DIM AT Demo", 47, 103, 584, 169, %WS_POPUP Or _
                                          %WS_BORDER Or %WS_DLGFRAME Or %WS_SYSMENU Or %WS_CLIPSIBLINGS Or _
                                          %WS_VISIBLE Or %DS_MODALFRAME Or %DS_3DLOOK Or %DS_NOFAILCREATE Or _
                                          %DS_SETFONT, %WS_EX_WINDOWEDGE Or %WS_EX_CONTROLPARENT Or %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING Or %WS_EX_RIGHTSCROLLBAR, To hDlg
                                      Control Add Button, hDlg, %Dim_Byte_Btn, "DIM b(19) AS BYTE AT " + _
                                          "STRPTR(string)", 15, 25, 170, 15
                                      Control Add Button, hDlg, %Sort_Byte_Btn, "SORT or re-sort b() (BYTE)", 15, _
                                          40, 170, 15
                                      Control Add Button, hDlg, %Dim_Long_Btn, "DIM L(9) AS LONG AT " + _
                                          "STRPTR(string)", 15, 55, 170, 15
                                      Control Add Button, hDlg, %Sort_Long_Btn, "SORT or re-sort L() (LONG)", 15, _
                                          70, 170, 15
                                      Control Add Button, hDlg, %Dim_Quad_Btn, "DIM Q(4) AS QUAD AT " + _
                                          "STRPTR(string)", 15, 85, 170, 15
                                      Control Add Button, hDlg, %Sort_Quad_Btn, "SORT or re-sort Q() (QUAD)", 15, _
                                          100, 170, 15
                                      Control Add Button, hDlg, %Dim_Single_Btn, "DIM s(3) AS STRING * 10 AT " + _
                                          "STRPTR(string)", 15, 115, 170, 15
                                      Control Add Button, hDlg, %Sort_Single_Btn, "SORT or re-sort s() (STRING)", 15, _
                                          130, 170, 15
                                      Control Add Label, hDlg, %IDC_LABEL1, " ", 190, 10, 380, 15, %WS_CHILD Or _
                                          %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING
                                      Control Set Color hDlg, %IDC_LABEL1, -1, %White
                                      Control Add Label, hDlg, %Dim_Byte_Lbl, " ", 190, 25, 380, 15, %WS_CHILD Or _
                                          %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING
                                      Control Set Color hDlg, %Dim_Byte_Lbl, -1, %White
                                      Control Add Label, hDlg, %Sort_Byte_Lbl, " ", 190, 40, 380, 15, %WS_CHILD Or _
                                          %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING
                                      Control Set Color hDlg, %Sort_Byte_Lbl, -1, %White
                                      Control Add Label, hDlg, %Dim_Long_Lbl, " ", 190, 55, 380, 15, %WS_CHILD Or _
                                          %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING
                                      Control Set Color hDlg, %Dim_Long_Lbl, -1, %White
                                      Control Add Label, hDlg, %Sort_Long_Lbl, " ", 190, 70, 380, 15, %WS_CHILD Or _
                                          %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING
                                      Control Set Color hDlg, %Sort_Long_Lbl, -1, %White
                                      Control Add Label, hDlg, %Dim_Quad_Lbl, " ", 190, 85, 380, 15, %WS_CHILD Or _
                                          %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING
                                      Control Set Color hDlg, %Dim_Quad_Lbl, -1, %White
                                      Control Add Label, hDlg, %Sort_Quad_Lbl, " ", 190, 100, 380, 15, %WS_CHILD Or _
                                          %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING
                                      Control Set Color hDlg, %Sort_Quad_Lbl, -1, %White
                                      Control Add Label, hDlg, %Dim_String_Lbl, " ", 190, 115, 380, 15, %WS_CHILD Or _
                                          %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING
                                      Control Set Color hDlg, %Dim_String_Lbl, -1, %White
                                      Control Add Label, hDlg, %Sort_String_Lbl, " ", 190, 130, 380, 15, %WS_CHILD Or _
                                          %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                          Or %WS_EX_LTRREADING
                                      Control Set Color hDlg, %Sort_String_Lbl, -1, %White
                                      Control Add Button, hDlg, %Reset_Btn, "Reset", 55, 150, 85, 15
                                   
                                      Control Add Button, hDlg, %John_Btn, "Resort", 200, 150, 85, 15
                                   
                                      Control Add Label, hDlg, %IDC_LABEL10, "Current string in allocated memory", _
                                          15, 10, 170, 15, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %SS_CENTER _
                                          Or %SS_CENTERIMAGE, %WS_EX_LEFT Or %WS_EX_LTRREADING
                                      hFont1 = PBFormsMakeFont("Courier New", 10, 400, %FALSE, %FALSE, %FALSE, %ANSI_CHARSET)
                                      Control Send hDlg, %IDC_LABEL1, %WM_SETFONT, hFont1, 0
                                      Control Send hDlg, %Dim_Byte_Lbl, %WM_SETFONT, hFont1, 0
                                      Control Send hDlg, %Sort_Byte_Lbl, %WM_SETFONT, hFont1, 0
                                      Control Send hDlg, %Dim_Long_Lbl, %WM_SETFONT, hFont1, 0
                                      Control Send hDlg, %Sort_Long_Lbl, %WM_SETFONT, hFont1, 0
                                      Control Send hDlg, %Dim_Quad_Lbl, %WM_SETFONT, hFont1, 0
                                      Control Send hDlg, %Sort_Quad_Lbl, %WM_SETFONT, hFont1, 0
                                      Control Send hDlg, %Dim_String_Lbl, %WM_SETFONT, hFont1, 0
                                      Control Send hDlg, %Sort_String_Lbl, %WM_SETFONT, hFont1, 0
                                  #PBForms End Dialog
                                      Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
                                      Function = lRslt
                                  End Function                                                                     
                                  Sub Resort_For_John(hndl As Dword)
                                   Local t, srt() As String
                                   Local ctr, ln As Long
                                     Control Get Text Hndl, %IDC_LABEL1 To t$
                                      t$ = Trim$(t$)
                                      ln = Len(t$)
                                      ReDim srt$(1 To ln) 'create array of ln chars
                                      For ctr = 1 To ln                            
                                         srt$(ctr) = Mid$(t$, ctr, 1)
                                      Next ctr                       
                                      Array Sort srt$() 'sort them
                                      Reset t$
                                      For ctr = 1 To ln 'rearrange them
                                        t$ = t$ & srt$(ctr)
                                      Next ctr  
                                     Control Set Text Hndl, %IDC_LABEL1, t$ 'put it back
                                   
                                   
                                  End Sub
                                  '--------------------------------------------------------------------------------
                                  ==================================
                                  I do not feel obliged to believe
                                  the same God who has endowed us
                                  with sense, reason, and intellect
                                  intended us to forgo their use.
                                  ~ Galileo Galilei
                                  ==================================
                                  Last edited by Gösta H. Lovgren-2; 1 Dec 2008, 10:23 PM.
                                  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


                                  • #18
                                    John, Been fooling around some more with your code. I think I grasp the Dim At concept pretty good now. And a bonus is now I *think* I'm getting a glimmer behind the concept of packed strings though I'll have to explore that further I think.

                                    (Note it helped below a lot when I changed the PBForms generated equates to human meaningful names.)

                                    Code:
                                    'http://www.powerbasic.com/support/pbforums/showthread.php?p=303453#post303453
                                    'John Gleason
                                    #PBForms Created
                                    '--------------------------------------------------------------------------------
                                    ' The first line in this file is a PBForms metastatement.
                                    ' It should ALWAYS be the first line of the file. Other
                                    ' PBForms metastatements are placed at the beginning and
                                    ' ending of blocks of code that should be edited using
                                    ' PBForms only. Do not edit or delete these
                                    ' metastatements or PBForms will not be able to reread
                                    ' the file correctly. See the PBForms documentation for
                                    ' more information.
                                    ' Beginning blocks begin like this: #PBForms Begin ...
                                    ' Ending blocks begin like this:    #PBForms End ...
                                    ' Other PBForms metastatements such as:
                                    '     #PBForms Declarations
                                    ' are used to tell PBForms where to insert additional
                                    ' code. Feel free to make changes anywhere else in the file.
                                    '--------------------------------------------------------------------------------
                                     
                                    #Compile Exe
                                    #Dim All
                                     
                                    '--------------------------------------------------------------------------------
                                    '   ** Includes **
                                    '--------------------------------------------------------------------------------
                                    #PBForms Begin Includes
                                    #If Not %Def(%WINAPI)
                                        #Include "WIN32API.INC"
                                    #EndIf
                                    #Include "PBForms.INC"
                                    #PBForms End Includes
                                    '--------------------------------------------------------------------------------
                                     
                                    '--------------------------------------------------------------------------------
                                    '   ** Constants **
                                    '--------------------------------------------------------------------------------
                                    #PBForms Begin Constants
                                    %IDD_DIALOG1    = 101
                                    %Dim_Byte_Btn    = 1002
                                    %Sort_Byte_Btn    = 1003
                                    %Dim_Long_Btn    = 1004
                                    %Sort_Long_Btn    = 1005
                                    %Dim_Quad_Btn    = 1006
                                    %Sort_Quad_Btn    = 1007
                                    %Dim_Single_Btn    = 1008
                                    %Sort_Single_Btn    = 1009
                                    %Original_String_lbl     = 1010
                                    %Dim_Byte_Lbl     = 1011
                                    %Sort_Byte_Lbl     = 1012
                                    %Dim_Long_Lbl     = 1013
                                    %Sort_Long_Lbl     = 1014
                                    %Dim_Quad_Lbl     = 1015
                                    %Sort_Quad_Lbl     = 1016
                                    %Dim_String_Lbl     = 1017
                                    %Sort_String_Lbl     = 1018
                                    %Reset_Btn   = 1019
                                    '%Original_String_lbl    = 1020
                                    #PBForms End Constants
                                    '--------------------------------------------------------------------------------
                                    %Letters_Btn = 1021
                                    %Mixed_Btn = 1022
                                    '--------------------------------------------------------------------------------
                                    '   ** Declarations **
                                    '--------------------------------------------------------------------------------
                                    Declare CallBack Function ShowDIALOG1Proc()
                                    Declare Function ShowDIALOG1(ByVal hParent As Dword) As Long
                                    #PBForms Declarations
                                    '--------------------------------------------------------------------------------
                                     
                                    '--------------------------------------------------------------------------------
                                    Function PBMain()
                                        ShowDIALOG1 %HWND_DESKTOP
                                    End Function
                                    '--------------------------------------------------------------------------------
                                     
                                    '--------------------------------------------------------------------------------
                                    '   ** CallBacks **
                                    '--------------------------------------------------------------------------------
                                    CallBack Function ShowDIALOG1Proc()
                                     Static memStr As String, oSeq() As Long, oLseq() As Long, oQseq() As Long, oSseq() As Long
                                     Static b() As Byte, L() As Long, q() As Quad
                                     Static sorted, sortedL, sortedQ, sortedS, bAlloc, Lalloc, qAlloc, sAlloc As Long
                                     Local  showStr As String
                                     Static Mixed_String, num_String, Letter_String As String
                                     Local ii As Long
                                     
                                        Select Case CbMsg
                                            Case %WM_INITDIALOG
                                                Letter_String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 'try this
                                                Num_String = "1234567890123456789012345678901234567890"       'make string mem block
                                                Mixed_String = "Now is the time for each man to come to the aid of his party."
                                    '
                                                memstr = Num_String 
                                                'memstr = Letter_String 'use letters instead of numbers
                                                Control Set Text CbHndl, %Original_String_lbl," " &  memStr
                                            Case %WM_COMMAND
                                                Select Case CbCtl
                                                    Case %Dim_Byte_Btn
                                                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                           ReDim b(19) As Static Byte At StrPtr(memStr)
                                                           For ii = 0 To 19
                                                              showStr = showStr & MkByt$(b(ii)) & "|"
                                                           Next
                                                           showStr = showStr & "  ||" & Right$(memStr, 20)
                                                           bAlloc = 1
                                                           Control Set Text CbHndl, %Dim_Byte_Lbl, " " & showStr
                                                           Control Set Text CbHndl, %Sort_Byte_Lbl, " " & showStr
                                                        End If
                                                    Case %Sort_Byte_Btn
                                                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                           If bAlloc = 0 Then
                                                              ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                              Exit Function
                                                           End If
                                                          If sorted = 0 Then
                                                             ReDim oSeq(19) As Static Long
                                                             For ii = 0 To 19
                                                                oSeq(ii) = ii
                                                             Next
                                                             Array Sort b(), TagArray oSeq()
                                                             For ii = 0 To 19
                                                                showStr = showStr & MkByt$(b(ii)) & "|"
                                                             Next
                                                             showStr = showStr & "  ||" & Right$(memStr, 20)
                                                             sorted = 1
                                                          Else
                                                             Array Sort oSeq(), TagArray b()
                                                             For ii = 0 To 19
                                                                showStr = showStr & MkByt$(b(ii)) & " "
                                                             Next
                                                             showStr = showStr & "  ||" & Right$(memStr, 20)
                                                             sorted = 0
                                                          End If
                                                             GoSub update
                                                        End If
                                                    Case %Dim_Long_Btn
                                                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                           ReDim L(9) As Static Long At StrPtr(memStr)
                                                           For ii = 0 To 9
                                                              showStr = showStr & Mkl$(L(ii)) & "|"
                                                           Next
                                                           LAlloc = 1
                                                           Control Set Text CbHndl, %Dim_Long_Lbl, " " & showStr
                                                           Control Set Text CbHndl, %Sort_Long_Lbl, " " & showStr
                                                        End If
                                                    Case %Sort_Long_Btn
                                                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                           If LAlloc = 0 Then
                                                              ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                              Exit Function
                                                           End If
                                                          If sortedL = 0 Then
                                                             ReDim oLseq(9) As Static Long
                                                             For ii = 0 To 9
                                                                oLseq(ii) = ii
                                                             Next
                                                             Array Sort L(), TagArray oLseq()
                                                             For ii = 0 To 9
                                                                showStr = showStr & Mkl$(L(ii)) & "|"
                                                             Next
                                                             sortedL = 1
                                                          Else
                                                             Array Sort oLseq(), TagArray L()
                                                             For ii = 0 To 9
                                                                showStr = showStr & Mkl$(L(ii)) & "|"
                                                             Next
                                                             sortedL = 0
                                                          End If
                                                             GoSub update
                                                        End If
                                                    Case %Dim_Quad_Btn
                                                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                           ReDim q(4) As Static Quad At StrPtr(memStr)
                                                           For ii = 0 To 4
                                                              showStr = showStr & Mkq$(q(ii)) & "|"
                                                           Next
                                                           qAlloc = 1
                                                           Control Set Text CbHndl, %Dim_Quad_Lbl, " " & showStr
                                                           Control Set Text CbHndl, %Sort_Quad_Lbl, " " & showStr
                                                        End If
                                                    Case %Sort_Quad_Btn
                                                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                           If qAlloc = 0 Then
                                                              ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                              Exit Function
                                                           End If
                                                          If sortedq = 0 Then
                                                             ReDim oQseq(4) As Static Long
                                                             For ii = 0 To 4
                                                                oQseq(ii) = ii
                                                             Next
                                                             Array Sort q(), TagArray oQseq()
                                                             For ii = 0 To 4
                                                                showStr = showStr & Mkq$(q(ii)) & "|"
                                                             Next
                                                             sortedQ = 1
                                                          Else
                                                             Array Sort oQseq(), TagArray q()
                                                             For ii = 0 To 4
                                                                showStr = showStr & Mkq$(q(ii)) & "|"
                                                             Next
                                                             sortedQ = 0
                                                          End If
                                                             GoSub update
                                                        End If
                                                    Case %Dim_Single_Btn
                                                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                           ReDim s(3) As Static String * 10 At StrPtr(memStr)
                                                           For ii = 0 To 3
                                                              showStr = showStr & s(ii) & "|"
                                                           Next
                                                           sAlloc = 1
                                                           Control Set Text CbHndl, %Dim_String_Lbl, " " & showStr
                                                           Control Set Text CbHndl, %Sort_String_Lbl, " " & showStr
                                                        End If
                                                    Case %Sort_Single_Btn
                                                        If CbCtlMsg = %BN_CLICKED Or CbCtlMsg = 1 Then
                                                           If sAlloc = 0 Then
                                                              ? "ERROR:  Array not allocated yet, so would likely GPF.", %MB_ICONERROR, "DIM AT Demo"
                                                              Exit Function
                                                           End If
                                                          If sorteds = 0 Then
                                                             ReDim oSseq(3) As Static Long
                                                             For ii = 0 To 3
                                                                oSseq(ii) = ii
                                                             Next
                                                             Array Sort s(), TagArray oSseq()
                                                             For ii = 0 To 3
                                                                showStr = showStr & s(ii) & "|"
                                                             Next
                                                             sorteds = 1
                                                          Else
                                                             Array Sort oSseq(), TagArray s()
                                                             For ii = 0 To 3
                                                                showStr = showStr & s(ii) & "|"
                                                             Next
                                                             sorteds = 0
                                                          End If
                                                             GoSub update
                                                        End If
                                     
                                                    Case %Reset_Btn
                                                       Reset oSeq(), oLseq(), oQseq(), oSseq(), b(), L(), q()
                                                       Reset sorted, sortedL, sortedQ, sortedS, bAlloc, Lalloc, qAlloc, sAlloc
                                    '                   Control Set Text CbHndl, %Dim_Byte_Lbl, ""
                                    '                   Control Set Text CbHndl, %Sort_Byte_Lbl, ""
                                    '                   Control Set Text CbHndl, %Dim_Long_Lbl, ""
                                    '                   Control Set Text CbHndl, %Sort_Long_Lbl, ""
                                    '                   Control Set Text CbHndl, %Dim_Quad_Lbl, ""
                                    '                   Control Set Text CbHndl, %Sort_Quad_Lbl, ""
                                    '                   Control Set Text CbHndl, %Dim_String_Lbl, ""
                                    '                   Control Set Text CbHndl, %Sort_String_Lbl, ""
                                                       memStr = Num_String '"1234567890123456789012345678901234567890"       'make string mem block
                                                       Control Set Text CbHndl, %Original_String_lbl, "" & memStr & "********"
                                                    '
                                                    Case %Letters_Btn               
                                                        memstr = Letter_String 'use letters instead of numbers
                                                         Control Set Text CbHndl, %Original_String_lbl," " &  memStr
                                                    '
                                                    Case %Mixed_Btn
                                                        memstr = Mixed_String 'use Mixed instead of numbers
                                                         Control Set Text CbHndl, %Original_String_lbl," " &  memStr
                                                         
                                                End Select                 
                                               
                                     
                                        End Select
                                      Exit Function
                                        
                                       update: 'simulate Button Clicks
                                        If bAlloc Then Dialog Post CbHndl, %WM_COMMAND, MakLng(%Dim_Byte_Btn, %BN_CLICKED), 0
                                        If LAlloc Then Dialog Post CbHndl, %WM_COMMAND, MakLng(%Dim_Long_Btn, %BN_CLICKED), 0
                                        If QAlloc Then Dialog Post CbHndl, %WM_COMMAND, MakLng(%Dim_Quad_Btn, %BN_CLICKED), 0
                                        If sAlloc Then Dialog Post CbHndl, %WM_COMMAND, MakLng(%Dim_Single_Btn, %BN_CLICKED), 0
                                        Control Set Text CbHndl, %Original_String_lbl, " " & memStr
                                       Return
                                    End Function
                                    '--------------------------------------------------------------------------------
                                     
                                    '--------------------------------------------------------------------------------
                                    '   ** Dialogs **
                                    '--------------------------------------------------------------------------------
                                    Function ShowDIALOG1(ByVal hParent As Dword) As Long
                                        Local lRslt As Long
                                    #PBForms Begin Dialog %IDD_DIALOG1->->
                                        Local hDlg As Dword
                                        Local hFont1 As Dword
                                     
                                     
                                        Dialog New hParent, "DIM AT Demo", 47, 103, 584, 169, %WS_POPUP Or _
                                            %WS_BORDER Or %WS_DLGFRAME Or %WS_SYSMENU Or %WS_CLIPSIBLINGS Or _
                                            %WS_VISIBLE Or %DS_MODALFRAME Or %DS_3DLOOK Or %DS_NOFAILCREATE Or _
                                            %DS_SETFONT, %WS_EX_WINDOWEDGE Or %WS_EX_CONTROLPARENT Or %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING Or %WS_EX_RIGHTSCROLLBAR, To hDlg
                                        Control Add Button, hDlg, %Dim_Byte_Btn, "DIM b(19) AS BYTE AT " + _
                                            "STRPTR(string)", 15, 25, 170, 15
                                        Control Add Button, hDlg, %Sort_Byte_Btn, "SORT or re-sort b() (BYTE)", 15, _
                                            40, 170, 15
                                        Control Add Button, hDlg, %Dim_Long_Btn, "DIM L(9) AS LONG AT " + _
                                            "STRPTR(string)", 15, 55, 170, 15
                                        Control Add Button, hDlg, %Sort_Long_Btn, "SORT or re-sort L() (LONG)", 15, _
                                            70, 170, 15
                                        Control Add Button, hDlg, %Dim_Quad_Btn, "DIM Q(4) AS QUAD AT " + _
                                            "STRPTR(string)", 15, 85, 170, 15
                                        Control Add Button, hDlg, %Sort_Quad_Btn, "SORT or re-sort Q() (QUAD)", 15, _
                                            100, 170, 15
                                        Control Add Button, hDlg, %Dim_Single_Btn, "DIM s(3) AS STRING * 10 AT " + _
                                            "STRPTR(string)", 15, 115, 170, 15
                                        Control Add Button, hDlg, %Sort_Single_Btn, "SORT or re-sort s() (STRING)", 15, _
                                            130, 170, 15
                                        Control Add Label, hDlg, %Original_String_lbl, " ", 190, 10, 380, 15, %WS_CHILD Or _
                                            %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING
                                        Control Set Color hDlg, %Original_String_lbl, -1, %White
                                        Control Add Label, hDlg, %Dim_Byte_Lbl, " ", 190, 25, 380, 15, %WS_CHILD Or _
                                            %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING
                                        Control Set Color hDlg, %Dim_Byte_Lbl, -1, %White
                                        Control Add Label, hDlg, %Sort_Byte_Lbl, " ", 190, 40, 380, 15, %WS_CHILD Or _
                                            %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING
                                        Control Set Color hDlg, %Sort_Byte_Lbl, -1, %White
                                        Control Add Label, hDlg, %Dim_Long_Lbl, " ", 190, 55, 380, 15, %WS_CHILD Or _
                                            %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING
                                        Control Set Color hDlg, %Dim_Long_Lbl, -1, %White
                                        Control Add Label, hDlg, %Sort_Long_Lbl, " ", 190, 70, 380, 15, %WS_CHILD Or _
                                            %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING
                                        Control Set Color hDlg, %Sort_Long_Lbl, -1, %White
                                        Control Add Label, hDlg, %Dim_Quad_Lbl, " ", 190, 85, 380, 15, %WS_CHILD Or _
                                            %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING
                                        Control Set Color hDlg, %Dim_Quad_Lbl, -1, %White
                                        Control Add Label, hDlg, %Sort_Quad_Lbl, " ", 190, 100, 380, 15, %WS_CHILD Or _
                                            %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING
                                        Control Set Color hDlg, %Sort_Quad_Lbl, -1, %White
                                        Control Add Label, hDlg, %Dim_String_Lbl, " ", 190, 115, 380, 15, %WS_CHILD Or _
                                            %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING
                                        Control Set Color hDlg, %Dim_String_Lbl, -1, %White
                                        Control Add Label, hDlg, %Sort_String_Lbl, " ", 190, 130, 380, 15, %WS_CHILD Or _
                                            %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_CENTERIMAGE, %WS_EX_LEFT _
                                            Or %WS_EX_LTRREADING
                                        Control Set Color hDlg, %Sort_String_Lbl, -1, %White
                                        Control Add Button, hDlg, %Reset_Btn, "Numbers String", 55, 150, 85, 15
                                        
                                        Control Add Button, hDlg, %Letters_Btn, "Letters String", 200, 150, 85, 15
                                        Control Add Button, hDlg, %Mixed_Btn, "Mixed String", 345, 150, 85, 15
                                        
                                        Control Add Label, hDlg, %Original_String_lbl, "Current string in allocated memory", _
                                            15, 10, 170, 15, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %SS_CENTER _
                                            Or %SS_CENTERIMAGE, %WS_EX_LEFT Or %WS_EX_LTRREADING
                                     
                                        hFont1 = PBFormsMakeFont("Courier New", 10, 400, %FALSE, %FALSE, %FALSE, %ANSI_CHARSET)
                                     
                                        Control Send hDlg, %Original_String_lbl, %WM_SETFONT, hFont1, 0
                                        Control Send hDlg, %Dim_Byte_Lbl, %WM_SETFONT, hFont1, 0
                                        Control Send hDlg, %Sort_Byte_Lbl, %WM_SETFONT, hFont1, 0
                                        Control Send hDlg, %Dim_Long_Lbl, %WM_SETFONT, hFont1, 0
                                        Control Send hDlg, %Sort_Long_Lbl, %WM_SETFONT, hFont1, 0
                                        Control Send hDlg, %Dim_Quad_Lbl, %WM_SETFONT, hFont1, 0
                                        Control Send hDlg, %Sort_Quad_Lbl, %WM_SETFONT, hFont1, 0
                                        Control Send hDlg, %Dim_String_Lbl, %WM_SETFONT, hFont1, 0
                                        Control Send hDlg, %Sort_String_Lbl, %WM_SETFONT, hFont1, 0
                                     
                                    #PBForms End Dialog
                                     
                                        Dialog Show Modal hDlg, Call ShowDIALOG1Proc To lRslt
                                     
                                        Function = lRslt
                                    End Function                                                                     
                                     
                                    Sub Ltrs_not_Nbrs(hndl As Dword, ltr As String)
                                    ' Local t, srt() As String
                                    ' Local ctr, ln As Long
                                    '   Control Get Text Hndl, %Original_String_lbl To t$
                                    '    t$ = Trim$(t$)
                                    '    ln = Len(t$)
                                    '    ReDim srt$(1 To ln) 'create array of ln chars
                                    '    For ctr = 1 To ln                            
                                    '       srt$(ctr) = Mid$(t$, ctr, 1)
                                    '    Next ctr                       
                                    '    Array Sort srt$() 'sort them
                                    '    Reset t$
                                    '    For ctr = 1 To ln 'rearrange them
                                    '      t$ = t$ & srt$(ctr)
                                    '    Next ctr  
                                       Control Set Text Hndl, %Original_String_lbl, ltr$ 'put it back
                                        
                                        
                                    End Sub
                                    '--------------------------------------------------------------------------------
                                    ============================================================
                                    "The instinct of nearly all societies is
                                    to lock up anybody who is truly free.
                                    First, society begins by trying to beat you up.
                                    If this fails, they try to poison you.
                                    If this fails too,
                                    they finish by loading honors on your head."
                                    Jean Cocteau (1889-1963)
                                    ============================================================
                                    Last edited by Gösta H. Lovgren-2; 2 Dec 2008, 09:55 PM.
                                    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

                                    Working...
                                    X