We can use VB script to create a text file and write some lines in the text file using the File System Object.
Write Method
Write Method writes a line and the cursor is placed at the end of the line and the next line will be continued from the end of the first line. Write Method writes a specified string to a Text Stream file.
The Syntax of the Write Method is
object.Write(string)
Example: To write a script to print 10 lines.
'Create a text file and write some lines into it
'Step 1: Create and object variable to interact with the File system object
set fso=CreateObject("Scripting.filesystemobject")
'Step 2: Create the test file.
set fil = fso.CreateTextFile("F:\Test1.txt")
'Step 3: Writing the lines into the file using For Loop
For i = 1 to 10
fil.Write ("This is line "&i)
Next
When the script is executed it displays the 10 lines like this.
This is line 1This is line 2This is line 3This is line 4This is line 5This is line 6This is line 7This is line 8This is line 9This is line 10
WriteLine Method
WriteLine method write statements in different lines. The cursor is placed at the next Line or New Line. Writes a specified string and newline character to a TextStream file.
The syntax of the WriteLine method is
object.WriteLine([string])
Example: To write a script to print 10 lines in different rows.
'Create a text file and write some lines into it
'Step 1: Create and object variable to interact with the File system object
set fso=CreateObject("Scripting.filesystemobject")
'Step 2: Create the test file.
set fil = fso.CreateTextFile("F:\Test1.txt")
'Step 3: Writing the lines into the file using For Loop
For i = 1 to 10
fil.WriteLine ("This is line "&i)
Next
When this script is executed the output is displayed like this
2 comments:
Hi Kiran ,
Is there any opening in your organization ?
If yes please let me know . i have 3+ yrs of exp in manual testing ,working as QA . My email id is kanchi9kant@rediffmail.com.
Regards,
Kanchan
Hi Kanchan
will let you know if there are any openings.
Kiran Paul
Post a Comment