Solved

Read Tab Delimited Text File with FileSystemObject in ASP

Posted on 2004-10-13
4
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
edit .asp files 5 47
Code Manager | Snippits 2 59
Building JSON Results Table FROM DB 9 32
SP converting date time to date and time separately 2 15
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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/…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

763 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