469,281 Members | 2,486 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

ASP Textstream question

I tried to read a text file using the Textstream object and each file
line has 4 elements. How do I put them in 4 separate table cells?
Thand you very much in advance.
Risa
Jul 19 '05 #1
3 2961
> I tried to read a text file using the Textstream object and each file
line has 4 elements. How do I put them in 4 separate table cells?


How are the elements separated? Let's say there is a pipe delimiter,
delimiter = "|" ' or comma, if tab use CHR(9) or vbTab
set fso = server.createobject("Scripting.FileSystemObject")
set fs = fso.openTextFile("c:\path\file.txt")
f = fs.readall()
fs.close: set fs = nothing: set fso = nothing

response.write "<table>"
rows = split(f, vbCrLf)
for i = 0 to ubound(rows)
response.write "<tr>"
cols = split(rows(i), "|")
for j = 0 to ubound(cols)
response.write "<td>" & cols(j) & "</td>"
next
response.write "</tr>"
next
Jul 19 '05 #2
> cols = split(rows(i), "|")

Sorry, this should say

cols = split(rows(i), delimiter)
Jul 19 '05 #3
You need to show me one of these lines from the file. I have no idea how
your elements are delimited, I assumed the pipe character, but obviously
that's not it...

--
Aaron Bertrand, SQL Server MVP
http://www.aspfaq.com/

Please reply in the newsgroups, but if you absolutely
must reply via e-mail, please take out the TRASH.
"risa wu" <an*******@devdex.com> wrote in message
news:uI**************@TK2MSFTNGP10.phx.gbl...
Hi Aaron: Thank you very much for the help. I am now able to diplay all
the line elements on one line but they all showed in one cell. How do I
separate them in different cells? Here is my code. Do you have time to
help with it?
I feel so bad at that stupid coding.
<% @language="vbscript" %>
<% option explicit %>
<html>
<title> </title>
<body>
<div align="center">
<table width="600" border="1">
<%
dim myfso,myts,intlinenum,strlinetext,i,j,f,rows,cols, delimiter
const forreading=1
delimiter="|"
set myfso=server.createobject("scripting.filesystemobj ect")
if myfso.fileexists("d:\gisnet\pplist.txt") then
set myts=myfso.opentextfile("d:\gisnet\pplist.txt",for reading)
f=myts.readall()
rows=split(f,vbcrlf)
for i=0 to ubound(rows)
response.write "<tr>"
cols=split(rows(i),delimiter)
for j=0 to ubound(cols)
response.write "<td>"& cols(j) &"</td>"
next
response.write "</tr>"
next
myts.close
else
reaponse.write "File was not found"
end if
%>

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Steve Bright | last post: by
3 posts views Thread by Stevey | last post: by
1 post views Thread by AspProgrammer | last post: by
1 post views Thread by mike.biang | last post: by
1 post views Thread by Madhu G | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.