Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

Sunday, March 10, 2013

Size of multi-dimensional array

How to find size of a multi-dimensional array. Use following code to find size of a multi-dimensional array.


'Define 3 dimensional array, with size of the first dimension as 4, with size of the second dimension as 6 and with size of the third dimension as 8

Dim myArray(4,6,8)

'size of the first dimension
MsgBox lbound(myArray,1)        'Returns 0
MsgBox ubound(myArray,1)        'Returns 4

'size of the second dimension
MsgBox lbound(myArray,2)        'Returns 0
MsgBox ubound(myArray,2)        'Returns 6

'size of the third dimension
MsgBox lbound(myArray,3)        'Returns 0
MsgBox ubound(myArray,3)        'Returns 8

Wednesday, February 22, 2012

Sorting an array using VBScript/ QTP

Following code can be used to sort an array using QTP. Let sortme is name of the array which is to be sorted. I have used "Bubble Sort" principle of sorting.





A) Descending Sort
For a = UBound(sortme) - 1 To 0 Step -1
  For j= 0 to a
If sortme(j+1) > sortme(j) Then
temp = sortme(j)
sortme(j) = sortme(j+1)
sortme(j+1) = temp
End If
Next
Next




B) Ascending Sort
For a = UBound(sortme) - 1 To 0 Step -1
  For j= 0 to a
If sortme(j+1) < sortme(j) Then
temp = sortme(j)
sortme(j) = sortme(j+1)
sortme(j+1) = temp
End If
Next
Next