Showing posts with label VB Script. Show all posts
Showing posts with label VB Script. Show all posts

Monday, August 29, 2011

How do I sort arrays items using vbscript?

we will be able to sort in alphabetically an array items using the vbscript.

' declaring the array
Dim arrSortOut(10)
' assigning data to the array
arrSortOut(0)="Ammu"
arrSortOut(1)="Siva"
arrSortOut(2)="Madhu"
arrSortOut(3)="Ranga"
arrSortOut(4)="Jagadesh"
arrSortOut(5)="Kumar"
arrSortOut(6)="Praveen"
arrSortOut(7)="Martha"
arrSortOut(8)="Zeebra"
arrSortOut(9)="123Zeebra"
arrSortOut(10)="!123Zeebra"

for i = UBound(arrSortOut) - 1 To 0 Step -1
  for j= 0 to i
    if arrSortOut(j)>arrSortOut(j+1) then
      temp=arrSortOut(j+1)
      arrSortOut(j+1)=arrSortOut(j)
      arrSortOut(j)=temp
   end if
  next
next


for x=0 to 8 UBound(arrSortOut)
 msgbox arrSortOut(x)' to check the items
next

Thursday, August 25, 2011

How to get Sub-folders Count and Names from a Folder?

How to get Sub-folders Count and Names from a Folder? using the below code(VB Script) you will be able get all the sub-folders in a parent folder.  This code will be very much useful in the during the creation of Test Automation Frame works.


Set Obj = CreateObject("Scripting.FileSystemObject") 
'Creating a file system object
    Set Obj1 = Obj.GetFolder("C:\test")
    Set Obj2 = Obj1.SubFolders
    msgbox Obj2.Count 'displaying count of sub-folders
    For Each Fold_Iteam in Obj2
        Fold_names = Fold_names& Fold_Iteam.name &vbnewline
Next
msgbox Fold_names 'Displaying all sub-folders names

Lock your system after execution of your QTP Script

Now you can lock your system after your QTP batch script/script execution.
use the below code at the end of your script(batch/regular). your system will be automatically locked,once after script executed.
Public Function Lock_your_system()
    Set obj = CreateObject("WScript.Shell")
    sCmnd = "%windir%\SYSTEM32\rundll32.exe user32.dll,LockWorkStation"
    obj.Run sCmnd, 0, False
End Function