Arrays
Updated: Apr 16, 2005

Dimension Statements -- Arrays of Variables and Objects
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Arrays of variables and selected objects are created with the same DIM
statement syntax adding subscript ranges immediately after the user_symbol.

  DIM A(99) As LONG  'same as DIM A(0 TO 99) As LONG

creates a 0-based array A with 100 LONG items.

  DIM A(1 TO 100) As LONG

creates a 1-based array A with 100 LONG items.

  DIM A(99,99) AS LONG

creates a 0-based two-dimensional array A with 10,000 LONG items.

For STRING data, we define the length of each array item with *n syntax
where n is item length.

  DIM A(99) As STRING*64

IF the *n notation is omitted, item length defaults to 256 bytes.

STRING arrays may store text data or binary data.  With text data,

  A(i) = MyString  'stores MyString as item i

IF MyString.Length > array item size n, MyString is truncated to length n.

For binary data like a UDT,

  DIM A(99) As MYTYPE  'where MYTYPE is a UDT or Custom object.
  DIM u As MYTYPE
  u = A(i)  'get UDT i
  A(i) = u  'put UDT i

For UDT arrays, HotBasic does not write any constructor values in the TYPE/
OBJECT definition into the array elements.  To initialize UDT arrays, DIM
an instance u, as above, and manually copy u into each array element.
Since this is sequential access to the array, a fast method is:

  A.Postion = 0  'needed only if A() has already been accessed
  FOR i = 0 to 99: A.WriteUDT(u): NEXT i

INITARRAY is *not* needed at program startup for any array.  All arrays in
HB are already initialized to zero at startup.  INITARRAY is a convenient
way to clear an array at run-time.

Array subscript range is -2147483648 to 2147483647.  Maximum array size is
about 4 gigabytes or available RAM.  One to five subscripts may be used to
access array elements.

The REDIM statement may be used to change the number of subscripts or size
of an array ("Statements > Miscellaneous").

Arrays of Objects (+): FILE, FONT, RECT and 24 FORM objects: BUTTON, CANVAS,
CHECKBOX, COMBOBOX, DATETIME, EDIT, FILELISTBOX, GAUGE, GRID, GROUPBOX,
HEADER, IMAGE, LABEL, LISTBOX, LISTVIEW, PANEL, RADIOBUTTON, RICHEDIT,
RICHEDIT2, SCROLLBAR, TABCONTROL, TRACKBAR, TREEVIEW AND UPDOWN.

Form MENU objects must be defined before any array of a FORM object.
[Note: with recent MENU upgrade, this restriction may no longer apply.]

For the FORM objects, REDIM will not destroy, recreate or create additional
objects if overall array size is changed.


+  Penthouse (Registered) version

Copyright 2003-2005 James J Keene PhD
Original Publication: Oct 9, 2003
