# How to make a Collection

- How to make a Collection
  - The Program
  - The Code:
  - The Source

A Collection is like an Array, but in a Collection you can store variables of different datatypes!

## The Program

At start time, two collections are instantiated and filled with variables of different datatypes.
The variables have to be added with Collection.Add(variable AS variant, key AS String)
In col1 I use Integers as keys, but they are interpreted as strings!
To prove that the variables really are of different datatypes, their datatype is tested before they are displayed.

## The Code:

    col1 AS NEW collection
    col2 AS NEW collection

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

    PUBLIC SUB _new()
       col1.Add("hello", 1)
       col1.Add(5.7,  2)
       col1.Add(876,  3)
       col1.Add(TRUE,  4)

       col2.Add("hello", "a")
       col2.Add(5.7,  "b")
       col2.Add(876,  "c")
       col2.Add(TRUE,  "d")
    END

    PUBLIC SUB Button1_Click()
       ltxt AS String
       rtxt AS String

       IF IsString(col1[1]) THEN
        ltxt = ltxt & col1[1] & " is String<br>"
       ELSE
         ltxt = ltxt & col1[1] & " is no String<br>"
       ENDIF
       IF IsFloat(col1[2]) THEN
        ltxt = ltxt & col1[2] & " is Float<br>"
       ELSE
        ltxt = ltxt & col1[2] & " is no Float<br>"
       ENDIF
       IF IsInteger(col1[3]) THEN
        ltxt = ltxt & col1[3] & " is Integer<br>"
       ELSE
        ltxt = ltxt & col1[3] & " is no Integer<br>"
       ENDIF
       IF IsBoolean(col1[4]) THEN
        ltxt = ltxt & col1[4] & " is Boolean<br>"
       ELSE
        ltxt = ltxt & col1[4] & " is no Boolean<br>"
       ENDIF
       TextLabel1.Text= ltxt & col1.Count

'----------------------------------------

       IF IsString(col2["a"]) THEN
         rtxt = rtxt & Str(col2["a"]) & " is String<br>"
        ELSE
          rtxt = rtxt & Str(col2["a"]) & " is no String<br>"
        ENDIF
        IF IsFloat(col2["b"]) THEN
         rtxt = rtxt & Str(col2["b"]) & " is Float<br>"
        ELSE
         rtxt = rtxt & Str(col2["b"]) & " is no Float<br>"
        ENDIF
        IF IsInteger(col2["c"]) THEN
         rtxt = rtxt & Str(col2["c"]) & " is Integer<br>"
        ELSE
         rtxt = rtxt & Str(col2["c"]) & " is no Integer<br>"
        ENDIF
        IF IsBoolean(col2["d"]) THEN
         rtxt = rtxt & Str(col2["d"]) & " is Boolean<br>"
        ELSE
         rtxt = rtxt & Str(col2["d"]) & " is no Boolean<br>"
        ENDIF
        TextLabel2.Text= rtxt & col2.Count
    END

## The Source

Download