Microsoft Small Basic

Program Listing: JSM615-0
' These are samples for Array object and arrays.
' Program ID JSM615-0

' To set value to array

shape["shape"] = "Rectangle" ' set value
shape["color"] = "Lime" ' set value
TextWindow.WriteLine(shape) ' shape=Rectangle;color=Lime;

' To get value from array

shape["color"] = "Lime" ' set value
color = shape["color"] ' get value
TextWindow.WriteLine(color) ' Lime

' To remove value from array

shape["shape"] = "Rectangle" ' set value
shape["color"] = "Lime" ' set value
shape["color"] = "" ' remove value
TextWindow.WriteLine(shape) ' shape=Rectangle;

' ContainsIndex operation

param["x"] = 200
param["y"] = 100
If Array.ContainsIndex(param, "x") Then
TextWindow.WriteLine(param["x"]) ' 200
EndIf

' ContainsValue operation

param["x"] = 200
param["y"] = 100
If Array.ContainsValue(param, 100) Then
TextWindow.WriteLine("Array param has value 100.") ' True
EndIf

' GetAllIndices operation

param["x"] = 200
param["y"] = 100
index = Array.GetAllIndices(param)
TextWindow.WriteLine(index) ' 1=x;2=y;

' GetItemCount operation

param = "x=200;y=100;width=300;height=150;"
num = Array.GetItemCount(param)
TextWindow.WriteLine("Array param has " + num + " items.") ' 4

' IsArray operation

param = "x=200;y=100;width=300;height=150;"
If Array.IsArray(param) Then
TextWindow.WriteLine("Array param is an array.") ' True
EndIf

' Index is not case sensitive

star["Σ"]["mag"] = 2.0
star["σ"]["mag"] = 5.7
TextWindow.WriteLine(star["Σ"]["mag"]) ' 5.7