ASP Textstream question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • risa

    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
  • Aaron Bertrand - MVP

    #2
    Re: ASP Textstream question

    > I tried to read a text file using the Textstream object and each file[color=blue]
    > line has 4 elements. How do I put them in 4 separate table cells?[/color]

    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.createob ject("Scripting .FileSystemObje ct")
    set fs = fso.openTextFil e("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


    Comment

    • Aaron Bertrand - MVP

      #3
      Re: ASP Textstream question

      > cols = split(rows(i), "|")

      Sorry, this should say

      cols = split(rows(i), delimiter)


      Comment

      • Aaron Bertrand [MVP]

        #4
        Re: ASP Textstream question

        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
        Please contact this domain's administrator as their DNS Made Easy services have expired.


        Please reply in the newsgroups, but if you absolutely
        must reply via e-mail, please take out the TRASH.


        "risa wu" <anonymous@devd ex.com> wrote in message
        news:uI6LbiaQDH A.3088@TK2MSFTN GP10.phx.gbl...[color=blue]
        > 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="vbsc ript" %>
        > <% option explicit %>
        > <html>
        > <title> </title>
        > <body>
        > <div align="center">
        > <table width="600" border="1">
        > <%
        > dim myfso,myts,intl inenum,strlinet ext,i,j,f,rows, cols,delimiter
        > const forreading=1
        > delimiter="|"
        > set myfso=server.cr eateobject("scr ipting.filesyst emobject")
        > if myfso.fileexist s("d:\gisnet\pp list.txt") then
        > set myts=myfso.open textfile("d:\gi snet\pplist.txt ",forreadin g)
        > f=myts.readall( )
        > rows=split(f,vb crlf)
        > 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![/color]


        Comment

        Working...