Scalar variables and array variables, Visual Basic Programming

Assignment Help:

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.


Related Discussions:- Scalar variables and array variables

Software that is rude - basics of gui design, Software That Is Rude: T...

Software That Is Rude: The software warns the user for making the mistakes. The Message boxes pop up representing the mistake and the user will have to click the OK or CANCEL

Multiple document interface (mdi) windows , MULTIPLE DOCUMENT INTERFACE (MD...

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

ADO.net architecture, write a detailed account on ADO.net architecture.

write a detailed account on ADO.net architecture.

Executesql - database application, Executesql: The ExecuteSQL is used ...

Executesql: The ExecuteSQL is used for executing the query on the database. The CRecordset uses the RFX mechanism to replace data between field data members of the record set

Loop statement from inside the loop, You can exit a Do...Loop using the Exi...

You can exit a Do...Loop using the Exit Do statement. Since usually you desire to exit only in certain situations, such as to ignore an endless loop, you should employ the Exit Do

Constant naming conventions, Earlier versions of VBScript had no mechanism ...

Earlier versions of VBScript had no mechanism for making user-defined constants. Constants, if utilized, were implemented as variables & distinguished from other variables by using

Help file property, Sets or returns wholly qualified path to a Help File. I...

Sets or returns wholly qualified path to a Help File. If Help file is indicated in HelpFile, it is called automatically when the user clicks Help button (or presses the F1 key) in

If then else - control statement, If Then Else: The control statement ...

If Then Else: The control statement If Then Else is used for computing a condition and taking the action based on the condition. If the condition is true then the section will

Refresh method - data control, The Refresh Method: The refresh method ...

The Refresh Method: The refresh method transfer to the first record in the record set. To invoke the refresh method follow the syntax which is as shown below: Form1.Data1.R

Create a vb application to make the text bold, Question 1 Create a VB appl...

Question 1 Create a VB application to make the text bold, italic, underlined and also color the text (using checkbox, option button, textbox controls) Question 2 Create a

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd