How to assign values into an array ?

jotis1

Member
Dear Friends/Erel,

Please see my program. It is simple.

Sub Globals
Dim NumberArray(0)
End Sub

Sub App_Start
NumberArray() = Array()
For i=0 To 4 Step+1
NumberArray(i) =i
Msgbox( NumberArray(i))
Next
End Sub




Here I can not assign values to my NumberArray.
Expected Output is 0 1 2 3 4 in Message box

Error description is
Index was outside the bounds of the array. Continue ?


I understood that the error in
NumberArray() = Array()

But I am not sure.

I just edited it with coma as like
NumberArray() = Array(,,,,,,,)

Now it is working.

So My question How can I give the size of the Array with out comma.
Can you help me for better program? :sign0085::sign0085:

rgds
Jotis
 
Last edited:

jotis1

Member
Hi Erel,

I changed my question with another program. Please see my question again
rgds
Jotis:sign0085::sign0085:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are using Array incorrectly.
Here are some examples:
B4X:
NumberArray() = Array(0,1,2,3,4)
B4X:
[COLOR=Navy]Sub Globals
      Dim NumberArray(5)    'Set the size in the declaration.
End Sub

Sub App_Start
         For i=0 To 4 Step+1
    [B][COLOR=Red]NumberArray(i) =i[/COLOR][/B]
    Msgbox( NumberArray(i)) 
    Next
End Sub
[/COLOR]
B4X:
[COLOR=Navy]Sub Globals
      Dim NumberArray(0)    
End Sub

Sub App_Start
    [B][COLOR=Red]Dim NumberArray(5) 'Redim the array[/COLOR][/B]
    For i=0 To 4 Step+1
    [B][COLOR=Red]NumberArray(i) =i[/COLOR][/B]
    Msgbox( NumberArray(i)) 
    Next
End Sub
[/COLOR]
 
Top