Reverse text

Discussion in 'ASP General' started by Steven Burn, Jan 7, 2004.

  1. Steven Burn

    Steven Burn Guest

    Just wondering if anyone is aware of any way to reverse the following so it
    displays the text from

    end of file > start of file

    instead of

    start of file > end of file


    <%
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Dim ThisLine
    Dim PrintLine
    Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    SomeFile = Server.MapPath("somefile.txt")
    Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
    Do While Not InputStream.AtEndOfStream
    ThisLine = InputStream.ReadLine
    PrintLine = PrintLine + ThisLine + "<br>"
    Loop
    InputStream.Close
    Set OutputStream = Nothing
    Set FileObject = Nothing
    Response.Write PrintLine
    %>

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)
     
    Steven Burn, Jan 7, 2004
    #1
    1. Advertising

  2. Steven Burn

    Guest Guest

    Do you mean that the last line goes first still preserving the prder od
    letters in it, or you want the last letter of the file to come first and so
    on?

    "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    news:...
    > Just wondering if anyone is aware of any way to reverse the following so

    it
    > displays the text from
    >
    > end of file > start of file
    >
    > instead of
    >
    > start of file > end of file
    >
    >
    > <%
    > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > Dim ThisLine
    > Dim PrintLine
    > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > SomeFile = Server.MapPath("somefile.txt")
    > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
    > Do While Not InputStream.AtEndOfStream
    > ThisLine = InputStream.ReadLine
    > PrintLine = PrintLine + ThisLine + "<br>"
    > Loop
    > InputStream.Close
    > Set OutputStream = Nothing
    > Set FileObject = Nothing
    > Response.Write PrintLine
    > %>
    >
    > --
    > Regards
    >
    > Steven Burn
    > Ur I.T. Mate Group
    > www.it-mate.co.uk
    >
    > Keeping it FREE!
    >
    > Disclaimer:
    > I know I'm probably wrong, I just like taking part ;o)
    >
    >
    >
     
    Guest, Jan 7, 2004
    #2
    1. Advertising

  3. Steven Burn

    Steven Burn Guest

    Basically, the file contains comments such as below;

    Date
    Name
    E-mail
    Website
    Comments

    (see example at:
    http://www.it-mate.co.uk/support/guestgen/viewguestbook.asp)

    At present, the oldest is shown first (i.e. the first entry in the file) as
    newer one's are simply appended to the file, so are thus, shown last (the
    oldest entry being at the top of the page, and the newest, at the bottom).

    I simply want to reverse the order in which the entries are shown, so the
    newest is at the top, and the oldest, at the bottom. (if that makes sense?).

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    <aa> wrote in message news:...
    > Do you mean that the last line goes first still preserving the prder od
    > letters in it, or you want the last letter of the file to come first and

    so
    > on?
    >
    > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > news:...
    > > Just wondering if anyone is aware of any way to reverse the following so

    > it
    > > displays the text from
    > >
    > > end of file > start of file
    > >
    > > instead of
    > >
    > > start of file > end of file
    > >
    > >
    > > <%
    > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > Dim ThisLine
    > > Dim PrintLine
    > > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > > SomeFile = Server.MapPath("somefile.txt")
    > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    False)
    > > Do While Not InputStream.AtEndOfStream
    > > ThisLine = InputStream.ReadLine
    > > PrintLine = PrintLine + ThisLine + "<br>"
    > > Loop
    > > InputStream.Close
    > > Set OutputStream = Nothing
    > > Set FileObject = Nothing
    > > Response.Write PrintLine
    > > %>
    > >
    > > --
    > > Regards
    > >
    > > Steven Burn
    > > Ur I.T. Mate Group
    > > www.it-mate.co.uk
    > >
    > > Keeping it FREE!
    > >
    > > Disclaimer:
    > > I know I'm probably wrong, I just like taking part ;o)
    > >
    > >
    > >

    >
    >
     
    Steven Burn, Jan 7, 2004
    #3
  4. Steven Burn

    TomB Guest

    PrintLine should contain the entire file, so you should be able to .....

    Dim iLoop
    Dim ReversedPrintLine
    for iLoop = len(PrintLine) to 1 step-1
    ReversedPrintLine=ReversedPrintLine & Mid(PrintLine,iLoop,1)
    next

    I'm assuming somefile.txt is text.

    "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    news:...
    > Just wondering if anyone is aware of any way to reverse the following so

    it
    > displays the text from
    >
    > end of file > start of file
    >
    > instead of
    >
    > start of file > end of file
    >
    >
    > <%
    > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > Dim ThisLine
    > Dim PrintLine
    > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > SomeFile = Server.MapPath("somefile.txt")
    > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
    > Do While Not InputStream.AtEndOfStream
    > ThisLine = InputStream.ReadLine
    > PrintLine = PrintLine + ThisLine + "<br>"
    > Loop
    > InputStream.Close
    > Set OutputStream = Nothing
    > Set FileObject = Nothing
    > Response.Write PrintLine
    > %>
    >
    > --
    > Regards
    >
    > Steven Burn
    > Ur I.T. Mate Group
    > www.it-mate.co.uk
    >
    > Keeping it FREE!
    >
    > Disclaimer:
    > I know I'm probably wrong, I just like taking part ;o)
    >
    >
    >
     
    TomB, Jan 7, 2004
    #4
  5. Steven Burn

    TomB Guest

    I didn't think of that. You could do that (reverse line order but not
    letters) by changing
    PrintLine=PrintLine + ThisLine+"<BR>"
    to
    PrintLine=ThisLine+PrintLine+"<BR>"

    <aa> wrote in message news:...
    > Do you mean that the last line goes first still preserving the prder od
    > letters in it, or you want the last letter of the file to come first and

    so
    > on?
    >
    > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > news:...
    > > Just wondering if anyone is aware of any way to reverse the following so

    > it
    > > displays the text from
    > >
    > > end of file > start of file
    > >
    > > instead of
    > >
    > > start of file > end of file
    > >
    > >
    > > <%
    > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > Dim ThisLine
    > > Dim PrintLine
    > > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > > SomeFile = Server.MapPath("somefile.txt")
    > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    False)
    > > Do While Not InputStream.AtEndOfStream
    > > ThisLine = InputStream.ReadLine
    > > PrintLine = PrintLine + ThisLine + "<br>"
    > > Loop
    > > InputStream.Close
    > > Set OutputStream = Nothing
    > > Set FileObject = Nothing
    > > Response.Write PrintLine
    > > %>
    > >
    > > --
    > > Regards
    > >
    > > Steven Burn
    > > Ur I.T. Mate Group
    > > www.it-mate.co.uk
    > >
    > > Keeping it FREE!
    > >
    > > Disclaimer:
    > > I know I'm probably wrong, I just like taking part ;o)
    > >
    > >
    > >

    >
    >
     
    TomB, Jan 7, 2004
    #5
  6. Steven Burn

    Steven Burn Guest

    It's plain text yes but, unfortunately I've tried that and it reverses the
    order of the entries aswell (see my reply to aa's reply).

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    TomB <> wrote in message
    news:uczm$...
    > PrintLine should contain the entire file, so you should be able to .....
    >
    > Dim iLoop
    > Dim ReversedPrintLine
    > for iLoop = len(PrintLine) to 1 step-1
    > ReversedPrintLine=ReversedPrintLine & Mid(PrintLine,iLoop,1)
    > next
    >
    > I'm assuming somefile.txt is text.
    >
    > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > news:...
    > > Just wondering if anyone is aware of any way to reverse the following so

    > it
    > > displays the text from
    > >
    > > end of file > start of file
    > >
    > > instead of
    > >
    > > start of file > end of file
    > >
    > >
    > > <%
    > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > Dim ThisLine
    > > Dim PrintLine
    > > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > > SomeFile = Server.MapPath("somefile.txt")
    > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    False)
    > > Do While Not InputStream.AtEndOfStream
    > > ThisLine = InputStream.ReadLine
    > > PrintLine = PrintLine + ThisLine + "<br>"
    > > Loop
    > > InputStream.Close
    > > Set OutputStream = Nothing
    > > Set FileObject = Nothing
    > > Response.Write PrintLine
    > > %>
    > >
    > > --
    > > Regards
    > >
    > > Steven Burn
    > > Ur I.T. Mate Group
    > > www.it-mate.co.uk
    > >
    > > Keeping it FREE!
    > >
    > > Disclaimer:
    > > I know I'm probably wrong, I just like taking part ;o)
    > >
    > >
    > >

    >
    >
     
    Steven Burn, Jan 7, 2004
    #6
  7. Steven Burn

    Curt_C [MVP] Guest

    use two strings....
    one to hold the person, one to hold the group.
    Read in the Person info assigning it like
    stringPer = stringPer + moreinfo

    When each person is done assign it to the group string like this
    stringGrp = stringPer + stringGrp
    stringPer = "" (make sure to reset the stringPer each time)



    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    www.Darkfalz.com


    "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    news:...
    > Basically, the file contains comments such as below;
    >
    > Date
    > Name
    > E-mail
    > Website
    > Comments
    >
    > (see example at:
    > http://www.it-mate.co.uk/support/guestgen/viewguestbook.asp)
    >
    > At present, the oldest is shown first (i.e. the first entry in the file)

    as
    > newer one's are simply appended to the file, so are thus, shown last (the
    > oldest entry being at the top of the page, and the newest, at the bottom).
    >
    > I simply want to reverse the order in which the entries are shown, so the
    > newest is at the top, and the oldest, at the bottom. (if that makes

    sense?).
    >
    > --
    > Regards
    >
    > Steven Burn
    > Ur I.T. Mate Group
    > www.it-mate.co.uk
    >
    > Keeping it FREE!
    >
    > Disclaimer:
    > I know I'm probably wrong, I just like taking part ;o)
    >
    >
    > <aa> wrote in message news:...
    > > Do you mean that the last line goes first still preserving the prder od
    > > letters in it, or you want the last letter of the file to come first and

    > so
    > > on?
    > >
    > > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > > news:...
    > > > Just wondering if anyone is aware of any way to reverse the following

    so
    > > it
    > > > displays the text from
    > > >
    > > > end of file > start of file
    > > >
    > > > instead of
    > > >
    > > > start of file > end of file
    > > >
    > > >
    > > > <%
    > > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > > Dim ThisLine
    > > > Dim PrintLine
    > > > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > > > SomeFile = Server.MapPath("somefile.txt")
    > > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    > False)
    > > > Do While Not InputStream.AtEndOfStream
    > > > ThisLine = InputStream.ReadLine
    > > > PrintLine = PrintLine + ThisLine + "<br>"
    > > > Loop
    > > > InputStream.Close
    > > > Set OutputStream = Nothing
    > > > Set FileObject = Nothing
    > > > Response.Write PrintLine
    > > > %>
    > > >
    > > > --
    > > > Regards
    > > >
    > > > Steven Burn
    > > > Ur I.T. Mate Group
    > > > www.it-mate.co.uk
    > > >
    > > > Keeping it FREE!
    > > >
    > > > Disclaimer:
    > > > I know I'm probably wrong, I just like taking part ;o)
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Curt_C [MVP], Jan 7, 2004
    #7
  8. Steven Burn

    Steven Burn Guest

    Cheers Curt, I'll give it a shot ;o)

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    Curt_C [MVP] <software_AT_darkfalz.com> wrote in message
    news:#...
    > use two strings....
    > one to hold the person, one to hold the group.
    > Read in the Person info assigning it like
    > stringPer = stringPer + moreinfo
    >
    > When each person is done assign it to the group string like this
    > stringGrp = stringPer + stringGrp
    > stringPer = "" (make sure to reset the stringPer each time)
    >
    >
    >
    > --
    > Curt Christianson
    > Owner/Lead Developer, DF-Software
    > www.Darkfalz.com
    >
    >
    > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > news:...
    > > Basically, the file contains comments such as below;
    > >
    > > Date
    > > Name
    > > E-mail
    > > Website
    > > Comments
    > >
    > > (see example at:
    > > http://www.it-mate.co.uk/support/guestgen/viewguestbook.asp)
    > >
    > > At present, the oldest is shown first (i.e. the first entry in the file)

    > as
    > > newer one's are simply appended to the file, so are thus, shown last

    (the
    > > oldest entry being at the top of the page, and the newest, at the

    bottom).
    > >
    > > I simply want to reverse the order in which the entries are shown, so

    the
    > > newest is at the top, and the oldest, at the bottom. (if that makes

    > sense?).
    > >
    > > --
    > > Regards
    > >
    > > Steven Burn
    > > Ur I.T. Mate Group
    > > www.it-mate.co.uk
    > >
    > > Keeping it FREE!
    > >
    > > Disclaimer:
    > > I know I'm probably wrong, I just like taking part ;o)
    > >
    > >
    > > <aa> wrote in message news:...
    > > > Do you mean that the last line goes first still preserving the prder

    od
    > > > letters in it, or you want the last letter of the file to come first

    and
    > > so
    > > > on?
    > > >
    > > > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > > > news:...
    > > > > Just wondering if anyone is aware of any way to reverse the

    following
    > so
    > > > it
    > > > > displays the text from
    > > > >
    > > > > end of file > start of file
    > > > >
    > > > > instead of
    > > > >
    > > > > start of file > end of file
    > > > >
    > > > >
    > > > > <%
    > > > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > > > Dim ThisLine
    > > > > Dim PrintLine
    > > > > Set FileObject =

    Server.CreateObject("Scripting.FileSystemObject")
    > > > > SomeFile = Server.MapPath("somefile.txt")
    > > > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    > > False)
    > > > > Do While Not InputStream.AtEndOfStream
    > > > > ThisLine = InputStream.ReadLine
    > > > > PrintLine = PrintLine + ThisLine + "<br>"
    > > > > Loop
    > > > > InputStream.Close
    > > > > Set OutputStream = Nothing
    > > > > Set FileObject = Nothing
    > > > > Response.Write PrintLine
    > > > > %>
    > > > >
    > > > > --
    > > > > Regards
    > > > >
    > > > > Steven Burn
    > > > > Ur I.T. Mate Group
    > > > > www.it-mate.co.uk
    > > > >
    > > > > Keeping it FREE!
    > > > >
    > > > > Disclaimer:
    > > > > I know I'm probably wrong, I just like taking part ;o)
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Steven Burn, Jan 7, 2004
    #8
  9. "Steven Burn" wrote:
    >
    > Just wondering if anyone is aware of any way to reverse
    > the following so it displays the text from
    >
    > end of file > start of file
    >
    > instead of
    >
    > start of file > end of file


    I assume you mean one line at a time. If the file isn't too large, string
    concatenation shouldn't be too taxing on VBScript. Replace these two
    lines...

    ThisLine = InputStream.ReadLine
    PrintLine = PrintLine + ThisLine + "<br>"

    ....with this:
    PrintLine = InputStream.ReadLine() + "<br>" + PrintLine


    In general, reversal of order is a great job for a stack. JScript lets you
    treat any array like one. Then again, it has a reverse() method. For
    completeness, here is a JScript alternative to string concatenation:

    var a = new Array(), forReading = 1,
    fso = Server.CreateOject("Scripting.FileSystemObject"),
    file = fso_OpenTextFile("somefile.txt", forReading)
    while (!file.AtEndOfStream) a.push(file.ReadLine())
    file.Close()

    At this point, you can either use Array.reverse()...
    Response.Write(a.reverse().join("<BR>"))

    ....or a sequence of Array.pop() operations:
    while (a.length) Response.Write(a.pop() + "<BR>")



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Jan 7, 2004
    #9
  10. Steven Burn

    Guest Guest

    Yes, It makes sense.
    The cleanest way seems to use a database rather then a text file - you will
    get much greater freedom of presentation the data.
    Another option is to use XML rather then flat text
    Alternatively you can read the lines into an array and then output the array
    starting with the highest index
    "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    news:...
    > Basically, the file contains comments such as below;
    >
    > Date
    > Name
    > E-mail
    > Website
    > Comments
    >
    > (see example at:
    > http://www.it-mate.co.uk/support/guestgen/viewguestbook.asp)
    >
    > At present, the oldest is shown first (i.e. the first entry in the file)

    as
    > newer one's are simply appended to the file, so are thus, shown last (the
    > oldest entry being at the top of the page, and the newest, at the bottom).
    >
    > I simply want to reverse the order in which the entries are shown, so the
    > newest is at the top, and the oldest, at the bottom. (if that makes

    sense?).
    >
    > --
    > Regards
    >
    > Steven Burn
    > Ur I.T. Mate Group
    > www.it-mate.co.uk
    >
    > Keeping it FREE!
    >
    > Disclaimer:
    > I know I'm probably wrong, I just like taking part ;o)
    >
    >
    > <aa> wrote in message news:...
    > > Do you mean that the last line goes first still preserving the prder od
    > > letters in it, or you want the last letter of the file to come first and

    > so
    > > on?
    > >
    > > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > > news:...
    > > > Just wondering if anyone is aware of any way to reverse the following

    so
    > > it
    > > > displays the text from
    > > >
    > > > end of file > start of file
    > > >
    > > > instead of
    > > >
    > > > start of file > end of file
    > > >
    > > >
    > > > <%
    > > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > > Dim ThisLine
    > > > Dim PrintLine
    > > > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > > > SomeFile = Server.MapPath("somefile.txt")
    > > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    > False)
    > > > Do While Not InputStream.AtEndOfStream
    > > > ThisLine = InputStream.ReadLine
    > > > PrintLine = PrintLine + ThisLine + "<br>"
    > > > Loop
    > > > InputStream.Close
    > > > Set OutputStream = Nothing
    > > > Set FileObject = Nothing
    > > > Response.Write PrintLine
    > > > %>
    > > >
    > > > --
    > > > Regards
    > > >
    > > > Steven Burn
    > > > Ur I.T. Mate Group
    > > > www.it-mate.co.uk
    > > >
    > > > Keeping it FREE!
    > > >
    > > > Disclaimer:
    > > > I know I'm probably wrong, I just like taking part ;o)
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Guest, Jan 7, 2004
    #10
  11. Steven Burn

    Steven Burn Guest

    Cheers for the reply. I'm trying to keep away from the database if I can as
    the file's I've written are to be used by those with no experience in HTML
    or ASP, and are to be placed on servers that don't have Access support (oh
    the joys).

    I'd like to look into the XML side of it and shall do so as soon as my time
    allows, thankyou for the suggestion.

    As for the array, I looked at that when I first wrote it and couldn't get
    the stupid thing to work, so just left it alone. ;o)

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    <aa> wrote in message news:...
    > Yes, It makes sense.
    > The cleanest way seems to use a database rather then a text file - you

    will
    > get much greater freedom of presentation the data.
    > Another option is to use XML rather then flat text
    > Alternatively you can read the lines into an array and then output the

    array
    > starting with the highest index
    > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > news:...
    > > Basically, the file contains comments such as below;
    > >
    > > Date
    > > Name
    > > E-mail
    > > Website
    > > Comments
    > >
    > > (see example at:
    > > http://www.it-mate.co.uk/support/guestgen/viewguestbook.asp)
    > >
    > > At present, the oldest is shown first (i.e. the first entry in the file)

    > as
    > > newer one's are simply appended to the file, so are thus, shown last

    (the
    > > oldest entry being at the top of the page, and the newest, at the

    bottom).
    > >
    > > I simply want to reverse the order in which the entries are shown, so

    the
    > > newest is at the top, and the oldest, at the bottom. (if that makes

    > sense?).
    > >
    > > --
    > > Regards
    > >
    > > Steven Burn
    > > Ur I.T. Mate Group
    > > www.it-mate.co.uk
    > >
    > > Keeping it FREE!
    > >
    > > Disclaimer:
    > > I know I'm probably wrong, I just like taking part ;o)
    > >
    > >
    > > <aa> wrote in message news:...
    > > > Do you mean that the last line goes first still preserving the prder

    od
    > > > letters in it, or you want the last letter of the file to come first

    and
    > > so
    > > > on?
    > > >
    > > > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > > > news:...
    > > > > Just wondering if anyone is aware of any way to reverse the

    following
    > so
    > > > it
    > > > > displays the text from
    > > > >
    > > > > end of file > start of file
    > > > >
    > > > > instead of
    > > > >
    > > > > start of file > end of file
    > > > >
    > > > >
    > > > > <%
    > > > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > > > Dim ThisLine
    > > > > Dim PrintLine
    > > > > Set FileObject =

    Server.CreateObject("Scripting.FileSystemObject")
    > > > > SomeFile = Server.MapPath("somefile.txt")
    > > > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    > > False)
    > > > > Do While Not InputStream.AtEndOfStream
    > > > > ThisLine = InputStream.ReadLine
    > > > > PrintLine = PrintLine + ThisLine + "<br>"
    > > > > Loop
    > > > > InputStream.Close
    > > > > Set OutputStream = Nothing
    > > > > Set FileObject = Nothing
    > > > > Response.Write PrintLine
    > > > > %>
    > > > >
    > > > > --
    > > > > Regards
    > > > >
    > > > > Steven Burn
    > > > > Ur I.T. Mate Group
    > > > > www.it-mate.co.uk
    > > > >
    > > > > Keeping it FREE!
    > > > >
    > > > > Disclaimer:
    > > > > I know I'm probably wrong, I just like taking part ;o)
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Steven Burn, Jan 7, 2004
    #11
  12. Steven Burn

    Steven Burn Guest

    Cheers for the reply Dave. Unfortunately, neither of the solutions will work
    as the entries in the text file (basically a flat text database) are along
    the line's of;

    date
    name
    email
    website
    comments

    Thus, using the solutions provided would also reverse the way the above
    appears. Instead (and I should have probably said in the first place), I'm
    trying to get each actual "entry" (as above) reversed (if that makes
    sense?).

    I should probably just place a marker or something with each entry, but
    decided not to (just to keep it explicitly simple, or so I thought at the
    time ;o)).

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    Dave Anderson <> wrote in message
    news:...
    > "Steven Burn" wrote:
    > >
    > > Just wondering if anyone is aware of any way to reverse
    > > the following so it displays the text from
    > >
    > > end of file > start of file
    > >
    > > instead of
    > >
    > > start of file > end of file

    >
    > I assume you mean one line at a time. If the file isn't too large, string
    > concatenation shouldn't be too taxing on VBScript. Replace these two
    > lines...
    >
    > ThisLine = InputStream.ReadLine
    > PrintLine = PrintLine + ThisLine + "<br>"
    >
    > ...with this:
    > PrintLine = InputStream.ReadLine() + "<br>" + PrintLine
    >
    >
    > In general, reversal of order is a great job for a stack. JScript lets you
    > treat any array like one. Then again, it has a reverse() method. For
    > completeness, here is a JScript alternative to string concatenation:
    >
    > var a = new Array(), forReading = 1,
    > fso = Server.CreateOject("Scripting.FileSystemObject"),
    > file = fso_OpenTextFile("somefile.txt", forReading)
    > while (!file.AtEndOfStream) a.push(file.ReadLine())
    > file.Close()
    >
    > At this point, you can either use Array.reverse()...
    > Response.Write(a.reverse().join("<BR>"))
    >
    > ...or a sequence of Array.pop() operations:
    > while (a.length) Response.Write(a.pop() + "<BR>")
    >
    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.

    Use
    > of this email address implies consent to these terms. Please do not

    contact
    > me directly or ask me to contact you directly for assistance. If your
    > question is worth asking, it's worth posting.
    >
    >
     
    Steven Burn, Jan 7, 2004
    #12
  13. "Steven Burn" wrote:
    >
    > Thus, using the solutions provided would also reverse the way
    > the above appears. Instead (and I should have probably said in
    > the first place), I'm trying to get each actual "entry" (as
    > above) reversed (if that makes sense?).


    I think it makes sense -- you have a repeating sequence of 5 lines, the
    sequence of which you want to invert. Correct?



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Jan 7, 2004
    #13
  14. Steven Burn

    Steven Burn Guest

    Basically, yes.......

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    Dave Anderson <> wrote in message
    news:...
    > "Steven Burn" wrote:
    > >
    > > Thus, using the solutions provided would also reverse the way
    > > the above appears. Instead (and I should have probably said in
    > > the first place), I'm trying to get each actual "entry" (as
    > > above) reversed (if that makes sense?).

    >
    > I think it makes sense -- you have a repeating sequence of 5 lines, the
    > sequence of which you want to invert. Correct?
    >
    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.

    Use
    > of this email address implies consent to these terms. Please do not

    contact
    > me directly or ask me to contact you directly for assistance. If your
    > question is worth asking, it's worth posting.
    >
    >
     
    Steven Burn, Jan 7, 2004
    #14
  15. "Steven Burn" wrote:
    >
    > Basically, yes.......


    In that case, how about something like this?

    Const ForReading = 1
    Dim FileObject, SomeFile, InputStream, PrintLine, LineCount
    Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    SomeFile = Server.MapPath("somefile.txt")
    Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
    LineCount = 0
    Do While Not InputStream.AtEndOfStream
    LineCount = LineCount + 1
    PrintLine = InputStream.ReadLine() + "<br>" + PrintLine
    If LineCount Mod 5 = 0 Then
    Response.Write(PrintLine)
    Else
    PrintLine = ""
    End If
    Loop
    InputStream.Close
    Set OutputStream = Nothing
    Set FileObject = Nothing


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
     
    Dave Anderson, Jan 7, 2004
    #15
  16. Steven Burn

    TomB Guest

    Is it possible to change the content of the text file when you are writing,
    rather than reading? I'm sure you are doing an append, but if you could
    read the contents of the text file in then replace the contents with the New
    followed by the current then you'd have the text file in the order you want.

    I assume you'd have more reads than writes, so this would (I'm guessing) be
    a little more efficient.


    "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    news:...
    > Basically, the file contains comments such as below;
    >
    > Date
    > Name
    > E-mail
    > Website
    > Comments
    >
    > (see example at:
    > http://www.it-mate.co.uk/support/guestgen/viewguestbook.asp)
    >
    > At present, the oldest is shown first (i.e. the first entry in the file)

    as
    > newer one's are simply appended to the file, so are thus, shown last (the
    > oldest entry being at the top of the page, and the newest, at the bottom).
    >
    > I simply want to reverse the order in which the entries are shown, so the
    > newest is at the top, and the oldest, at the bottom. (if that makes

    sense?).
    >
    > --
    > Regards
    >
    > Steven Burn
    > Ur I.T. Mate Group
    > www.it-mate.co.uk
    >
    > Keeping it FREE!
    >
    > Disclaimer:
    > I know I'm probably wrong, I just like taking part ;o)
    >
    >
    > <aa> wrote in message news:...
    > > Do you mean that the last line goes first still preserving the prder od
    > > letters in it, or you want the last letter of the file to come first and

    > so
    > > on?
    > >
    > > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > > news:...
    > > > Just wondering if anyone is aware of any way to reverse the following

    so
    > > it
    > > > displays the text from
    > > >
    > > > end of file > start of file
    > > >
    > > > instead of
    > > >
    > > > start of file > end of file
    > > >
    > > >
    > > > <%
    > > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > > Dim ThisLine
    > > > Dim PrintLine
    > > > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > > > SomeFile = Server.MapPath("somefile.txt")
    > > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    > False)
    > > > Do While Not InputStream.AtEndOfStream
    > > > ThisLine = InputStream.ReadLine
    > > > PrintLine = PrintLine + ThisLine + "<br>"
    > > > Loop
    > > > InputStream.Close
    > > > Set OutputStream = Nothing
    > > > Set FileObject = Nothing
    > > > Response.Write PrintLine
    > > > %>
    > > >
    > > > --
    > > > Regards
    > > >
    > > > Steven Burn
    > > > Ur I.T. Mate Group
    > > > www.it-mate.co.uk
    > > >
    > > > Keeping it FREE!
    > > >
    > > > Disclaimer:
    > > > I know I'm probably wrong, I just like taking part ;o)
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    TomB, Jan 7, 2004
    #16
  17. Steven Burn

    Guest Guest

    eXcellent idea. I wish I though about this myself.
    I suggest Steven to drop all other options and do just this

    "TomB" <> wrote in message
    news:...
    > Is it possible to change the content of the text file when you are

    writing,
    > rather than reading? I'm sure you are doing an append, but if you could
    > read the contents of the text file in then replace the contents with the

    New
    > followed by the current then you'd have the text file in the order you

    want.
    >
    > I assume you'd have more reads than writes, so this would (I'm guessing)

    be
    > a little more efficient.
    >
    >
    > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > news:...
    > > Basically, the file contains comments such as below;
    > >
    > > Date
    > > Name
    > > E-mail
    > > Website
    > > Comments
    > >
    > > (see example at:
    > > http://www.it-mate.co.uk/support/guestgen/viewguestbook.asp)
    > >
    > > At present, the oldest is shown first (i.e. the first entry in the file)

    > as
    > > newer one's are simply appended to the file, so are thus, shown last

    (the
    > > oldest entry being at the top of the page, and the newest, at the

    bottom).
    > >
    > > I simply want to reverse the order in which the entries are shown, so

    the
    > > newest is at the top, and the oldest, at the bottom. (if that makes

    > sense?).
    > >
    > > --
    > > Regards
    > >
    > > Steven Burn
    > > Ur I.T. Mate Group
    > > www.it-mate.co.uk
    > >
    > > Keeping it FREE!
    > >
    > > Disclaimer:
    > > I know I'm probably wrong, I just like taking part ;o)
    > >
    > >
    > > <aa> wrote in message news:...
    > > > Do you mean that the last line goes first still preserving the prder

    od
    > > > letters in it, or you want the last letter of the file to come first

    and
    > > so
    > > > on?
    > > >
    > > > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > > > news:...
    > > > > Just wondering if anyone is aware of any way to reverse the

    following
    > so
    > > > it
    > > > > displays the text from
    > > > >
    > > > > end of file > start of file
    > > > >
    > > > > instead of
    > > > >
    > > > > start of file > end of file
    > > > >
    > > > >
    > > > > <%
    > > > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > > > Dim ThisLine
    > > > > Dim PrintLine
    > > > > Set FileObject =

    Server.CreateObject("Scripting.FileSystemObject")
    > > > > SomeFile = Server.MapPath("somefile.txt")
    > > > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    > > False)
    > > > > Do While Not InputStream.AtEndOfStream
    > > > > ThisLine = InputStream.ReadLine
    > > > > PrintLine = PrintLine + ThisLine + "<br>"
    > > > > Loop
    > > > > InputStream.Close
    > > > > Set OutputStream = Nothing
    > > > > Set FileObject = Nothing
    > > > > Response.Write PrintLine
    > > > > %>
    > > > >
    > > > > --
    > > > > Regards
    > > > >
    > > > > Steven Burn
    > > > > Ur I.T. Mate Group
    > > > > www.it-mate.co.uk
    > > > >
    > > > > Keeping it FREE!
    > > > >
    > > > > Disclaimer:
    > > > > I know I'm probably wrong, I just like taking part ;o)
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Guest, Jan 7, 2004
    #17
  18. Steven Burn

    Steven Burn Guest

    Cheers Dave.

    Unfortunately, something seems to have gone amiss on this one;

    What it looks like;

    http://www.it-mate.co.uk/temp/tmpgb/viewguestbook.asp

    Actual contents;

    http://www.it-mate.co.uk/support/guestgen/viewguestbook.asp

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    Dave Anderson <> wrote in message
    news:O6pm$...
    > "Steven Burn" wrote:
    > >
    > > Basically, yes.......

    >
    > In that case, how about something like this?
    >
    > Const ForReading = 1
    > Dim FileObject, SomeFile, InputStream, PrintLine, LineCount
    > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > SomeFile = Server.MapPath("somefile.txt")
    > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
    > LineCount = 0
    > Do While Not InputStream.AtEndOfStream
    > LineCount = LineCount + 1
    > PrintLine = InputStream.ReadLine() + "<br>" + PrintLine
    > If LineCount Mod 5 = 0 Then
    > Response.Write(PrintLine)
    > Else
    > PrintLine = ""
    > End If
    > Loop
    > InputStream.Close
    > Set OutputStream = Nothing
    > Set FileObject = Nothing
    >
    >
    > --
    > Dave Anderson
    >
    > Unsolicited commercial email will be read at a cost of $500 per message.

    Use
    > of this email address implies consent to these terms. Please do not

    contact
    > me directly or ask me to contact you directly for assistance. If your
    > question is worth asking, it's worth posting.
    >
    >
     
    Steven Burn, Jan 7, 2004
    #18
  19. Steven Burn

    Steven Burn Guest

    Tom, short of using a DB, it certainly looks like it so I'll just do
    that.....

    Thanks for the replies everyone.

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    Disclaimer:
    I know I'm probably wrong, I just like taking part ;o)


    TomB <> wrote in message
    news:...
    > Is it possible to change the content of the text file when you are

    writing,
    > rather than reading? I'm sure you are doing an append, but if you could
    > read the contents of the text file in then replace the contents with the

    New
    > followed by the current then you'd have the text file in the order you

    want.
    >
    > I assume you'd have more reads than writes, so this would (I'm guessing)

    be
    > a little more efficient.
    >
    >
    > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > news:...
    > > Basically, the file contains comments such as below;
    > >
    > > Date
    > > Name
    > > E-mail
    > > Website
    > > Comments
    > >
    > > (see example at:
    > > http://www.it-mate.co.uk/support/guestgen/viewguestbook.asp)
    > >
    > > At present, the oldest is shown first (i.e. the first entry in the file)

    > as
    > > newer one's are simply appended to the file, so are thus, shown last

    (the
    > > oldest entry being at the top of the page, and the newest, at the

    bottom).
    > >
    > > I simply want to reverse the order in which the entries are shown, so

    the
    > > newest is at the top, and the oldest, at the bottom. (if that makes

    > sense?).
    > >
    > > --
    > > Regards
    > >
    > > Steven Burn
    > > Ur I.T. Mate Group
    > > www.it-mate.co.uk
    > >
    > > Keeping it FREE!
    > >
    > > Disclaimer:
    > > I know I'm probably wrong, I just like taking part ;o)
    > >
    > >
    > > <aa> wrote in message news:...
    > > > Do you mean that the last line goes first still preserving the prder

    od
    > > > letters in it, or you want the last letter of the file to come first

    and
    > > so
    > > > on?
    > > >
    > > > "Steven Burn" <nobody@PVT_it-mate.co.uk> wrote in message
    > > > news:...
    > > > > Just wondering if anyone is aware of any way to reverse the

    following
    > so
    > > > it
    > > > > displays the text from
    > > > >
    > > > > end of file > start of file
    > > > >
    > > > > instead of
    > > > >
    > > > > start of file > end of file
    > > > >
    > > > >
    > > > > <%
    > > > > Const ForReading = 1, ForWriting = 2, ForAppending = 8
    > > > > Dim ThisLine
    > > > > Dim PrintLine
    > > > > Set FileObject =

    Server.CreateObject("Scripting.FileSystemObject")
    > > > > SomeFile = Server.MapPath("somefile.txt")
    > > > > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading,

    > > False)
    > > > > Do While Not InputStream.AtEndOfStream
    > > > > ThisLine = InputStream.ReadLine
    > > > > PrintLine = PrintLine + ThisLine + "<br>"
    > > > > Loop
    > > > > InputStream.Close
    > > > > Set OutputStream = Nothing
    > > > > Set FileObject = Nothing
    > > > > Response.Write PrintLine
    > > > > %>
    > > > >
    > > > > --
    > > > > Regards
    > > > >
    > > > > Steven Burn
    > > > > Ur I.T. Mate Group
    > > > > www.it-mate.co.uk
    > > > >
    > > > > Keeping it FREE!
    > > > >
    > > > > Disclaimer:
    > > > > I know I'm probably wrong, I just like taking part ;o)
    > > > >
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Steven Burn, Jan 7, 2004
    #19
  20. Steven Burn

    Brynn Guest

    You could go grab my TextToArray.asp script and do


    <!-- #include virtual =
    "/coolpier_scripts/_text_tools/TextToArray.asp" -->
    <%
    Dim yourArray
    yourArray =
    cp_TextFileToArray(Server.MapPath("/directory/yourTextFile"), "none")

    n = ubound(yourArray)
    Do Until n < 0


    n = n - 1
    Loop
    %>

    Brynn
    www.coolpier.com


    On Wed, 7 Jan 2004 12:11:10 -0000, "Steven Burn"
    <nobody@PVT_it-mate.co.uk> wrote:

    >Just wondering if anyone is aware of any way to reverse the following so it
    >displays the text from
    >
    > end of file > start of file
    >
    >instead of
    >
    > start of file > end of file
    >
    >
    ><%
    >Const ForReading = 1, ForWriting = 2, ForAppending = 8
    >Dim ThisLine
    >Dim PrintLine
    > Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
    > SomeFile = Server.MapPath("somefile.txt")
    > Set InputStream = FileObject.OpenTextFile(SomeFile, ForReading, False)
    > Do While Not InputStream.AtEndOfStream
    > ThisLine = InputStream.ReadLine
    > PrintLine = PrintLine + ThisLine + "<br>"
    > Loop
    > InputStream.Close
    > Set OutputStream = Nothing
    > Set FileObject = Nothing
    > Response.Write PrintLine
    >%>
    >
    >--
    >Regards
    >
    >Steven Burn
    >Ur I.T. Mate Group
    >www.it-mate.co.uk
    >
    >Keeping it FREE!
    >
    >Disclaimer:
    >I know I'm probably wrong, I just like taking part ;o)
    >
    >
    >
     
    Brynn, Jan 7, 2004
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rastislav Struharik

    Reverse engineering an EDIF file?

    Rastislav Struharik, Nov 10, 2003, in forum: VHDL
    Replies:
    8
    Views:
    7,997
    Joonas Timo Taavetti Kekoni
    Jan 2, 2004
  2. Shannon Yoder

    How do I list records in reverse order?

    Shannon Yoder, Aug 14, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    393
  3. dogbite
    Replies:
    4
    Views:
    695
    osmium
    Oct 10, 2003
  4. Rajorshi  Biswas
    Replies:
    6
    Views:
    791
    glen herrmannsfeldt
    Sep 28, 2005
  5. leo
    Replies:
    1
    Views:
    294
    Bob Lehmann
    Dec 5, 2005
Loading...

Share This Page