{{fbdoc item="title" value="Array Index"}}----
An array index is the number used to access an [[ProPgArrays|Array]] of [[ProPgVariables|Variables]] created using the ##[[KeyPgDim|Dim]]## command.

{{fbdoc item="desc"}}
	The following examples illustrate the use of array elements.
	
	If we have an array ##myArray## with elements of 1 to 10, filled with random data:
%%
Index        Data
1              5
2              2
3              6
4              5
5              9
6              1
7              0
8              4
9              5
10             7
%%
	
	One can access each piece of data separately by pointing to the Index of the array element:
	%%(freebasic)
	Print myArray(5)
	%%
	Printing the data contained in the fifth element of ##myArray## results in an output of:
	%%
	9
	%%
	To change the contents of an array, use it like any other [[ProPgVariables|Variable]]:
	%%(freebasic)
	myArray(3) = 0
	%%
	To print the contents of ##myArray(3)##, use the command:
	%%(freebasic)
	Print myArray(3)
	%%
	Which results in an output of:
	%%
	0
	%%
	Array elements can be indexed using another [[ProPgVariables|Variable]]. In this example we set all elements in our array to zero:
	%%(freebasic)
	Dim a As Integer
	for a = 1 to 10
	  myArray(a) = 0
	next a
	%%
	To change a random array element to a random value:
	%%(freebasic)
	Dim Index As Integer
	Dim Value As Integer
	index = int(rnd(1) * 10) + 1 'This line will simply return a random value between 1 and 10
	Value = int(rnd(1) * 10) + 1 'This line will do the same
	myArray(index) = Value
	%%

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/proguide/arrays/indexing.bas"}}%%(freebasic)
DECLARE SUB PrintArray()

DIM Numbers(1 to 10) AS INTEGER
DIM SHARED OtherNumbers(1 to 10) as INTEGER
dim a as integer

Numbers(1) = 1
Numbers(2) = 2
OtherNumbers(1) = 3
OtherNumbers(2) = 4

PrintArray ()

for a = 1 to 10
 print Numbers(a)
next a

print OtherNumbers(1)
print OtherNumbers(2)
print OtherNumbers(3)
print OtherNumbers(4)
print OtherNumbers(5)
print OtherNumbers(6)
print OtherNumbers(7)
print OtherNumbers(8)
print OtherNumbers(9)
print OtherNumbers(10)

SUB PrintArray ()
 dim a as integer
 for a = 1 to 10
   print otherNumbers(a)
 next a
END SUB
%%

{{fbdoc item="see"}}
	- [[ProPgArrays|Arrays]]
	- ##[[KeyPgDim|Dim]]##
	- ##[[KeyPgFunction|Function]]##
	- ##[[KeyPgSub|Sub]]##
	- [[ProPgVariables|Variables]] 
	- [[ProPgVariableScope|Variable Scope]]
	- ##[[TblVarTypes|Standard Data Type Limits]]##

{{fbdoc item="back" value="CatPgProgrammer|Programmer's Guide"}}