ASP Write Method - How to Position the Cursor

B

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?
 
D

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
 
B

Billy

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










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
 
B

Bob Barrows [MVP]

Billy said:
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)
 
E

Evertjan.

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top