ASP Write Method - How to Position the Cursor

Discussion in 'ASP General' started by Billy, Feb 7, 2007.

  1. Billy

    Billy Guest

    Hi all, I'm building a text file from a database table using the ASP
    Write Method and would like to position the cursor in a specific
    column position before writing the fields. As I loop through and write
    the fields into strings of rows, I want to be able to put field1 in
    row1/column position1, field2 in row1/column position10,.....etc.

    I've included the basic code to write a string of text. I understand
    the process of how to write the fields and loop, etc. If you would be
    kind enough to just show me in there the syntax for positioning the
    cursor before the write I will then apply it to my code.

    Your help is appeciated!

    Code
    <%
    dim fs,f
    set fs=Server.CreateObject("Scripting.FileSystemObject")
    set f=fs.CreateTextFile("c:\test.txt",true)
    f.write("Hello World!")
    f.write("How are you today?")
    f.close
    set f=nothing
    set fs=nothing
    %>The file test.txt will look like this after executing the code
    above:

    Result
    Hello World!How are you today?
    Billy, Feb 7, 2007
    #1
    1. Advertising

  2. Billy wrote on 7 Feb 2007 08:05:00 -0800:

    > Hi all, I'm building a text file from a database table using the ASP
    > Write Method and would like to position the cursor in a specific
    > column position before writing the fields. As I loop through and write
    > the fields into strings of rows, I want to be able to put field1 in
    > row1/column position1, field2 in row1/column position10,.....etc.
    >
    > I've included the basic code to write a string of text. I understand
    > the process of how to write the fields and loop, etc. If you would be
    > kind enough to just show me in there the syntax for positioning the
    > cursor before the write I will then apply it to my code.
    >
    > Your help is appeciated!
    >
    > Code
    > <%
    > dim fs,f
    > set fs=Server.CreateObject("Scripting.FileSystemObject")
    > set f=fs.CreateTextFile("c:\test.txt",true)
    > f.write("Hello World!")
    > f.write("How are you today?")
    > f.close
    > set f=nothing
    > set fs=nothing
    > %>The file test.txt will look like this after executing the code
    > above:
    >
    > Result
    > Hello World!How are you today?


    To position the "cursor" (you're actually just writing to a file, there is
    no cursor, but I'll stick with your terminology), you have to write the data
    to get it to where you want it to go.

    For instance, if you want Hello at row 1 col 1, and then World at row 1 col
    10, and How are you at row2 col 3, you would do something like this:

    f.write "Hello" & Space(4) & "World" & vbCrLf & Space(2) & "How are you"

    You have to work out how to do all the spacing yourself - there is no such
    thing as a cursor position.

    Dan
    Daniel Crichton, Feb 7, 2007
    #2
    1. Advertising

  3. Billy

    Billy Guest

    On Feb 7, 11:12 am, "Daniel Crichton" <> wrote:
    > Billy wrote on 7 Feb 2007 08:05:00 -0800:
    >
    >
    >
    >
    >
    > > Hi all, I'm building a text file from a database table using the ASP
    > > Write Method and would like to position the cursor in a specific
    > > column position before writing the fields. As I loop through and write
    > > the fields into strings of rows, I want to be able to put field1 in
    > > row1/column position1, field2 in row1/column position10,.....etc.

    >
    > > I've included the basic code to write a string of text. I understand
    > > the process of how to write the fields and loop, etc. If you would be
    > > kind enough to just show me in there the syntax for positioning the
    > > cursor before the write I will then apply it to my code.

    >
    > > Your help is appeciated!

    >
    > > Code
    > > <%
    > > dim fs,f
    > > set fs=Server.CreateObject("Scripting.FileSystemObject")
    > > set f=fs.CreateTextFile("c:\test.txt",true)
    > > f.write("Hello World!")
    > > f.write("How are you today?")
    > > f.close
    > > set f=nothing
    > > set fs=nothing
    > > %>The file test.txt will look like this after executing the code
    > > above:

    >
    > > Result
    > > Hello World!How are you today?

    >
    > To position the "cursor" (you're actually just writing to a file, there is
    > no cursor, but I'll stick with your terminology), you have to write the data
    > to get it to where you want it to go.
    >
    > For instance, if you want Hello at row 1 col 1, and then World at row 1 col
    > 10, and How are you at row2 col 3, you would do something like this:
    >
    > f.write "Hello" & Space(4) & "World" & vbCrLf & Space(2) & "How are you"
    >
    > You have to work out how to do all the spacing yourself - there is no such
    > thing as a cursor position.
    >
    > Dan- Hide quoted text -
    >
    > - Show quoted text -


    Ok, thank you. What I'm actually trying to do is to write out fields
    from a table that I have no control to change; and the data in the
    fields are variable in size (never the same length), yet the developer
    who is importing my final text file data into a hosted app is
    requiring this text file to be fixed width - not comma delimited. I
    have to ensure that no matter how long the string of data that I read
    from the field is, that I write it in each row consistently in the
    same place. I never know how big the field string will be so I cant
    just write spaces after the write or else the data shifts constantly.
    I gave the developer a field definition table so he is expecting the
    fields to always appear the same size.....

    output example (see how the data shifts from row to row when the field
    is shorter in some instances.....

    example:

    PK 0676 PRE 908047817799 FedEx 02/06/2007
    PK 068 PRE 908047817803 FedEx 02/06/2007
    LKZ PRE 908047817939 FedEx 02/06/2007
    Billy, Feb 7, 2007
    #3
  4. Billy wrote:
    > Ok, thank you. What I'm actually trying to do is to write out fields
    > from a table that I have no control to change; and the data in the
    > fields are variable in size (never the same length), yet the developer
    > who is importing my final text file data into a hosted app is
    > requiring this text file to be fixed width - not comma delimited. I
    > have to ensure that no matter how long the string of data that I read
    > from the field is, that I write it in each row consistently in the
    > same place.


    Use Left() to guarantee the proper length:
    a="PK"
    correct_length_a=Left(a & Space(5), 5)

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Feb 7, 2007
    #4
  5. Billy

    Evertjan. Guest

    Billy wrote on 07 feb 2007 in microsoft.public.inetserver.asp.general:

    > yet the developer
    > who is importing my final text file data into a hosted app is
    > requiring this text file to be fixed width - not comma delimited.


    you can fill the defined room of char places to a defined total:

    VBS example:

    aStringvalue = "qwerty"

    function fillPlaces(v,n)
    bars = "-------------------------------------- "
    fillPlaces = right(bars & v,n)
    end function

    f.write fillPlaces(aStringvalue,12)


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Feb 7, 2007
    #5
    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. Matt Tapia

    Insert text at cursor position

    Matt Tapia, Nov 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    533
    Chris Taylor
    Nov 26, 2003
  2. Matt Tapia

    Insert text at cursor position...still

    Matt Tapia, Dec 1, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    584
    General Protection Fault
    Dec 1, 2003
  3. =?Utf-8?B?VG9tYXMgS2VwaWM=?=

    Changing DEFAULT cursor to WAIT cursor in ASP

    =?Utf-8?B?VG9tYXMgS2VwaWM=?=, Apr 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,298
    Bruce Barker
    Apr 5, 2005
  4. invy
    Replies:
    4
    Views:
    380
    CBFalconer
    Dec 28, 2006
  5. dmaziuk
    Replies:
    3
    Views:
    556
    Chris Gonnerman
    Jan 25, 2011
Loading...

Share This Page