Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > ASP Write Method - How to Position the Cursor

Reply
Thread Tools

ASP Write Method - How to Position the Cursor

 
 
Billy
Guest
Posts: n/a
 
      02-07-2007
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?

 
Reply With Quote
 
 
 
 
Daniel Crichton
Guest
Posts: n/a
 
      02-07-2007
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


 
Reply With Quote
 
 
 
 
Billy
Guest
Posts: n/a
 
      02-07-2007
On Feb 7, 11:12 am, "Daniel Crichton" <(E-Mail Removed)> 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

 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      02-07-2007
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.


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      02-07-2007
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
how to tell if cursor is sqlite.Cursor or psycopg2.Cursor dmaziuk Python 3 01-25-2011 04:52 AM
Declare Cursor error while implementing SCROLL CURSOR invy C Programming 4 12-28-2006 02:35 PM
Changing DEFAULT cursor to WAIT cursor in ASP =?Utf-8?B?VG9tYXMgS2VwaWM=?= ASP .Net 1 04-05-2005 07:42 PM
OT: Position Mouse Cursor in centre of screen Slarty Bartfast MCSE 11 10-08-2003 06:49 PM



Advertisments