Array within an Array

In Basic when I create an array within an array the compiler seems to get confused. For example:

Dim Tees()
if i = 0 then
  Tees(0) = Array(TeeName,TeeRating,TeeSlope)
else
   Push(Tees,Array(TeeName,TeeRating,TeeSlope))
end if

translates to

if (i == 0) {
    Tees[0] = new Array[TeeName][TeeRating][TeeSlope];
} else {
     Push(Tees, Array[TeeName][TeeRating][TeeSlope]);
}

(Doesn’t this just put a single element into the Tees array? I want to put an array containing three elements (TeeName, TeeRating, and TeeSlope) into the Tees array.)

Shouldn’t it translate to

if (i == 0) {
    Tees[0] = new Array(TeeName,TeeRating,TeeSlope);
} else {
     Push(Tees, Array(TeeName,TeeRating,TeeSlope);
}

or am I doing something wrong to create an array within an array

You’re right - that’s wrong! The problem is in the Translator.

Can you tell me what the final data structure should look like? I can then suggest a workaround.

Share your story with the AppStudio Community! Quarantine Stories

Here’s an example

  Push(GolfCourseArray, _
    Array("Balboa Park","San Diego,CA",0,"",0,"", _
      Array(Array(0,4,5,4,4,4,3,5,4,3,4,4,4,3,5,4,5,3,4), _
            Array(0,15,5,9,1,13,3,7,17,11,6,10,4,18,12,14,2,16,8), _
            Array(Array("Blue",71.2,125), _
                  Array("White",68.7,119), _
                  Array("Red",66.8,114))), _
      Array(Array(0,4,5,4,4,4,3,5,4,3,4,4,4,3,5,4,5,3,4), _
            Array(0,10,4,12,8,14,6,2,18,16,5,11,7,17,3,15,1,13,9), _
            Array(Array("Blue",77.5,134), _
                  Array("White",74.2,129), _
                  Array("Red",72.8,128)))))

Dim GolfCourseArray()
Const COURSENAME         = 0
Const COURSELOCATION     = 1
Const HOLE19PAR          = 2
Const HOLE19LABEL        = 3
Const HOLE19PREVIOUS     = 4
Const COURSEHOLENOTES    = 5
Const MENS               = 6
Const WOMENS             = 7 
'Definition for MENS & WOMENS
  Const PARS             = 0 'Indexed by hole number
  Const HDCPS            = 1 'Indexed by hole number
  Const TEES             = 2
'Definition for TEES
    Const TEE            = 0
    Const RATING         = 1
    Const SLOPE          = 2
    Const ALTHOLE1       = 3
    Const ALTPAR1        = 4
    Const ALTHOLE2       = 5
    Const ALTPAR2        = 6

Pretty complex! It would be easier to simply use JavaScript notation here. JS refers to arrays using square brackets instead of round. When you do this, you don’t need the Array() function any more:

GolfCourseArray = []
  Push(GolfCourseArray, _
    ["Balboa Park","San Diego,CA",0,"",0,"", _
      [[0,4,5,4,4,4,3,5,4,3,4,4,4,3,5,4,5,3,4], _
            [0,15,5,9,1,13,3,7,17,11,6,10,4,18,12,14,2,16,8], _
            [["Blue",71.2,125], _
                  ["White",68.7,119], _
                  ["Red",66.8,114]]], _
      [[0,4,5,4,4,4,3,5,4,3,4,4,4,3,5,4,5,3,4], _
            [0,10,4,12,8,14,6,2,18,16,5,11,7,17,3,15,1,13,9], _
            [["Blue",77.5,134], _
                  ["White",74.2,129], _
                  ["Red",72.8,128]]]])

Here’s what console.log then shows:
Screen Shot 2020-04-08 at 11.07.46 AM

Share your story with the AppStudio Community! Quarantine Stories