Difference between Dim and Redim Statement In VBScript,UFT,QTP

2
49
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Difference between Dim and Redim Statement In VBScript,UFT,QTP
Difference between Dim and Redim Statement In VBScript,UFT,QTP

Distinction among 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 co ordinates. 
Peruse Array class and idea in Java here

Array has two important concepts

  • Upperbound – it Signify 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 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. 
 

Dynamic Array:

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 create 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

like-Redim customer(100)

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

Preserve keyword catchphrase guarantees that the information which are beforehand present in the cluster is all things considered while changing the measurement utilizing ReDim watchword.

Concept-I

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.

Concept-II:

While working with Preserve keyword,we can just resize the last measurement or the last memory block.If an endeavor is made to resize some other dimension,VBScript Engine will create some blunder (throw an error I mean!!)
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here