Announcement

Collapse
No announcement yet.

Declaring an ARRAY in a UDT

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

    Declaring an ARRAY in a UDT

    IM trying to declare an array in a TYPE because later
    I poke the whole UDT into a string and send it to Mapped
    memory for sharing between processes.

    I thought I had dont this before but I guess not.

    GLOBAL TXString AS STRING, RXString AS STRING

    TYPE TSDataType
    Vars() AS SINGLE ' does not compile
    END TYPE

    GLOBAL RXData AS TSDataType, TXData AS TSDataType
    '
    '
    TXString = PEEK$(VARPTR(TXData), LEN(TXData))
    POKE$ hMap, TXString ' transfer to SHARED Memory

    and vice versa for RX

    RXString = PEEK$(hMap, LEN(RXData)) 'Recover from Shared Memory
    POKE$ VARPTR(RXData), RXString
    Var1 = RXData.Vars(1)
    Var2 = RXData.Vars(2)

    I guess the problem is that I have not Dimensioned the SINGLE
    array so the TYPE does not know how large it is?



    [This message has been edited by Mike Trader (edited September 27, 2001).]

    #2
    Mike, what is more commonly used i think is an array as a UDT.
    This way, it seems you could even redim without problems i
    would think.


    ------------------
    Client Writeup for the CPA

    buffs.proboards2.com

    Links Page

    Comment


      #3
      I guess the problem is that I have not Dimensioned the SINGLE
      array so the TYPE does not know how large it is?
      Short answer, Yep!

      Regards,
      Jules

      Comment


        #4
        My problem is that I have written this to poke the start address
        and length which is easy to get from a UDT that contains all the
        data.

        How would I put the contents of a SINGLE array into my string?
        GLOBAL Vars() as SINGLE
        '
        '
        Dim Vars(200)
        '
        '
        Var(0) = 4543
        Var(1) = 3457
        Var(2) = 7568
        '
        '
        TXString = PEEK$(VARPTR(Var(0)), LEN(????)) ' help !

        POKE$ hMap, TXString


        ------------------
        Kind Regards
        Mike

        Comment


          #5
          Mike,

          The LEN can be calculated as a function of the # of elements.
          You know that a single requires 4 bytes, so:

          %ElementSize = 4

          LEN = UBOUND( Vars() ) * %ElementSize

          201 elements * 4 bytes = 804 in your example



          ------------------
          Bernard Ertl
          Bernard Ertl
          InterPlan Systems

          Comment


            #6
            Oh yeah. Thx Bern.
            Why didnt I see that.

            ------------------
            Kind Regards
            Mike

            Comment


              #7
              %ElementSize = 4
              LEN = UBOUND( Vars() ) * %ElementSize
              ArrayDataLength = (UBOUND(Vars,1) - LBOUND(Vars,1) + 1) * SIZEOF(Vars(1))

              Using LBOUND, UBOUND and SIZEOF you don't have to remember anything or set up equates.

              MCM

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

              Comment


                #8
                Code:
                TYPE TSDataType
                  Vars() AS SINGLE ' does not compile
                END TYPE
                Tables embedded n UDTs require explicit dimensions to compile, as table size is fixed at compile time.

                Code:
                TYPE TsDataType
                  Vars (0 to 999) AS SINGLE
                END TYPE
                MCM


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

                Comment


                  #9
                  ArrayDataLength = (UBOUND(Vars,1) - LBOUND(Vars,1) + 1) * SIZEOF(Vars(UBOUND(Vars,1)))

                  ------------------
                  Tom Hanlin
                  PowerBASIC Staff

                  Comment

                  Working...
                  X
                  😀
                  🥰
                  🤢
                  😎
                  😡
                  👍
                  👎