Brackets for arrays

In my Basic code sometimes when I use round brackets (parentheses) for array access (eg. MyArray(2)) I will get an error saying MyArray is not a function. The only work around I’ve found is to use the Java format square brackets (eg. MyArray[2]) - is this normal?

JavaScript uses square brackets for arrays. BASIC can use either round or square.

The BASIC to JavaScript Translator will translate BASIC’s round brackets to square ones if it can figure out that you mean an array and not a function call. It does that by looking for a Dim myVar[] statement which declares the variable to be an array.

You’ll need to have one in the code module itself. If it is in a different code module or form, the Translator will not know that you mean it to be an array. It’s OK to have multiple DIM statements for the same array in different modules - nothing will get messed up.

I have the following code where GameBetsArray is defined in the same function it is used, but I still get an error saying GameBetsArray is not a function - if I use square brackets (GameBetsArray[i][0] and GameBetsArray[i][1]) I don’t get the error. The UBound(GameBetsArray) never seems to have a problem.

  Dim GameBetsArray = Array()
  For i = 0 To results.rows.length-1
  If GameSelect.ListCount > 1 Then
    Game1Value.value = 0
    For i = 0 To UBound(GameBetsArray)
      If GameBetsArray(i,0) = GameSelect.List(1) Then
        Game1Value.value = GameBetsArray(i,1)
        Exit For
      End If
 End If

What happens if you do this:

Dim GameBetsArray()

George Henne
NS BASIC Corporation

That solves the bracket problem, but then the first Push into the array puts the elements in (1,0) and (1,1) and not (0,0) and (0,1) (GameBetsArray(0,0) is undefined)

What is your push statement exactly?

(Tip: when entering code using the web interface of this board, use the </> icon to format the code nicely)

It’s the Push statement shown in the code at the top of this discussion

I see what you mean now - if I use both of the following statements I get the results I want:

Dim GameBetsArray()
GameBetsArray = Array()