472,141 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

ASP Write Method - How to Position the Cursor

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?

Feb 7 '07 #1
4 4533
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
Feb 7 '07 #2
On Feb 7, 11:12 am, "Daniel Crichton" <msn...@worldofspack.comwrote:
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

Feb 7 '07 #3
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)
Feb 7 '07 #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.
Feb 7 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Xah Lee | last post: by
3 posts views Thread by Priya | last post: by
2 posts views Thread by Michael C | last post: by
3 posts views Thread by Mathieu Chavoutier | last post: by
1 post views Thread by Paul | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.