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.

    Code:
    type xxx
      aaa 
    as integer
      bbb 
    as string * 12
      ccc 
    as long
      ...
    end type

    dim pippo as xxx
    So, "pippo.aaa" 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

    Code:
    Dim aaa(4as Byte
    Dim bbb(8as Byte
    Dim ccc(31as Byte
    Dim Type(aaa, bbb, ccc) myVar
    in order to get a "myVar.aaa" 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(myVar.aaa) returns 8. What's wrong?

    Thanks,
    Mimmo
     
  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.
    Code:
    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 ...
    ' myVar.aaa 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)?

    Code:
    Dim Body_aaa(4as Byte
    Dim Body_bbb(8as Byte
    Dim Body_ccc(31as Byte
    Regards
    Mimmo
     
  4. agraham

    agraham Expert Licensed User

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

    ....

    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

    Yup!
     
Loading...
  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