How do I write a program using an array?

Arrays. Ordered Lists. Tables.

How do I write a program using an array?

Postby uberdroid on Wed Jan 14, 2009 10:16 pm

This example sets up an array of strings. To do this, declare an array type where the components of the array are strings. Then declare a variable using the array type and put the strings into the array. For example:
Code: Select all
// TestArray.cls
  Ubercode 1 class TestArray 

  type TStringArray[*:*] : array[*:*] of string[200]

  public function main()
    MyStrings : TStringArray[*:*]
    call Redim(1, 4, MyStrings)
    MyStrings[1] <- "Humpty"
    MyStrings[2] <- "Dumpty"
    MyStrings[3] <- "sat on the"
    MyStrings[4] <- "wall"
    call Msgbox("Test String Array", Str(MyStrings))
  end function

  end class

The program just shown declares a one-dimensional type TStringArray. The array is one-dimensional because it is declared using *:* for its size (the two stars represent the lower and upper bound of the one-dimensional array). The array type consists of strings with a maximum length of 200 characters per string. In function main a local array variable MyStrings is declared, based on the array type. The array variable is declared as resizable because it uses *:* for its size.

The code resizes the array to fit 4 strings (with a lower bound of 1 and an upper bound of 4), then the assignment statements copy 4 strings into the array. Finally the Msgbox displays the contents of the array.
Posts: 38
Joined: Wed Jan 14, 2009 4:36 am

Return to Arrays, Collections, Lists, and Tables

Who is online

Users browsing this forum: No registered users and 1 guest