var_CreateInstance = DotNetFactory.CreateInstance("System.Environment")
msgbox var_CreateInstance.CurrentDirectory
Dim SystemDate , oDate
Set SystemDate = Dotnetfactory.CreateInstance("System.DateTime")
Set oDate = SystemDate.Parse("Fri, 9 Oct 2009")
FormattedDate = oDate.Day & "/" & oDate.Month & "/" & oDate.Year
msgbox FormattedDate
Set SystemDate = Nothing
Set oDate = Nothing The .NET SortedList class provides a hash table with automatically sorted key/value pairs.
The following code creates a SortedList and populates it with some key/value pairs:Set objSortedList = Dotnetfactory.CreateInstance ( "System.Collections.Sortedlist" )
objSortedList.Add "First", "Hello"
objSortedList.Add "Second", ","
objSortedList.Add "Third", "world"
objSortedList.Add "Fourth", "!"
For i = 0 To objSortedList.Count - 1
WScript.Echo objSortedList.GetKey(i) & vbTab & objSortedList.GetByIndex(i)
Next
' this code creates and populates an ArrayList
Set myArrayList = CreateObject( "System.Collections.ArrayList" )
myArrayList.Add "F"
myArrayList.Add "B"
myArrayList.Add "D"
myArrayList.Add "C"
' [1] add the new element to the ArrayList
myArrayList.Add "Z"
' [2] sort the ArrayList
myArrayList.Sort
And how about deleting an element?
In an array you would need to "shift" the elements to fill the gap and then ReDim the array again.
In an ArrayList you would use either myArrayList.Remove "element_value" or myArrayList.RemoveAt "element_index".
More interview questions and answers on arrays in QTP are given below.
msgbox var_CreateInstance.CurrentDirectory
Dim SystemDate , oDate
Set SystemDate = Dotnetfactory.CreateInstance("System.DateTime")
Set oDate = SystemDate.Parse("Fri, 9 Oct 2009")
FormattedDate = oDate.Day & "/" & oDate.Month & "/" & oDate.Year
msgbox FormattedDate
Set SystemDate = Nothing
Set oDate = Nothing The .NET SortedList class provides a hash table with automatically sorted key/value pairs.
The following code creates a SortedList and populates it with some key/value pairs:Set objSortedList = Dotnetfactory.CreateInstance ( "System.Collections.Sortedlist" )
objSortedList.Add "First", "Hello"
objSortedList.Add "Second", ","
objSortedList.Add "Third", "world"
objSortedList.Add "Fourth", "!"
For i = 0 To objSortedList.Count - 1
WScript.Echo objSortedList.GetKey(i) & vbTab & objSortedList.GetByIndex(i)
Next
' this code creates and populates an ArrayList
Set myArrayList = CreateObject( "System.Collections.ArrayList" )
myArrayList.Add "F"
myArrayList.Add "B"
myArrayList.Add "D"
myArrayList.Add "C"
' [1] add the new element to the ArrayList
myArrayList.Add "Z"
' [2] sort the ArrayList
myArrayList.Sort
And how about deleting an element?
In an array you would need to "shift" the elements to fill the gap and then ReDim the array again.
In an ArrayList you would use either myArrayList.Remove "element_value" or myArrayList.RemoveAt "element_index".
More interview questions and answers on arrays in QTP are given below.
- What is the difference between dictionary and array in QTP?
- How to create dynamic 2 dimensional array in QTP?
- How to sort array of strings in qtp?
- How to create array of dictionary in qtp?
- How to define or declare array in qtp?
- How to return array from function in qtp?
- How to find the length of array in qtp?
- How to find the size of array in qtp?
- Explain the ubound function in qtp.
- Explain the split function in qtp with example.
- What is dotnetfactory object in qtp?
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs