Announcement

Collapse
No announcement yet.

Declaring an ARRAY in a UDT

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

  • Tom Hanlin
    replied
    ArrayDataLength = (UBOUND(Vars,1) - LBOUND(Vars,1) + 1) * SIZEOF(Vars(UBOUND(Vars,1)))

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

    Leave a comment:


  • Michael Mattias
    replied
    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


    Leave a comment:


  • Michael Mattias
    replied
    %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

    Leave a comment:


  • Mike Trader
    replied
    Oh yeah. Thx Bern.
    Why didnt I see that.

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

    Leave a comment:


  • Bern Ertl
    replied
    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

    Leave a comment:


  • Mike Trader
    replied
    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

    Leave a comment:


  • Jules Marchildon
    replied
    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

    Leave a comment:


  • Fred Buffington
    replied
    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.


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

    Leave a comment:


  • Mike Trader
    started a topic Declaring an ARRAY in a UDT

    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).]
Working...
X