Android Question create an array of types and every element gets set to the same value

Discussion in 'Android Questions' started by tmf, Jun 10, 2015.

  1. tmf

    tmf Member Licensed User

    Type devv (deviceonoff As Boolean, devicekind As Int, devicefill As Int, devicepeaks As Int, devicemode As Int, devicechain As Int,devicecount As Int,brightness As Int,deviceflipx As Boolean,deviceflipy As Boolean,deviceenabled As Boolean,r(2) As Int,g(2) As Int,b(2) As Int,peakholds As Int,peakdecays As Int,fillholds As Int,filldecays As Int,devicevu As Boolean,length As Int)

    Dim devices(6) As devv

    when I set devices(0).devicekind = 1 all in the array get set the same

    to verify it was not some odd code I would take out devicekind from type and just make

    dim devicekind(6) as int and recode for that and all ok.... so its a mystery.

    Richard.
     
  2. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

  3. tmf

    tmf Member Licensed User

    OK I have read it and studied it and do not get it....

    I declare mine once in globals() and thats it....

    Richard.
     
  4. tmf

    tmf Member Licensed User

    So when I used the TYPE declaration:
    devices(0).dname = st is a reference (pointer to st)
    and when I use
    dname(0) = st its a value (not a pointer?)
     
  5. LucaMs

    LucaMs Expert Licensed User

    Have you initialized each element of the array?

    Dim devices(6) As devv

    devices(0).Initialize
    devices(1).Initialize
    ...

    ?

    I prefer classes :)
     
    Enrique Gonzalez R likes this.
  6. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    something like this

    For i = 0 To 9
    Dim devices as devv
    Devices(I).devicekind =1
    Next

    I insist is "kind of"
     
    LucaMs likes this.
  7. tmf

    tmf Member Licensed User

    Yes I have, if I initialize or not it does the same thing.
     
  8. tmf

    tmf Member Licensed User

    Enrique I do not think that will work, how is that an array??
     
  9. LucaMs

    LucaMs Expert Licensed User

    this works without problems:

    Code:
    Sub Process_Globals

    Type devv(deviceonoff As Boolean, devicekind As Int)
    Private devices(6As devv

    End Sub

    Code:
    devices(0).Initialize
    devices(
    1).Initialize
     
    devices(
    0).devicekind = 1
     
    Log(devices(0).devicekind)
    Log(devices(1).devicekind)
    Log(devices(2).devicekind)
     
  10. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    Sorry I am writing this from my cellphone,

    Dim devices(6) as devv

    For I to devices.length - 1
    Dim device as Dev
    Device.initialize(...)
    Devices(I) = device
    Next

    In this way the other memory allocation will be different for every device you enter in the array.
     
    LucaMs likes this.
Loading...