- 1 Share and Enjoy !
- 2 The distinction between Dim and Redim Statement In VBScript, UFT, QTP:
- 3 Share and Enjoy !
The distinction between Dim and Redim Statement In VBScript, UFT, QTP:
Array Concept in VBScript:
Concept of Plain Array in VBScript:
While the plain Variant or variable has one memory square to store one specific value, the Array has a few memory squares or compartments to store different values. Array speaks to the line and segment (rows and column)concept(not fully, just sort of).
Arrays are utilized to store some sort of Objects when we know the span of the Objects upfront. A VBScript Array can hold up to 60 dimensions(Array sections are known as dimensions). Two or three-dimensional exhibit implies it can speak to an incentive in x,y or x,y,z coordinates.
Peruse Array class and idea in Java here.
The array has two important concepts
- Upper bound – it Signifies what number of most extreme memory hinder a cluster can hold.
- LowerBounds-it Signify what number of least memory obstruct an exhibit can hold.it is frequently alluded as zero(0).LowerBounds zero alludes to a zero-based cluster.
VBScript arrays constantly zero-based so we require to tell the VBScript motor what is the UpperBounds esteem for the cluster.
Dim myArray(5) ' will dependably hold 6 component as it begins from zero.
Plain array functions admirably when we know the span of the information forthright that the array is going to hold. In case we don’t have the foggiest idea about the information estimate previously, we can make utilization of Dynamic array in VBScript.
Deceleration of Dynamic Array:
Dim myArray() ' an unfilled enclosure will make a dynamic array.we require 'to give the upper bound amid the runtime.
This is a mainstream method to maintain a strategic distance from hard coding in the content.
The second technique to creating a Dynamic Array
Dim myArray(5) ' will always hold 6 element as it starts from zero. ReDim myArray(10)' Array size increased to 11.
So the ReDim explanation is utilized to change the cluster measure inside the content, for instance…
on the off chance that we have announced an array diminish client (30)
in any case, after that we need to change the extent of the array, we can do it with the assistance of Redim explanation
Note: Redim explanation clears all components present in the exhibit variable so if our cluster contains some data, once we apply ReDim, all information will be gone.If we would prefer not to free the information we can utilize another catchphrase called-Preserve.
Preserve keyword catchphrase guarantees that the information which is beforehand present in the cluster is all things considered while changing the measurement utilizing ReDim watchword.
ReDim, for the most part, used to expanded the measurement however we can utilize ReDim to resize to littler size than the present cluster size. In that case, Preserve watchword won’t make any difference. Redim to a lower size will at any rate chop down the additional memory squares of the exhibit to abbreviate the size.
While working with the Preserve keyword, we can just resize the last measurement or the last memory block. If an endeavour is made to resize some other dimension, VBScript Engine will create some blunder (throw an error I mean!!)