B4J Question Add all items in a type to a list?

Discussion in 'B4J Questions' started by ShaneG30, Jan 23, 2015.

  1. ShaneG30

    ShaneG30 Well-Known Member Licensed User

    I have a type which contains level names, scores, etc and would like to add the names to a list. The list will then be loaded into a ComboBox.

    Example Type Code:
    Code:
    Public TreasureLevels(16As CollectTreasure 'Work In Progress
        TreasureLevels(0).Name = "Tropical Forest"
        TreasureLevels(
    0).Score = 2110
        TreasureLevels(
    0).BaseTime = 420 '7 Minutes
        TreasureLevels(1).Name = "Silver Lake"
        TreasureLevels(
    1).Score = 2920
        TreasureLevels(
    1).BaseTime = 480 '8 Minutes
        TreasureLevels(2).Name = "Thirsty Desert"
        TreasureLevels(
    2).Score = 3340
        TreasureLevels(
    2).BaseTime = 600 '10 Minutes
        TreasureLevels(3).Name = "Twilight Hollow"
        TreasureLevels(
    3).Score = 3240
        TreasureLevels(
    3).BaseTime = 600 '10 Minutes
        TreasureLevels(4).Name = "Shaded Garden"
        TreasureLevels(
    4).Score = 3180
        TreasureLevels(
    4).BaseTime = 480
    I would like to all of the names into a List.
     
  2. stevel05

    stevel05 Expert Licensed User

    Try this:
    Code:
    Dim ScoreNames As List
    ScoreNames.Initialize
    For Each TL As CollectTreasure In TreasureLevels
        ScoreNames.Add(TL.Name)
    Next
    Or

    Code:
    Dim ScoreNames As List
    ScoreNames.Initialize
    For i = 0 to TreasureLevels.Length - 1
        ScoreNames.Add(TreasureLevels(i).Name)
    Next
     
    ShaneG30 likes this.
  3. ShaneG30

    ShaneG30 Well-Known Member Licensed User

    Thanks! I'm trying to make my code as portable as possible so all I have to re-code is the GUI code.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Dim data() As Object = Array("Tropical Forest"2110420, _
    "Silver Lake"2920480, _
    "Thirsy Desert"3340600, _
    "Twilight Hollow"3240600, _
    "Shaded Garden"3180480)
    Dim Scores As Map
    Scores.Initialize
    For i = 0 To data.Length-1 Step 3
       
    Dim tl As CollectTreasure
       tl.Initialize
       tl.Name = data(i)
       tl.Score = data(i + 
    1)
       tl.BaseTime = data(i + 
    2)
       Scores.Put(tl.Name, tl)
    Next
     
    jose luis gudino and ShaneG30 like this.
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