Difference between Concept of Array in C and VBScript

Hi Guys,
I am writting this post through cell phone.So please forgive me if spell anything wrongly. Today i got an idea of changing the concept of array in two different languages.

I was trying to execute a piece of code in QTP like..
dim a(10)
for i=0 to Ubound(a) ' a being an array
msgbox a(i)

I was seeing the loop is actually running from 0 to 10.That mean it is running for 11 times.

Check it out guys..
But those who are from C programming background may find it faulty..isn't it?????

Even if we use a simple logic to loop through it is suppose to run 10 times!!!!!!!!!!!

well i got an idea..

For C
The declaration int values[10]; would reserve enough space for an array called values that could hold up to 10 integers. Refer to the below given picture to conceptualize the reserved storage space.
so this will loop through 0 to 9 that is 10 times....

But For VB Script
The concept is..
Dim students(6) As Integer
The array students in the preceding example contains 7 elements. The indexes of the elements range from 0 through 6. Having this array is simpler than declaring 7 different variables.
The following illustration shows the array students. For each element of the array:
The index of the element represents the grade (index 0 represents kindergarten).
The value contained in the element represents the number of students in that grade.

The array values stored in the memory.
The example is taken from Microsoft

So the bottom line is while using QTP or any other VB script Application please take care of this array concept.
Difference between Concept of Array in C and VBScript Difference between Concept of Array in C and VBScript Reviewed by Animesh Chatterjee on October 26, 2009 Rating: 5


  1. Dude,

    Len method with array will throw error. Use ubound(a)instead.


  2. Thanks Dude...This is correct...I have changed it....Thanks again for reading and correcting.


Powered by Blogger.