Solved

Read Tab Delimited Text File with FileSystemObject in ASP

Posted on 2004-10-13
4
252 Views
Last Modified: 2008-03-04

Hi,

I am trying to Read in the data from a Tab Delimited Text File Using ASP code.

The text file looks okay when I open it with Notepad but when I try to open with Excel, I have to go through the process of Importing the data with the excel wizard then it comes through okay, otherwise if I rename the file from .txt to .csv it comes through as one big value with the data seperated by little squares.

The problem I'm facing is that im using the FileSystemObject which reads a properly setup csv file from excel correctly and perfectly, but not a tab delimited text file.

Heres my code -

<%

dim sPath,objFso
strPath = Server.MapPath("MyFile.csv")
Set objFso = createObject("Scripting.FileSystemObject")
Set objTxtStream = objFso.OpenTextFile( strPath )

Dim strSQL
Dim i, myArr, theLine

While not objTxtStream.AtEndOfStream
theLine = objTxtStream.ReadLine

myArr = split(theLine, ",")
i = 0

str1      = myArr(i)
str2       = myArr(i+1)
str3      = myArr(i+2)
str4       = myArr(i+3)
str5      = myArr(i+4)
str6       = myArr(i+5)
str7       = myArr(i+6)
str8       = myArr(i+7)
str9       = myArr(i+8)
str10       = myArr(i+9)
str11       = myArr(i+10)
str12       = myArr(i+11)
str13       = myArr(i+12)
str14       = myArr(i+13)
str15       = myArr(i+14)
str16       = myArr(i+15)
str17       = myArr(i+16)
str18       = myArr(i+17)
str19       = myArr(i+18)
str20       = myArr(i+19)
str21       = myArr(i+20)
str22       = myArr(i+21)
str23       = myArr(i+22)
str24       = myArr(i+23)
str25       = myArr(i+24)

wend
                        
%>

Is there anyway I can read in a tab delimited text file with my code?

Thanks in advance!!!

Fracture



0
Comment
Question by:Fracture
  • 2
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
boblah earned 500 total points
ID: 12302958
Hi Fracture,

what happens if you change

myArr = split(theLine, ",")

to

myArr = split(theLine, chr(9))


Cheers!
0
 

Author Comment

by:Fracture
ID: 12303077

Boblah!!!!

Thanks for your rapid reply, that worked great! I will award you the points, but just further to this - the file has headings and this is coming through as the first record.
I can get around this a few ways, like looping from the second record or seeing as i know what the headings are - just ignore them, but is there anyway of not getting this back as the first record?

Cheers again.

Fracture
0
 
LVL 6

Expert Comment

by:boblah
ID: 12303223
Fracture,

changing

Dim strSQL
Dim i, myArr, theLine

While not objTxtStream.AtEndOfStream
theLine = objTxtStream.ReadLine

to

Dim strSQL
Dim i, myArr, theLine

objTxtStream.ReadLine

While not objTxtStream.AtEndOfStream
theLine = objTxtStream.ReadLine

would do the job, but that's pretty much what you suggested anyway. That would be preferable to knowing what they are and spotting them, which would not be very robust/maintainable.
0
 

Author Comment

by:Fracture
ID: 12303245

Thanks bud, I had something similar but thats even better!

Cheers.

Fracture
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now