[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Read Tab Delimited Text File with FileSystemObject in ASP

Posted on 2004-10-13
4
Medium Priority
?
263 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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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