Custom types, again

Discussion in 'Questions (Windows Mobile)' started by skipper, Sep 19, 2009.

  1. skipper

    skipper Member Licensed User

    Hello all,

    I'm trying to mimic in B4ppc the VB old style user defined types.

    type xxx
    as integer
    as string * 12
    as long
    end type

    dim pippo as xxx
    So, "" was referring to an integer 2 bytes long, "pippo.bbb" to a string 12 bytes long and so on. Because I need fixed lenght fields to be filled with an ArrayCopy and then converted using the BytesConverter library by Agraham, I was trying to use

    Dim aaa(4as Byte
    Dim bbb(8as Byte
    Dim ccc(31as Byte
    Dim Type(aaa, bbb, ccc) myVar
    in order to get a "" as an array of Bytes 4 bytes long, "myVar.ccc" as an array of bytes
    31 bytes long and so on...

    Perhaps I'm wasting my (and your) time. ArrayLen( returns 8. What's wrong?

  2. agraham

    agraham Expert Licensed User

    You have misunderstood what a structure variable is in Basic4ppc. It is an array with predefined constant symbolic accessors. Their names are independent of other variable and array names.
    Dim aaa(4as Byte ' array of 4 bytes
    Dim bbb(8as Byte ' array of 8 bytes
    Dim ccc(31as Byte ' array of 31 bytes
    Dim Type(aaa, bbb, ccc) myVar ' array of 3 variables aaa=0, bbb= 1 ...
    ' is the same as myVar(0)
    ' myVar.bbb is the same as myVar(1)
    I don't know how you get that to run as its errors on my system :confused:
    Last edited: Sep 19, 2009
  3. skipper

    skipper Member Licensed User

    Thank you, Andrew

    you are right. I misunderstood the B4PPC online help. Is there a simple way to logically group (one of the advantage of structure) byte variables of different lenght (apart prefixing them with a symbolic string)?

    Dim Body_aaa(4as Byte
    Dim Body_bbb(8as Byte
    Dim Body_ccc(31as Byte
  4. agraham

    agraham Expert Licensed User

    I would do something like
    Dim Body(4+8+31As Byte
    Int32_aaa = 
    Dbl_bbb = 
    Str31_cccc = 


    aaa = Conv.Int32FromBytes(Body, Int32_aaa)
    bbb = Conv.DoubleFromBytes(Body, Dbl_bbb)
    ccc = Conv.String0FromBytes(Body, Str12_cccc)
  5. Erel

    Erel Administrator Staff Member Licensed User

    Currently structures only support a single regular type. More complex structures may be supported in the future.
  6. Erel

    Erel Administrator Staff Member Licensed User

    Interesting suggestion. I assume that 'conv' is a ByteConverter object.
  7. agraham

    agraham Expert Licensed User

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice