QTP code - Array Basics











Sponsored Links:


Some basic info about creating and using arrays.

















' The easiest way create an array is to simply declare it as follows
Dim strCustomers()

' Another method is to define a variable and then set it as an array afterwards
Dim strStaff
strStaff = Array("Alan","Brian","Chris")

' Yet another way is to use the split command to create and populate the arrayDim strProductArray
strProductArray = "Keyboards,Laptops,Monitors"
strProductArray = Split(strProductArray, ",")

' To itterate through the contents of an array you can use the For Each loop
Dim strItem
For Each strItem In strProductArray
    MsgBox strItem
Next

' This will also itterate through the loop
Dim intCount
For intCount = LBound(strProductArray) To UBound(strProductArray)
    Msgbox strProductArray(intCount)
Next

' This will itterate through the array backwards
For intCount = UBound(strProductArray) To LBound(strProductArray) Step -1
    Msgbox strProductArray(intCount)
Next

' To add extra data to an array use Redim Preserve
Redim Preserve strProductArray(3)
strProductArray(3) = "Mice"

' To store the contents of an array into one string, use Join
Msgbox Join(strProductArray, ",")

' To delete the contents of an array, use the Erase command
Erase strProductArray

Source: http://qtphelper.com

No comments: