Solved

Read Tab Delimited Text File with FileSystemObject in ASP

Posted on 2004-10-13
4
256 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 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

11 Experts available now in Live!

Get 1:1 Help Now