Android Question sizeof(x) equivalent b4a

Discussion in 'Android Questions' started by MbedAndroid, Mar 11, 2015.

  1. MbedAndroid

    MbedAndroid Active Member Licensed User

    already searched forum, but how to determin a size of array or type in B4a?
    For random acess i need to forward the point to a offset i*sizeof(y) where i is the pointer to the stored location and y and var which holds the type of vars
     
  2. TheJinJ

    TheJinJ Active Member Licensed User

    Is this what your after? Apologies if not...

    Code:
    Dim myArray(10As List
    Log(myArray.Length)
     
  3. MbedAndroid

    MbedAndroid Active Member Licensed User

    doesnt work
    i need to know the sizeof spots
    Code:
    Type SPOTSLABELS  (spotname As String,  positie As Position, Date As String, Time As String)
    Dim Spots As SPOTSLABELS
    /[code]
    spots.length doesnt work
     
  4. TheJinJ

    TheJinJ Active Member Licensed User

    Could you use

    Code:
    Spots.spotname.Length
     
  5. MbedAndroid

    MbedAndroid Active Member Licensed User

    it works for 1 var inside the type
    i could make a adding of all the var's inside the type, that should work, but there must be a much easier way, only i dont know the equivalent in basic or b4a basic
    Normally in #c you say sizeof(array) etc
     
  6. TheJinJ

    TheJinJ Active Member Licensed User

    EDIT...not any use...I think you need to manually calculate the size of the array
     
  7. stevel05

    stevel05 Expert Licensed User

    A Type is actually a class, the variables it holds are available by reference.

    If you explain what you are trying to achieve it may be possible to get the result in different ways.
     
  8. MbedAndroid

    MbedAndroid Active Member Licensed User

    tried, compiler error for type
     
  9. MbedAndroid

    MbedAndroid Active Member Licensed User

  10. MbedAndroid

    MbedAndroid Active Member Licensed User

    i'm saving several files, random each of type "spots" To index the pointer i need to know the size of "spots". I found this manually (304 bytes) so the application is working

    the best way is to count each var inside the type like Erel mentioned in his answer. Basic doesnt seem to have a equivalent command of sizeof in C#
     
  11. stevel05

    stevel05 Expert Licensed User

    If the Type holds non string variables then the length would be dependent on the value of the variable value, if the values are numeric, you could cast them to a string and measure their length but if they are boolean or another class or type then it would be more complicated.
     
    Last edited: Mar 11, 2015
  12. MbedAndroid

    MbedAndroid Active Member Licensed User

    one way is to set the length much larger then the actual size of type. Then the file contains blocks where the type will fit. This works, but not a nice way...
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    Two options:
    1. Add all the type instances to a List and save the list with WriteB4XObject. You can then load the list and work with it.
    2. Use KeyValueStore class.
     
  14. Yalçın Kondur

    Yalçın Kondur Member Licensed User

    I'm not sure if an equvalent of Delphi's SizeOf(TRecord) command exists in B4A.

    Edit: Where did Delphi come to my mind?
     
    Last edited: Mar 11, 2015
  15. DonManfred

    DonManfred Expert Licensed User

    Right. but you are not defining a array! You have definied just a single variable (a customtype).
     
  16. DonManfred

    DonManfred Expert Licensed User

    You can use a list instead of a customtype. You then can get the lists length.
     
  17. MbedAndroid

    MbedAndroid Active Member Licensed User

    [​IMG] Size AsInt [read only]
    Returns the number of items in the list.
    size only returns the number of items, not the total size in bytes
    if Erel should release a C#4a i would buy it right away....
     
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