Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add multiple lines to a txt file

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
Hello,

I am able to add a single line to a Text file using a DataTable. I would like to be able to add multiple lines into the Text file using the Datatable
How can I add the 2nd, 3rd more lines?

Dim S1' Variable for custom spacing 1
s1=Space((DataTable.Value("Custom_spacing1",dtLocalSheet))) ' variabke that insert spacing on loop
Set fso=createobject("Scripting.FileSystemObject")
'Create a non existing file "qtptest.txt " with overwrite option as True
Set qfile1=fso.CreateTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP Test 834\Text files\qtptest1.txt",true,False)
qfile1.Write((DataTable.Value("ISA_I01_Author_Info_Qualifier",dtGlobalSheet)))
qfile1.Write("*")
qfile1.Write(s1)
qfile.Write((DataTable.Value("Test2",dtGlobalSheet))) ' How do I create a new line for this in the txt file qtptest1.txt?
 
Use WriteLine instead of Write

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hello

Thanks that works but what if I want to have multiple txt elements on the same line?

For example

00*Smith*20130801
02*CMT*43438743

What is the correct syntax to do this?

 
1) split the line by "*" and writeline for each
Code:
strLine = "00*Smith*20130801"
arrElements = split((strLine, "*")
for i = 0 to ubound(arrElements) - 1
   qfile1.writeline arrElements(i)
next

or

2) replace the "*" with vbCrLf (Carriage Return / Line Feed)
Code:
strLine = "00*Smith*201308041"
qfile1.writeline replace(strLine, "*", vbCrLf)

Method 1 will allow you to easily refer to the elements later by arrElement. Method 2 will not.

-Geates

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top