Thursday 20 September 2012

1+(1+2)*2+(1+2+3)*3+(1+2+3+4)*4 if n=1 then o/p is 1 if n=2 then o/p is 1+(1+2)*2 if n=3 then o/p is 1+(1+2)*2+(1+2+3)*3

n=cint(inputbox("Enter the value"))

For i=1 to n
For j=1 to i

    c=c+j

    If j=i Then
        e=e+(c*j)
    End If

    Next
    c=empty
Next
print e

Sunday 8 July 2012

Export data to xlsx from Action1 datatable

  Set qSheet=DataTable.GetSheet("Action1")
fn=qSheet.getparametercount

Set ExcelApp=CreateObject("Excel.Application") 
ExcelApp.visible=true
     Set ExcelFile=ExcelApp.WorkBooks.Open ("E:\new.xls") 
     Set ExcelSheet = ExcelApp.WorkSheets("Sheet1") 
 
  rowcount= qSheet.getrowcount

For index1=1 to fn
fname=qSheet.getparameter(index1).name
ExcelSheet.cells(1,index1)=fname

next

For i=2 to  rowCount+1
For j=1 to fn
    fg=qSheet.getparameter(j).valuebyrow(i-1) 
ExcelSheet.cells(i,j)=fg
    next
Next

ExcelFile.save
ExcelFile.close
ExcelApp.quit


Saturday 19 May 2012

Get Data in odd Sheets From Excel

Set exc=createobject("excel.application")
Set bk=exc.workbooks.open("E:\new.xls")
Set sheets=bk.worksheets
d=sheets.count
For k=1 to d
If (k mod 2)<>0 Then
Set shts=bk.worksheets(k)

rc=shts.usedrange.rows.count
cc=shts.usedrange.columns.count
For i=1 to rc
    For j=1 to cc
rs=shts.usedrange.cells(i,j)
print rs

Next
next

End If
Next

bk.close
exc.quit

Thursday 12 April 2012

To Find Whether the Required Sheet is Present or Not in excel


Set exc=createobject("excel.application")
Set bk=exc.workbooks.open("E:\sac2.xls")
For each  m in bk.worksheets
If m.name="shtupdate" then
x=1
Exit for
end if
Next
If x=1 Then
msgbox"Sheet is present"
else
MsgBox"Sheet not found"
End If




Wednesday 11 April 2012

To Find Object BG Color


d=Browser("Google").Page("Google").Object.bgColor
print d

Compare Cells in single excelsheet


Set obj=createobject("excel.application")
obj.visible=true
Set obj1=obj.workbooks.open("E:\sac2.xls")
Set range1=obj1.worksheets(1).range("A1:B7")
Set range2=obj1.worksheets(1).range("C1:D7")

r1=range1.rows.count
c1=range1.columns.count
For i=1 to r1
For j=1 to c1
If range1.cells(i,j).value<>range2.cells(i,j).value Then
range1.cells(i,j).interior.colorindex=6
End If
Next

Next
obj1.save
obj1.close
obj.application.quit

OutPut :Here i compared cells between the range A1:B7 and C1:D7

Tuesday 10 April 2012

To find Armstrong Number


n=InputBox("enter the value")
For x=1 to n
For i=1 to len(x)
c=mid(x,i,1)
s=s+c^3
Next
If s=x Then
print "Armstrong Numbers are:  "&s
End If

s=empty
Next

Fibonacci series


n=InputBox("enter the value")
a=0
b=1
For i=1 to n-1
If a=0 Then
print a

End If
    c=a+b
a=b
print a
b=c
Next









Check whether the number is prime or not


n=InputBox("enter the number")
flag=0
For i=2 to (n-1)
If (n mod i)=0 Then
flag=flag+1
Exit for
End If
Next
If flag=1 Then
print " not prime"
else
print "prime"
End If

Import table from Access Database to Excel


Const acExport = 1
Const acSpreadsheetTypeExcel9 = 8

Set objAccess = CreateObject("Access.Application")
objAccess.OpenCurrentDatabase "C:\Scripts\Test.mdb"

objAccess.DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, _
"Employees", "C:\Scripts\Employees.xls", True

'Note:create test.mdb in C:\Scripts\Test.mdb with one table(create one table) inside named as Employees and
'create newspreadsheet in C:\Scripts\Employees.xls
''run the script and finally you will see the employee table created in access  in excelsheet

Getting all values from Global sheet or local sheets


Set dg=datatable.GlobalSheet
rc=datatable.GetRowCount
cc=datatable.GlobalSheet.getparametercount
For i=1 to cc
cname=dg.getparameter(i).name
set d=dg.getparameter(cname)
For j=1 to rc
val=d.valuebyrow(j)
MsgBox(val)
            next
Next

(OR)

sc=datatable.GetSheetCount
For i=1 to sc
rc=datatable.GetRowCount
cc=datatable.getsheet(sc).getparametercount
For j=1 to rc
   For k=1 to cc
f= datatable.getsheet(i).getparameter(k).name
Set h=datatable.getsheet(i).getparameter(f)
l=h.valuebyrow(j)
print l
Next
Next
Next

Sunday 8 April 2012

Search word in text file using Regular Expression


Set objregex=createobject("vbscript.regexp")
objregex.pattern="dhsi"
Set fso=createobject("scripting.filesystemobject")
Set ob=fso.opentextfile("E:\test.txt",1)
Do until ob.atendofstream
strsearch=ob.readline
set c=objregex.execute(strsearch)
If c.count>0 Then
For each m in c
msgbox(strsearch)
Next


End If
Loop
ob.close

Compare 2 text file


file1=InputBox("enter the path","","E:\test.txt")
file2=InputBox("enter the path","","E:\textcheck.txt")

Function comparefiles(file1,file2)
Set fso=createobject("scripting.filesystemobject")
if (fso.getfile(file1).size)<>(fso.getfile(file2).size) then
comparefiles=true
Exit function
end if
Set d=fso.getfile(file1).openastextstream(1,0)
Set s=fso.getfile(file2).openastextstream(1,0)
comparefiles=false
Do while d.atendofstream=false

file1content=d.readline
file2content=s.readline
comparefiles=strcomp(file1content,file2content,1)
If (comparefiles<>0) Then
comparefiles=true
Exit do
End If

Loop
d.close
s.close
End Function

If comparefiles(file1,file2)=false Then
MsgBox("identical")
else
msgbox("not identical")
End If

To Get number of link and their names,URL in a page



set desc=description.create
desc("micclass").value="Link"
set getalllink=browser("name:=Google").page("title:=Google").childobjects(desc)
linkcnt=getalllink.count
print "no of link is "&linkcnt
for i=0 to getalllink.count-1
link_name=getalllink(i).getroproperty("name")
link_url=getalllink(i).getroproperty("url")

msgbox "Link Name is "&link_name &"  it's URL"& " "&link_url
next

Saturday 7 April 2012

To view the properties and value of Object in Design time


set d=Window("Flight Reservation").WinButton("FLIGHT").GetTOProperties
a=d.count
For i=0 to a-1
j=d(i).name&" "&d(i).value
print j
Next

Change Excel Sheet Name


Set exc=createobject("excel.application")
Set bk=exc.workbooks.open("E:\sac2.xls")
Set sht=bk.worksheets(1)
sht.name="shtupdate"
bk.save
exc.quit

Without Using Split Function


x="hi  wel come"
For i=1 to len(x)
c=mid(x,i,1)
If c<>empty Then
b=b&c
End If
If c=" " Then
print b
b=""
End If
Next
print b

Friday 6 April 2012

Print duplicates


x=array(1,1,2,3,3,5,7,9)
For i=0 to UBound(x)
If instr(b,x(i))=0 Then
b=b&x(i)
elseif instr(b,x(i))>0 then
print x(i)
End If
Next

To print the decimal numbers


Dim a,b
a=123.343
b=a-int(a)
print b

Result= 0.343

To get data from particular sheet


Set obj=createobject("excel.application")
Set bk=obj.workbooks.open("E:\sac1.xls")
Set sh1=bk.worksheets(1)
rc=sh1.usedrange.rows.count
cc=sh1.usedrange.columns.count
For i=1 to rc
For j=1 to cc
rs=sh1.usedrange.cells(i,j)
print rs
Next

Next

Wednesday 4 April 2012

Create text file if not present


Set fso=createobject("scripting.filesystemobject")
Set obj=fso.opentextfile("E:\textcheck.txt",2,true)
obj.writeline "hi welcome"
obj.close

Tuesday 3 April 2012

Delete your Trash,spam mails in gmail Webtable


Set desc=description.Create
desc("type").value="checkbox"

set x=browser("name:=Gmail.*").page("title:=Gmail.*").webtable("name:=t").ChildObjects(desc)
c=x.count
print "No of Mails in Gmail  deleted are "&c
For i=0  to c-1
x(i).Set "ON"
Next
browser("name:=Gmail.*").page("title:=Gmail.*").WebButton("name:=Delete Forever","Index:=0").Click

Getting current Browser URL


x=browser("title:=.*").page("title:=.*").GetROProperty("url")
print x

How does QTP Descriptive Programming work?
First of all, I've created new Description object: 
Set Desc = Description.Create()
Description object contains collection of properties, which identify any UI object such as a browser, a page, a dialog, a list, a button etc.

To specify that we want identify all Edits on browser's page I use 
"micclass"property:
Desc("micclass").Value "WebEdit"
Note: the "mic" prefix in "micclass" stands for "Mercury Interactive Constant".

How do you know the class name ("micclass") of object?

Use Spy for that:
QTP Object Spy
Open QTP object Spy and check recorded properties of object.
For example, these are properties of Edit:
QTP Object Spy - recorded properties
As you can see, there is "Class Name" property and its value - "WebEdit"So,"WebEdit" is a value of Class Name of all Edits located on Web page.
Note: 
"Class Name" is a synonym of "micclass". 

I gathered Class Names of Web objects in this table:

#Type of Web objectClass Name(micclass)
1Web BrowserBrowser
2PagePage
3Edit boxWebEdit
4ImageImage
5LinkLink
6Web ElementWebElement
7ButtonWebButton
8CheckboxWebCheckBox
9Combobox (DropDownList)WebList
10TableWebTable


Since we created Description object for all edit boxes, we can use this description to get all specified objects ( = edit boxes).
The next step 
returns the collection of all child objects (i.e. edit boxes) contained within the page:
Set Links = Browser("Google Sets").Page("Google Sets").ChildObjects(Desc)

To get the number of found objects in a returned collection, we use Countproperty:

MsgBox "Number of Edits: " & Links.Count

And the result is 5 found Edits on Google Sets  page:
Number of Edits

How to Update Particular Line in a textfile


txtFilePath= "C:\copy.txt"
txtRowNumber=3 '
TextToAdd="three"
 
Set fso= CreateObject( "scripting.filesystemobject")
Set f=fso.OpenTextFile( txtFilePath, 1)
txtData=f.readall
f.close
 
Set f=fso.OpenTextFile( txtFilePath, 2)
 
strTxtData=split( txtData,vbnewline)
 
For cnt=0 to ubound(strTxtData)
 
 
If cnt<>txtRowNumber- 1 Then
    f.writeline( strTxtData( cnt))
else
    f.writeline( TextToAdd )
End If
 
Next
 
f.close

Monday 2 April 2012

Find the Biggest and Smallest number


To find Biggest number
num=array("34","12","98","43","89","49","56")
For i=1 to ubound(num)
 If (num(i)>num(0)) Then
    num(0)=num(i)
 End If
Next
print num(0)

To find smallest number


num=array("34","12","98","43","89","49","56")
For i=1 to UBound(num)
 If (num(i)<num(0)) Then
    num(0)=num(i)
 End If
Next

print num(0)

Generate Random number


x=randomnumber(1,100)
print x

Create and type words in doc

set objword=createobject("word.application")
objword.document.add
objword.selection.typetext "hi hello"
objword.activedocument.saveas"C:\Test.doc"

GetRowCount for specific column in DataTable



For i=1 to datatable.GetRowCount
a=datatable.Value("C")
datatable.SetNextRow
If a<>vbnullstring Then
cnt=cnt+1
End If
Next
print cnt

Sunday 1 April 2012

Excel Operation and its use


Compare by cells

Set objexcel=createobject("excel.application")
objexcel.visible=true
Set sac1=objexcel.workbooks.open("E:\sac1")
Set sac2=objexcel.workbooks.open("E:\sac2")
Set sh1=sac1.worksheets(1)
Set sh2=sac2.worksheets(1)
For each cell in sh1.usedrange
If cell.value<>sh2.range(cell.address).value Then
            cell.interior.colorindex=6
            else
            cell.interior.colorindex=0
End If
Next

Search Particular value

Set objexcel=createobject("excel.application")
Set obj=objexcel.workbooks.open("E:\sac1.xls")
With obj.worksheets(1).usedrange
Set c=.find("12")
For each c in obj.worksheets(1).usedrange
If c="12" Then
c.interior.colorindex=40
else
Set c=.findnext(c)

End If

Next

End with

Sorting By Column

Const xlDescending = 1
Const xlYes = 1
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Open("E:\sac1.xls")
Set objWorksheet = objWorkbook.Worksheets(1)
Set objRange = objWorksheet.UsedRange
Set objRange2 = objExcel.Range("A1")
objRange.Sort objRange2,xlDescending
set objExcel=nothing

FILESYSTEMOBJECT

Enable and Disable Overwriting

'Create a filesystemObject
Set fso=createobject("Scripting.FileSystemObject")
'Create a non existing file "qtptest.txt "  with overwrite option as True
Set qfile1=fso.CreateTextFile("C:\qtptest.txt",True,False) 
'Output --> New File "qtptest.txt " is created
'Close the files
qfile1.Close
'Release the allocated objects
Set qfile1=nothing 
Example:   
'Create a filesystemObject
Set fso=createobject("Scripting.FileSystemObject")
'Create a   file "qtptest.txt "  in C Drive . 
'Then  run the below statement with overwrite option as False
 'Output --> Error message "File already exists" is displayed
Set qfile2=fso.CreateTextFile("C:\qtptest.txt",False,False)
Set fso=nothing

Method: CopyFile
Description: Copies one or more files from one location to a new location

Syntax: fso.CopyFile (source, destination[, overwrite])

Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
source:
(Required) A character string file specification, which can include wildcard characters, for one or more files to be copied.
destination:
(Required) Character string destination where the file or files from source are to be copied.Wildcard characters are not allowed in the destination string.
overwrite:
(Optional) Boolean value that indicates if existing files are to be overwritten. If True, files are overwritten; if False, they are not. The default is True. Note that CopyFile will fail if destination has the read-only attribute set, regardless of the value of overwrite.

Example: 
Set fso=createobject("Scripting.FileSystemObject")
'File to be copied Sourcefile="C:\copy.txt"'Dest folder where the file has to be copied
Destination="D:\final1\"
'If the destination doesnot exist then create the destination folder
If fso.FolderExists(Destination) = false Then   
fso.CreateFolder (Destination)
End If  
'Copy the file 
fso.CopyFile Sourcefile,Destination,True
Set fso=nothing

Method: DeleteFile

Description: Deletes a specified file

Syntax: fso.DeleteFile (filename[, force])

Arguments:
fso: 
(Required) The name of a FileSystemObject object previously instantiated
filename:
(Required) The name of the file to delete. The filename can contain wildcard characters in the last path component.
force:
(Optional) Boolean value that is True of files with the read-only attribute set are to be deleted;False if they are not. False is the default.

Example:   
Set fso=createobject("Scripting.FileSystemObject")
'File to be  deleted.  Sourcefile="C:\copy.txt"  'Delete the file
fso.DeleteFile Sourcefile
Set fso=nothing
 

Method: CreateFolder

Description: Creates a new folder in the specified location

Syntax: fso.CreateFolder(foldername)

Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
foldername:
(Required) A character string expression that identifies the folder to create.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Folder to be created Foldername="D:\Folder_create"  
'If the folder doenot exst then create the folder
If fso.FolderExists(Foldername) = false Then
 fso.CreateFolder (Foldername)
End If
Set fso=nothing

Method: CopyFolder

Description: Copies a folder to a new location

Syntax: fso.CopyFolder (source, destination[, overwrite])

Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
source:
(Required) A character string folder specification, which can include wildcard characters, for one or more folders to be copied. Wildcard characters can only be used in the last path component of the source argument.
destination:
(Required) Character string destination where the folder and subfolders from source are to be copied. Wildcard characters are not allowed in the destination string.
overwrite:
(Optional) Boolean value that indicates if existing folders are to be overwritten. If True, files are overwritten; if False, they are not. The default is True.

Example:   
Set fso=createobject("Scripting.FileSystemObject")
'Folder to be created SourcePath="D:\Folder_create" DestinationPath="D:\Destination\"  
'If the folder doesnot exst then create the folder
If fso.FolderExists(DestinationPath) = false Then
 fso.CreateFolder (DestinationPath)
End If
fso.CopyFolder  SourcePath,DestinationPath,True
Set fso=nothing

Method: MoveFolder

Description: Moves one or more folders from one location to another.

Syntax: fso.MoveFolder (source, destination)

Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
source:
(Required) The path to the folder or folders to be moved. The source argument string can contain wildcard charactersin the last path component only.
destination:
(Required) The path where the folder or folders are to be moved. The destination argument can't contain wildcard characters.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Folder to be created SourcePath="D:\Folder_move" DestinationPath="D:\Destination\" 
'If the folder doesnot exst then create the folder
If fso.FolderExists(DestinationPath) = false Then
 fso.CreateFolder (DestinationPath)
End If
fso.MoveFolder  SourcePath,DestinationPath
Set fso=nothing
 

Method: DeleteFolder

Description: Deletes the specified folder and its contents

Syntax: fso.DeleteFolder (folderspec[, force])

Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated
folderspec:
(Required) The name of the folder to delete. The folderspec can contain wildcard characters in the last path component.
force:
(Optional) Boolean value that is True of folders with the read-only attribute set are to be deleted;False if they are not. False is the default.

Example:  
Set fso=createobject("Scripting.FileSystemObject")
'Folder to be  deleted.  FolderDel="D:\final1"  'Delete the folder
fso.DeleteFolder(FolderDel)
Set fso=nothing

Method: DriveExists

Description: Determines whether or not a specified drive exists

Syntax: fso.DriveExists (drivespec)

Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
drivespec:
(Required) A drive letter or a complete path specification.

Example:  
Set fso=createobject("Scripting.FileSystemObject")
'The drive to check the existence
drivepath="D:\" 
 If fso.DriveExists(drivepath) then 
 msgbox  "Drive Exists"  Else    Msgbox "Drive doesnot Exist"
End If
Set fso=nothing

Method: FileExists

Description: Determines whether or not a specified file exists

Syntax: fso.FileExists (filespec)

Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
filespec:
(Required) The name of the file whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the file isn't expected to exist in the current folder.

Example:  
Set fso=createobject("Scripting.FileSystemObject")
'The file to check the existence
filepath="D:\qtptest.txt"
If fso.FileExists(filepath) then
 msgbox  "File Exists"
Else
 Msgbox "File doesnot Exist"
End If
Set fso=nothing

Method: FolderExists

Description: Determines whether or not a specified folder exists

Syntax: fso.FolderExists (folderspec)

Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
folderspec:
(Required) The name of the folder whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the folder isn't expected to exist in the current folder.

Example:   
Set fso=createobject("Scripting.FileSystemObject")
'The Folder to check the existence
folderpath="D:\qtp"
If fso.FolderExists(folderpath)  then
 msgbox  "Folder Exists"
Else
 Msgbox "Folder doesnot Exist"
End If
Set fso=nothing
 

Method: GetDrive

Description: Returns a Drive object corresponding to the drive for a specified path

Syntax: objDrv = fso.GetDrive(drivespec)
Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
drivespec:
(Required) The drivespec argument can be a drive letter (c), a drive letter with a colon appended (c:), a drive letter with a colon and path separator appended (c:\), or any network share specification (file://computer2/share1

Set fso=createobject("Scripting.FileSystemObject")
'Drive for  getting details  Sourcefile="C:\"  Set get_drv=fso.GetDrive(Sourcefile) 
 'Some of the following details can be retrieved from a drive
msgbox  get_drv.AvailableSpace
Msgbox  get_drv.DriveLetter
msgbox  get_drv.DriveType
msgbox  get_drv.FileSystem
msgbox  get_drv.FreeSpace
msgbox  get_drv.Path
Msgbox  get_drv.RootFolder
Msgbox  get_drv.SerialNumber
Msgbox  get_drv.TotalSize
Set fso=nothing
 

Method: GetFolder

Description: Returns a Folder object corresponding to the folder in a specified path

Syntax: objFolder = fso.GetFolder(folderSpec)

Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
folderSpec:
(Required) The folderspec is the path (absolute or relative) to a specific folder.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Folder  for  getting details  
Sourcefolder="D:\QTP"  
Set get_folder=fso.GetFolder(Sourcefolder) 
'get the subfolders count in a folder
Set  get_subfolder=get_folder.SubFolders
For  each  sfile  in get_subfolder
'Get the name of each folder
 Msgbox  sfile.name
Next
Set fso=nothing
 

Method: GetFile

Description: Returns a File object corresponding to the file in the specified path. The file object methods and properties can be accessed. See File Object for the file object’s methods and properties.

Syntax: objFile = fso.GetFile(fileSpec)
Arguments:
fso:
(Required) The name of a FileSystemObject object previously instantiated.
fileSpec:
(Required) The filespec is the path (absolute or relative) to a specific file.


Example:    
Set fso=createobject("Scripting.FileSystemObject")
'File for  getting details  Sourcefile="D:\qtptest.txt"
 Set get_file=fso.GetFile(Sourcefile) 
'Some of  the following details can be retrieved from a file
msgbox  get_file.DateCreated
msgbox  get_file.DateLastAccessed
msgbox  get_file.DateLastModified
msgbox  get_file.ParentFolder
msgbox  get_file.Path
Set fso=nothing      
 

Text Stream Object Methods:

Method: Close

Description: Closes an open TextStream file

Syntax: objTso.Close

Arguments:
objTso:
(Required) The name of a TextStream Object previously instantiated.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Open the file "qtptest.txt" in writing mode. 
Set qfile=fso.OpenTextFile("C:\qtptest.txt",2,True) 
'write contents to the file into a single line
qfile.Write  "Welcome to the World of QTP"
qfile.Write "the file name is qtptest.txt"
'Open the file "qtptest.txt" in reading mode. 
Set qfile=fso.OpenTextFile("C:\qtptest.txt",1,True) 
'Read  the entire contents of  priously written file
Do while qfile.AtEndOfStream <> true
 'Output --> The file will contain the above written content  in  single line. 
Msgbox  qfile.ReadLine 
Loop
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing

Method: Read

Description: Reads a specified number of characters from a TextStream file and returns the resulting string.

Syntax: strChars = objTso.Read(numCharacters)

Arguments:
objTso:
(Required) The name of a TextStream Object previously instantiated.
numCharacters:
(Required) The number of characters you want to read from the file

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Open the file "qtptest.txt" in writing mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",2,True)
'write contents to the file into two newlines
qfile.Writeline  "Welcome to the World of QTP"
qfile.Writeline  "the file name is qtptest.txt"
'Open the file "qtptest.txt" in reading mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",1,True)
'Read  characters from the file
Msgbox  qfile.Read(10)                 'Output --> "Welcome to"  will be read
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing

Method: ReadAll

Description: Reads the entire TextStream file and returns the resulting string.

Syntax: strChars = objTso.ReadAll

Arguments:
objTso:
(Required) The name of a TextStream Object previously instantiated.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Open the file "qtptest.txt" in writing mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",2,True)
'write contents to the file into two newlines
qfile.Writeline  "Welcome to the World of QTP"
qfile.Writeline  "the file name is qtptest.txt"
'Open the file "qtptest.txt" in reading mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",1,True)
'Read  the entire contents of  priously written file
Msgbox  qfile.ReadAll  'Output --> Displays the entire file.
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing

Method: ReadLine

Description: Reads an entire line (up to, but not including, the newline character) from a TextStream file and returns the resulting string.

Syntax: strChars = objTso.ReadLine

Arguments:
objTso:
(Required) The name of a TextStream Object previously instantiated.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Open the file "qtptest.txt" in writing mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",2,True)
'write contents to the file into two newlines
qfile.Writeline  "Welcome to the World of QTP"
qfile.Writeline  "the file name is qtptest.txt"
'Open the file "qtptest.txt" in reading mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",1,True)
'Read  the entire contents of  priously written file
Do while qfile.AtEndOfStream <> true
Msgbox  qfile.ReadLine  'Output --> The file will be read line line by line. 
Loop
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing
 

Method: Write:

Description: Writes a specified string to a TextStream file.

Syntax: objTso.Write(string)

Arguments:
objTso:
(Required) The name of a TextStream Object previously instantiated.
string:
(Required) The text you want to write to the file.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Open the file "qtptest.txt" in writing mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",2,True)
'write contents to the file into a single line
qfile.Write  "Welcome to the World of QTP"
qfile.Write "the file name is qtptest.txt"
'Open the file "qtptest.txt" in reading mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",1,True)
'Read  the entire contents of  priously written file
Do while qfile.AtEndOfStream <> true
 'Output --> The file will contain the above written content  in  single line. 
Msgbox  qfile.ReadLine
Loop
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing

Method: WriteLine

Description: Writes a specified string and newline character to a TextStream file.

Syntax: objTso.WriteLine([string])

Arguments:
objTso:
(Required) The name of a TextStream Object previously instantiated.
string:
(Optional) The text you want to write to the file.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Open the file "qtptest.txt" in writing mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",2,True)
'write contents to the file into two newlines
qfile.Writeline  "Welcome to the World of QTP"
qfile.Writeline  "the file name is qtptest.txt"
'Open the file "qtptest.txt" in reading mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",1,True)
'Read  the entire contents of  priously written file
Do while qfile.AtEndOfStream <> true
 'Output --> The file will contain the above written content  line by line.
Msgbox  qfile.ReadLine 
Loop
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing

Method: WriteBlankLines

Description: Writes a specified number of newline characters to a TextStream file.

Syntax: objTso.WriteBlankLines(numLines)

Arguments:
objTso:
(Required) The name of a TextStream Object previously instantiated.
numLines:
(Required) The number of newline characters you want to write to the file.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Open the file "qtptest.txt" in writing mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",2,True)
'write contents to the file into two newlines
qfile.Writeline  "Welcome to the World of QTP"
'will insert 4 new  blank lines
qfile.WriteBlankLines(4)
qfile.Writeline  "the file name is qtptest.txt"
'Open the file "qtptest.txt" in reading mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",1,True)
'Read  the entire contents of  priously written file
Do while qfile.AtEndOfStream <> true
 'Output --> The file will be read file line by line. 
Msgbox  qfile.ReadLine
Loop
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing

Property: AtEndOfLine

Description: Indicates whether the file pointer is positioned immediately before the end-of-line marker in a TextStream file.

Syntax: objTso.AtEndOfLine

Arguments:
objTso:
(Required) The name of a TextStream Object previously instantiated.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Open the file "qtptest.txt" in writing mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",2,True)
'write contents to the file into newline
qfile.Writeline  "Welcome to the World of QTP"
'Open the file "qtptest.txt" in reading mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",1,True)
Do while qfile.AtEndOfLine <> true
Msgbox  qfile.Read(1)  'Output --> The file will be read word by word. 
Loop
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing

Property: AtEndOfStream

Description: Indicates whether the file pointer is positioned at the end of a TextStream file.

Syntax: objTso.AtEndOfStream

Arguments:
objTso:
(Required) The name of a TextStream Object previously instantiated.

Example:    
Set fso=createobject("Scripting.FileSystemObject")
'Open the file "qtptest.txt" in writing mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",2,True)
'write contents to the file into two newlines
qfile.Writeline  "Welcome to the World of QTP"
qfile.Writeline  "the file name is qtptest.txt"
'Open the file "qtptest.txt" in reading mode.
Set qfile=fso.OpenTextFile("C:\qtptest.txt",1,True)
'Read  the entire contents of  previously written file
Do while qfile.AtEndOfStream <> true
Msgbox  qfile.ReadLine  'Output --> The file will be read line line by line. 
Loop
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing