ASP Write Method - How to Position the Cursor

ASP Write Method - How to Position the Cursor

am 07.02.2007 17:05:00 von Billy

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?

Re: ASP Write Method - How to Position the Cursor

am 07.02.2007 17:12:11 von Daniel Crichton

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

Re: ASP Write Method - How to Position the Cursor

am 07.02.2007 17:50:11 von Billy

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

Re: ASP Write Method - How to Position the Cursor

am 07.02.2007 18:00:03 von reb01501

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.

Re: ASP Write Method - How to Position the Cursor

am 07.02.2007 18:01:14 von exjxw.hannivoort

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)