UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software UniBasic Commands Reference - Rocket Software

rocketsoftware.com
from rocketsoftware.com More from this publisher
11.04.2013 Views

Parameters The following table describes each parameter of the syntax. Paramete r Description INMAT Function Return Values After you execute DIM, the UniBasic INMAT function returns one of the values described in the following table. Resizing Arrays You can use the DIM statement to dynamically redimension an array without losing any data if the size of the redimensioned array is large enough to contain all data in the original array. When you redimension, UniBasic places the old data elements into the new array from left to right and from top to bottom. All leftover data is placed in the 0,0 element. 1-211 UniBasic Commands Reference name1 Specifies the name of the array. rows Specifies the number of rows in the array. ,cols Specifies the number of columns in the array. If cols is omitted, the array is one-dimensional. DIM Parameters Value Description 0 The dimensioned array was not created. UniData returns an error message, but program execution continues. 1 Memory was insufficient to create the dimensioned array. UniData returns an error message, but program execution continues. n The dimensioned array was created. n is the number of elements in the array. INMAT Function Return Values

Although you can change the size of an array during program execution, its configuration cannot change. For example, a two-dimensional array cannot be changed to one-dimensional and vice versa. Examples In the following example, the program statement creates three arrays: one-dimensional NAME, one-dimensional TITLES, and two-dimensional DATES. DIM NAME(100),TITLES(100),DATES(100,2) In the next example, two DIMENSION statements are included in the same program, although because the new array is smaller than the original, all excess data is placed in element 0,0. After the execution of the second DIMENSION statement, the array has the dimension of 100 by 10. DIM WAGES(50,100) DIM WAGES(100,10) The following program segment creates the array TEST by setting variable A to 30, and then declaring TEST as a one-dimensional array of 30 elements: A = 30 DIM TEST (A) The following sample code is invalid because array size is declared with nonnumeric variables “(” and “)” and because you cannot use a variable in a dimension statement: TEST = "(10,5)" DIM TEST In contrast, the following statement is valid: DIM TEST (10,5) Related Commands UniBasic INMAT, MAT, MATBUILD, MATPARSE, MATREAD, MATREADL, MATREADU, MATWRITE, MATWRITEU DIM 1-212

Although you can change the size of an array during program execution, its configuration<br />

cannot change. For example, a two-dimensional array cannot be changed to<br />

one-dimensional and vice versa.<br />

Examples<br />

In the following example, the program statement creates three arrays: one-dimensional<br />

NAME, one-dimensional TITLES, and two-dimensional DATES.<br />

DIM NAME(100),TITLES(100),DATES(100,2)<br />

In the next example, two DIMENSION statements are included in the same program,<br />

although because the new array is smaller than the original, all excess data is placed<br />

in element 0,0. After the execution of the second DIMENSION statement, the array<br />

has the dimension of 100 by 10.<br />

DIM WAGES(50,100)<br />

DIM WAGES(100,10)<br />

The following program segment creates the array TEST by setting variable A to 30,<br />

and then declaring TEST as a one-dimensional array of 30 elements:<br />

A = 30<br />

DIM TEST (A)<br />

The following sample code is invalid because array size is declared with nonnumeric<br />

variables “(” and “)” and because you cannot use a variable in a dimension statement:<br />

TEST = "(10,5)"<br />

DIM TEST<br />

In contrast, the following statement is valid:<br />

DIM TEST (10,5)<br />

Related <strong>Commands</strong><br />

<strong>UniBasic</strong><br />

INMAT, MAT, MATBUILD, MATPARSE, MATREAD, MATREADL,<br />

MATREADU, MATWRITE, MATWRITEU<br />

DIM 1-212

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!