# How to make an Array

- How to make an Array
  - The Program
  - The Code:
  - The Source

An Array is a list in which different variables of the same datatype can be stored.
You can access each variable by its position in the list, the first variable has got the position number 0.

## The Program

At start time an array of Strings is initialized and filled. If you click the button,
the variables of the array will be displayed.
First you have to add variables to the array with the function Array.Add().
If you have done this, you can access a variable: xyz = Array[x].
You can set a variable: Array[x] = xyz
(see also collections)

## The Code:

    arStr AS String[]

    STATIC PUBLIC SUB Main()
      hForm AS Fmain
      hForm = NEW Fmain
      hForm.show
    END

    PUBLIC SUB _new()
      i AS Integer
      arStr = NEW String[]

'arStr = NEW String[5]
'does NOT work!

      FOR i = 0 TO 4
        arStr.Add(Str(i))
      NEXT
      arStr[3] = " hello"
    END

    PUBLIC SUB Button1_Click()
      i AS Integer
      txt AS String
      FOR i = 0 TO 4
        txt = txt & arStr[i]
      NEXT
      TextLabel1.Text = txt
    END

## The Source

Download