Scalar variables and array variables, Visual Basic Programming

Mostly time, you just desire to assign a single value to a variable you have declared. A variable having a single value is a scalar variable. At other times, this is convenient to assign more than one associated value to a single variable. Then you can create a variable which can have a series of values. It is called an array variable. Array variables & scalar variables are declared in the same way, apart from that the declaration of an array variable employee parentheses ( ) following the variable name. In the following instance, a single-dimension array having 11 elements is declared:

Dim A(10)

Although the number illustrated in the parentheses is ten, in VBScript all arrays are counted from base 0, so that actually this array contains 11 elements. In such an array, the number of array elements is always the number illustrated in parentheses plus one. This kind of array is known as fixed-size array.

You assign data to each of the elements of the array via an index into the array. Starting at zero and ending at 10, data will be assigned to the elements of an array given as:

A(0) = 256

A(1) = 324

A(2) = 100

. . .

A(10) = 55

Likewise, the data can be retrieved from any element via an index in the specific array element you desire. For illustration:

. . .

SomeVariable = A(8)

. . .

Arrays are not restricted to a single dimension. You can have as several as 60 dimensions, although mostly people cannot comprehend more than three or four dimensions. Multiple dimensions are declared through separating an array's size numbers in the parentheses along commas. In the following instance, the MyTable variable is two-dimensional array having 6 rows and 11 columns:

Dim MyTable(5, 10)

In a two-dimensional array, always the first number is of rows; the second number is of columns.

You can also declare an array whose size alter whereas your script is running. It is called a dynamic array. Initially the array is declared in a process either using the Dim statement or the ReDim statement. Though, for a dynamic array, no size or number of dimensions is placed inside the parentheses.

For instance: Dim MyArray()

ReDim AnotherArray()

To employ a dynamic array, you have to subsequently use ReDim to find out the number of dimensions and the size of each dimension. In the following instance, ReDim sets the initial size of the dynamic array to 25. A subsequent ReDim statement resizes array to 30, however uses the Preserve keyword to preserve the contents of the array as the resizing takes place.

ReDim MyArray(25)

. . .

ReDim Preserve MyArray(30)

There is no limitation to the number of times you can resize dynamic array, although you should know that if you make an array smaller than it was, you lose the data in the removed elements.

Posted Date: 4/18/2013 5:30:34 AM | Location : United States







Related Discussions:- Scalar variables and array variables, Assignment Help, Ask Question on Scalar variables and array variables, Get Answer, Expert's Help, Scalar variables and array variables Discussions

Write discussion on Scalar variables and array variables
Your posts are moderated
Related Questions
MULTIPLE DOCUMENT INTERFACE (MDI) WINDOWS   The SDI (Single document interface) supports one open window or document at a particular time. Microsoft's notepad and paint are il

Enabling ODBC: 1. Select the control panel, programs, setting and then ODBC32 2. Double click on the ODBC32 3. The Settings for an operating system will take place. 4

MESSAGES The Windows-based applications do not make explicit function calls to acquire input. They wait for the system to pass the input to them. The system passes input to the

USE OF SERIALIZE FUNCTION IN DOCUMENT CLASS TO IMPLEMENT FILE void CStoreDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here }

I HAVE A C# ASSIGNMENT , WILL I FIND SOMEONE PROFESSIONAL HELP HERE ?

Variant Type: If no data type is related with the VB variables, it takes the default variant type. The variable x will be of the variant type when the two declarations below a

ARCHITECTURE OF WIN 32 PROGRAM   Figure: working of Win 3 program The hardware events in the figure are the mouse associated events like the mouse move, left

I have a problem with Visual Basic: exchangeable 2 images of place I have 2 picturebox''s placed a button when I click on the button, the 2 pictures of this place change with e

what mean by programing

ODBC   The ODBC gives an API which distinguishes the data base vendors implementation via the ODBC drivers specific to a DBMS. The program will use the API to call the ODBC dr