Announcement

Collapse
No announcement yet.

Sort of type array

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

  • Sort of type array

    Hi,

    I´m using PB Dos 3.5 and this code errors with 477: why ?

    type tee
    t(1 to 10) as string *2
    end type

    dim d as tee

    dd$=" 1 2 3 4 5 6 7 8 910"
    lset d=dd$

    array sort d.t(),descend '--- this is the error line

    Thanks for help

    Matthias Kuhn

    ------------------

  • #2
    Because tables in UDTs (aka "embedded arrays") are not arrays and may not be used as objects of any of the ARRAY functions.

    ARRAY SORT|SCAN|INSERT|DELETE require 'real' arrays; so you create one:
    Code:
    type tee
      t(1 to 10) as string * 2
    end type
    dim d as tee
    dd$    = " 1 2 3 4 5 6 7 8 910"
    lset d = dd$
    
    REDIM    dt(1 to 10) AS STRING * 2 AT VARPTR(d.t(1))
    ARRAY    SORT   dt(), DESCEND
    MCM


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

    Comment


    • #3
      Your best bet in this case is to copy the data that you want to sort on
      in the type to another array, and then use the TAGARRAY option to tag
      UDT on to the Array Sort.

      eg.

      Code:
      Type MyType
        FirstName As Asciiz * 20
        LastName  As Asciiz * 20
        Address1  As Asciiz * 30
        Address2  As Asciiz * 30
        City      As Asciiz * 20
        St        As Asciiz * 10
        ZipCode   As Asciiz * 12
      End Type
       
      Dim MyArray(1:10) As MyType
       
      ' To sort the above arry on the last name field do this:
       
      Dim Temp(1:10) As String ' or whatever type is needed
       
      For x = 1 to 10
         Temp(x) = MyArray(x).LastName
      Next x
       
      Array Sort Temp(), TagArray MyArray()  ' Sort it!
      This method will allow you to sort a UDT on any Field or Fields needed
      for your particular aplication.



      ------------------
      Scott Slater
      Summit Computer Networks, Inc.
      www.summitcn.com
      Scott Slater
      Summit Computer Networks, Inc.
      www.summitcn.com

      Comment


      • #4
        Hallo,

        Michael, I´ve understood. My idea was to read in the data very
        quick. But why do You use '* 2 AT VARPTR(d.t(1))' ?

        Scott good idea.
        But I´m not shure if diffent array types worked right with
        tagarray but I´ll test it. The next point is that I´ve 20000
        elements to sort(Barcodes) and I´ve only less memory in DOS.

        Thanks for answere.

        Matthias Kuhn


        ------------------


        [This message has been edited by Matthias Kuhn (edited October 13, 2003).]

        Comment


        • #5
          But why do You use '* 2 AT VARPTR(d.t(1))' ?
          Help file:
          Code:
          DIM var[(subscripts)] [AS [GLOBAL | LOCAL | STATIC] type] _
           [PTR | POINTER][AT address] [, ...]
          address=VARPTR
          [later}
          OOOPS... this is PB/DOS... change that to VARPTR32
          [/later]

          MCM




          [This message has been edited by Michael Mattias (edited October 14, 2003).]
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Originally posted by Matthias Kuhn:
            Scott good idea.
            But I´m not shure if diffent array types worked right with
            tagarray but I´ll test it. The next point is that I´ve 20000
            elements to sort(Barcodes) and I´ve only less memory in DOS.
            The TagArray works fine that way. I've used it for years...

            If you are running short on memory, then you can always go to the
            old fassioned disk based sort using a pair of files.




            ------------------
            Scott Slater
            Summit Computer Networks, Inc.
            www.summitcn.com
            Scott Slater
            Summit Computer Networks, Inc.
            www.summitcn.com

            Comment

            Working...
            X