Xbasic

REDIM

Syntax

REDIM [ Scope ] Variable_Name as Value_Type

Arguments

Scope

Default = "LOCAL".

"SHARED" = Desktop only. Variable exists as long as a window is open. Even if you change the layout that is loaded in the window (by using the File > Open command from within the Form or Browse window), the variable continues to exist.

"GLOBAL" = Desktop only. Variable exists as long as Alpha Anywhere is running, until you close the current database.

"PRIVATE" = Desktop only. The variable is visible only inside its class.

Variable_Name

The name of the variable.

Value_Type

The variable type is indicated through the Value_Type, a single character.

  • "A" = any type
  • "B" = blob
  • "C" = character
  • "D" = date
  • "F" = function
  • "L" = logical
  • "N" = numeric
  • "P" = pointer
  • "T" = time
  • "U" = collection

Description

REDIM is used to change the size of an array.

Discussion

All existing values in the array are lost when an array is REDIMmed.

To preserve existing values in the array use the array's size() method. An alternative way to add new entries to an array, and simultaneously increase the array size, is to use the '[]' syntax. See example below. See also DIM, DELETE, TYPE ... END TYPE.

Example:

Re-dimensioning an array.

dim ary[3] as C
ary[1] = "a"
ary[2] = "b"
ary[3] = "c"
ary[4] = "d"
ERROR: array index out-of-bounds

redim ary[4] as C
ary[4] = "d"
?ary
= [1] = ""
[2] = ""
[3] = ""
[4] = "d"

'Note how the .resize() method preserves existing array entries.
ary.resize(5)
ary[5] = "e"
?ary
= [1] = ""
[2] = ""
[3] = ""
[4] = "d"
[5] = "e"

'Add a new entry to the array and increase its size
ary[] = "f"
?ary[6]
= "f"

ary[] = "g"
?ary.size()
= 7

See Also