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 split txt file that has "*" delimiters into separate columns in Datatable or excel

Status
Not open for further replies.

kdjonesmtb2

Technical User
Nov 19, 2012
93
US
The following code puts the entire text file that has "*" delimiters for each field/column into Column A in an Excel spreadsheet

How would I get the txt file to be broken into columns by the delimiter "*"?

const toRead = 1
row=1
'Dim i
set objFSO = CreateObject("scripting.filesystemobject")
set objFile = objFSO.OpenTextFile("\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\MNSure 820 files\M377668100_820_A400000004_20131106123300_IND.txt", toRead)

dim filename()
i=0

Do until objFile.atEndofStream
Redim Preserve filename(i)
filename(i) = objfile.readline
i=i+i+1

loop

objFile.close 'closes this file

For Each strline in filename
myarray = split(strline, "", -1, 1)
for each sline in myarray
datatable("A",dtglobalsheet)=sline
row=row+1
next
next

datatable.exportsheet "\\ikanas267\Documents\kgittensjones\My Documents\QTP 834\test3.xls",1

Sample txt file data:

Goal is to load text file into DataTable and compare column lengths for individual columns against expected lengths and data types



ISA*00* *00* *ZZ*M377668100 *ZZ*A470618100
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top