I have an asp script that gets recordss from an access database. .The fields
in the database have a specific length. I need to write the recordsets into
a txt file but if i have a field in the db that is 15 char. long
but there are only 5 char. written into the db i need to retreve the 5
chars. and the 10 empty spaces, and then
write them into the txt file, but when i retreive the RS it only writes the
5chars. What do i have to do
to retreive the blank spaces??
Re: Return the whole field length
am 26.07.2005 15:40:59 von unknown
What kind of database? If SQL, if you were using char (instead of varchar,
let's say), your lengths would be consistent. But, as far as a non-database
solution, do:
Function Pad(s,n)
Pad = Left(s & String(n, " "), n)
End Function
Ray at work
"polilop" wrote in message
news:esW9dXdkFHA.3656@TK2MSFTNGP09.phx.gbl...
> I have an asp script that gets recordss from an access database. .The
fields
> in the database have a specific length. I need to write the recordsets
into
> a txt file but if i have a field in the db that is 15 char. long
> but there are only 5 char. written into the db i need to retreve the 5
> chars. and the 10 empty spaces, and then
> write them into the txt file, but when i retreive the RS it only writes
the
> 5chars. What do i have to do
> to retreive the blank spaces??
>
>
Re: Return the whole field length
am 26.07.2005 16:15:47 von Roland Hall
"polilop" wrote in message news:esW9dXdkFHA.3656@TK2MSFTNGP09.phx.gbl...
:I have an asp script that gets recordss from an access database. .The
fields
: in the database have a specific length. I need to write the recordsets
into
: a txt file but if i have a field in the db that is 15 char. long
: but there are only 5 char. written into the db i need to retreve the 5
: chars. and the 10 empty spaces, and then
: write them into the txt file, but when i retreive the RS it only writes
the
: 5chars. What do i have to do
: to retreive the blank spaces??
Assume _ is a space character and c is a character.
Is the data stored as ccccc__________ or __________ccccc
Have you verified using len that the data retrieved is actually only 5
characters?
Response.Write len(rs("myvar"))
Have you verified it is actually in the database as 5 characters and 10
spaces characters or are you saying the field is set to max 15 characters
and the field is holding 5?
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Re: Return the whole field length
am 27.07.2005 08:13:04 von fmatosic
Sorry didn't explain the problem well.
I have an access db. It has a table with 10 fields all different lengths.
What i have to do is take the data and write it into a txt file.
the 1st field is 15 chars long, 2nd is 10 ........
but the thing is that if the data in the first (or any field ) is less than
the specified length,
when i write into the txt file, i have to add to the end of the data space
characters.
eg.
first field is "name" its field size is 15 and the data is "Steven"
2nd filed is "surename" field size is 20 and the data is "Henry"
in the text file it has to look like this
( ill put _ as space characters)
Steven_________Henry_______________
Then after i process the first row at the end i have to put CRLF and write
the next row of data into
the new line?
The problem with the padding function is that i have to retreive the data
with
a.WriteLine((RsPrijava.Fields.Item("name").Value) .......
And cannot give the function the remaining spaces that it has to add, as the
field lengths are of different sizes.
"Roland Hall" wrote in message
news:ecUyFyekFHA.576@TK2MSFTNGP15.phx.gbl...
> "polilop" wrote in message news:esW9dXdkFHA.3656@TK2MSFTNGP09.phx.gbl...
> :I have an asp script that gets recordss from an access database. .The
> fields
> : in the database have a specific length. I need to write the recordsets
> into
> : a txt file but if i have a field in the db that is 15 char. long
> : but there are only 5 char. written into the db i need to retreve the 5
> : chars. and the 10 empty spaces, and then
> : write them into the txt file, but when i retreive the RS it only writes
> the
> : 5chars. What do i have to do
> : to retreive the blank spaces??
>
> Assume _ is a space character and c is a character.
>
> Is the data stored as ccccc__________ or __________ccccc
>
> Have you verified using len that the data retrieved is actually only 5
> characters?
>
> Response.Write len(rs("myvar"))
>
> Have you verified it is actually in the database as 5 characters and 10
> spaces characters or are you saying the field is set to max 15 characters
> and the field is holding 5?
>
> --
> Roland Hall
> /* This information is distributed in the hope that it will be useful, but
> without any warranty; without even the implied warranty of merchantability
> or fitness for a particular purpose. */
> Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
> WSH 5.6 Documentation -
> http://msdn.microsoft.com/downloads/list/webdev.asp
> MSDN Library - http://msdn.microsoft.com/library/default.asp
>
>
Re: Return the whole field length
am 27.07.2005 08:46:37 von Tim Williams
not difficult....
'sample for 2 fields
f=RsPrijava.Fields
s=Pad(f("name").value,15) & Pad(f("surname").value,20)
a.writeline(s)
"polilop" wrote in message
news:%23y91CJnkFHA.708@TK2MSFTNGP10.phx.gbl...
> Sorry didn't explain the problem well.
> I have an access db. It has a table with 10 fields all different
> lengths.
> What i have to do is take the data and write it into a txt file.
> the 1st field is 15 chars long, 2nd is 10 ........
> but the thing is that if the data in the first (or any field ) is
> less than the specified length,
> when i write into the txt file, i have to add to the end of the data
> space characters.
> eg.
> first field is "name" its field size is 15 and the data is "Steven"
> 2nd filed is "surename" field size is 20 and the data is "Henry"
>
> in the text file it has to look like this
> ( ill put _ as space characters)
> Steven_________Henry_______________
>
> Then after i process the first row at the end i have to put CRLF and
> write the next row of data into
> the new line?
>
> The problem with the padding function is that i have to retreive
> the data with
> a.WriteLine((RsPrijava.Fields.Item("name").Value) .......
> And cannot give the function the remaining spaces that it has to
> add, as the field lengths are of different sizes.
>
>
>
> "Roland Hall" wrote in message
> news:ecUyFyekFHA.576@TK2MSFTNGP15.phx.gbl...
>> "polilop" wrote in message
>> news:esW9dXdkFHA.3656@TK2MSFTNGP09.phx.gbl...
>> :I have an asp script that gets recordss from an access database.
>> .The
>> fields
>> : in the database have a specific length. I need to write the
>> recordsets
>> into
>> : a txt file but if i have a field in the db that is 15 char. long
>> : but there are only 5 char. written into the db i need to retreve
>> the 5
>> : chars. and the 10 empty spaces, and then
>> : write them into the txt file, but when i retreive the RS it only
>> writes
>> the
>> : 5chars. What do i have to do
>> : to retreive the blank spaces??
>>
>> Assume _ is a space character and c is a character.
>>
>> Is the data stored as ccccc__________ or __________ccccc
>>
>> Have you verified using len that the data retrieved is actually
>> only 5
>> characters?
>>
>> Response.Write len(rs("myvar"))
>>
>> Have you verified it is actually in the database as 5 characters
>> and 10
>> spaces characters or are you saying the field is set to max 15
>> characters
>> and the field is holding 5?
>>
>> --
>> Roland Hall
>> /* This information is distributed in the hope that it will be
>> useful, but
>> without any warranty; without even the implied warranty of
>> merchantability
>> or fitness for a particular purpose. */
>> Technet Script Center -
>> http://www.microsoft.com/technet/scriptcenter/
>> WSH 5.6 Documentation -
>> http://msdn.microsoft.com/downloads/list/webdev.asp
>> MSDN Library - http://msdn.microsoft.com/library/default.asp
>>
>>
>
>
Re: Return the whole field length
am 27.07.2005 23:49:26 von Roland Hall
"polilop" wrote in message news:%23y91CJnkFHA.708@TK2MSFTNGP10.phx.gbl...
: Sorry didn't explain the problem well.
: I have an access db. It has a table with 10 fields all different lengths.
: What i have to do is take the data and write it into a txt file.
: the 1st field is 15 chars long, 2nd is 10 ........
: but the thing is that if the data in the first (or any field ) is less
than
: the specified length,
: when i write into the txt file, i have to add to the end of the data space
: characters.
: eg.
: first field is "name" its field size is 15 and the data is "Steven"
: 2nd filed is "surename" field size is 20 and the data is "Henry"
:
: in the text file it has to look like this
: ( ill put _ as space characters)
: Steven_________Henry_______________
:
: Then after i process the first row at the end i have to put CRLF and write
: the next row of data into
: the new line?
:
: The problem with the padding function is that i have to retreive the data
: with
: a.WriteLine((RsPrijava.Fields.Item("name").Value) .......
: And cannot give the function the remaining spaces that it has to add, as
the
: field lengths are of different sizes.
To add to Tim's suggestion...
function pad(str, length)
pad = str & space(length - len(str))
end function
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Re: Return the whole field length
am 28.07.2005 14:36:59 von fmatosic
The pad function helped a lot, and solved my problem
but still trying to find a permanent solution to the problem. This way if i
add a new
field to the db i have to go into the code and add the field (with the pad
function),
so i'm trying to see if i can automatically retreve the data, get the real
length of the field
defined in the database and subtract it from the data length written and
then add the space characters
with the pad function and go through the recordset with:
for each x in rs.Fields
that way i dont have to name the fields, but then after each field the
writeline function adds a CRLF,
allso don't know when the last field of the row is written so i can add the
CRLF and put the next row of data into a new line??
Have the problem solved but if any ideas come to mind be a lot of help THX
"Roland Hall" wrote in message
news:OsvDQUvkFHA.3656@TK2MSFTNGP09.phx.gbl...
> "polilop" wrote in message news:%23y91CJnkFHA.708@TK2MSFTNGP10.phx.gbl...
> : Sorry didn't explain the problem well.
> : I have an access db. It has a table with 10 fields all different
> lengths.
> : What i have to do is take the data and write it into a txt file.
> : the 1st field is 15 chars long, 2nd is 10 ........
> : but the thing is that if the data in the first (or any field ) is less
> than
> : the specified length,
> : when i write into the txt file, i have to add to the end of the data
> space
> : characters.
> : eg.
> : first field is "name" its field size is 15 and the data is "Steven"
> : 2nd filed is "surename" field size is 20 and the data is "Henry"
> :
> : in the text file it has to look like this
> : ( ill put _ as space characters)
> : Steven_________Henry_______________
> :
> : Then after i process the first row at the end i have to put CRLF and
> write
> : the next row of data into
> : the new line?
> :
> : The problem with the padding function is that i have to retreive the
> data
> : with
> : a.WriteLine((RsPrijava.Fields.Item("name").Value) .......
> : And cannot give the function the remaining spaces that it has to add, as
> the
> : field lengths are of different sizes.
>
> To add to Tim's suggestion...
>
> function pad(str, length)
> pad = str & space(length - len(str))
> end function
>
> --
> Roland Hall
> /* This information is distributed in the hope that it will be useful, but
> without any warranty; without even the implied warranty of merchantability
> or fitness for a particular purpose. */
> Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
> WSH 5.6 Documentation -
> http://msdn.microsoft.com/downloads/list/webdev.asp
> MSDN Library - http://msdn.microsoft.com/library/default.asp
>
>
Re: Return the whole field length
am 28.07.2005 15:52:49 von Roland Hall
"polilop" wrote in message news:el23OE3kFHA.3568@tk2msftngp13.phx.gbl...
: The pad function helped a lot, and solved my problem
:
: but still trying to find a permanent solution to the problem. This way if
i
: add a new
: field to the db i have to go into the code and add the field (with the pad
: function),
: so i'm trying to see if i can automatically retreve the data, get the real
: length of the field
: defined in the database and subtract it from the data length written and
: then add the space characters
: with the pad function and go through the recordset with:
:
: for each x in rs.Fields
:
: that way i dont have to name the fields, but then after each field the
: writeline function adds a CRLF,
: allso don't know when the last field of the row is written so i can add
the
: CRLF and put the next row of data into a new line??
: Have the problem solved but if any ideas come to mind be a lot of help THX
Posting after my response instead of before it would be helpful.
What is the point of having the field padded with spaces? What will you do
for memo fields or numbers?
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Re: Return the whole field length
am 28.07.2005 16:36:19 von fmatosic
Sorry about posting.
After the txt file is created it is uploaded to another site which reads the
data from the txt file.
It reads the data by its length, so each field has to be that length, so i
have to fill
it with space characters if the field is not that long. I know that it would
be easier if it was delimeted with a tab or something but i didn't do the
spec's or the program on that other server.
So i'm trying to avoid the problem if any new field is added later to the
db, so i
dont have to go back into the code and add that field.
"Roland Hall" wrote in message
news:%23MsNlu3kFHA.3260@TK2MSFTNGP10.phx.gbl...
> "polilop" wrote in message news:el23OE3kFHA.3568@tk2msftngp13.phx.gbl...
> : The pad function helped a lot, and solved my problem
> :
> : but still trying to find a permanent solution to the problem. This way
> if
> i
> : add a new
> : field to the db i have to go into the code and add the field (with the
> pad
> : function),
> : so i'm trying to see if i can automatically retreve the data, get the
> real
> : length of the field
> : defined in the database and subtract it from the data length written and
> : then add the space characters
> : with the pad function and go through the recordset with:
> :
> : for each x in rs.Fields
> :
> : that way i dont have to name the fields, but then after each field the
> : writeline function adds a CRLF,
> : allso don't know when the last field of the row is written so i can add
> the
> : CRLF and put the next row of data into a new line??
> : Have the problem solved but if any ideas come to mind be a lot of help
> THX
>
> Posting after my response instead of before it would be helpful.
>
> What is the point of having the field padded with spaces? What will you
> do
> for memo fields or numbers?
>
> --
> Roland Hall
> /* This information is distributed in the hope that it will be useful, but
> without any warranty; without even the implied warranty of merchantability
> or fitness for a particular purpose. */
> Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
> WSH 5.6 Documentation -
> http://msdn.microsoft.com/downloads/list/webdev.asp
> MSDN Library - http://msdn.microsoft.com/library/default.asp
>
>
Re: Return the whole field length
am 28.07.2005 19:02:44 von Roland Hall
"polilop" wrote in message news:uwFO6G4kFHA.3580@TK2MSFTNGP09.phx.gbl...
: Sorry about posting.
: After the txt file is created it is uploaded to another site which reads
the
: data from the txt file.
: It reads the data by its length, so each field has to be that length, so i
: have to fill
: it with space characters if the field is not that long. I know that it
would
: be easier if it was delimeted with a tab or something but i didn't do the
: spec's or the program on that other server.
: So i'm trying to avoid the problem if any new field is added later to the
: db, so i
: dont have to go back into the code and add that field.
Ok, I'm not sure if this is the correct way to do this but I like this
better than using adoSchema. I'm using the Northwind.mdb file and I'm
iterating all tables and columns and in two of the columns, I'm displaying
the rows. I'm returning the DefinedSize of the fields and with the data,
you get the length and then use the pad function to write to the file. I
haven't written a complete example of exactly what you want but I'm giving
you all you need to get there.
Is there a better way? Perhaps but someone else would have to provide it.
sub lprt(str)
Response.Write str & " " & vbCrLf
end sub
sub SQLConnect()
set conn = CreateObject("ADODB.Connection")
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & db &
";"
conn.open connstr
end sub
sub SQLDisconnect()
conn.Close
set conn = nothing
end sub
Const strPath = "c:\db\"
dim adox, db, oTable, oColumn, conn, connstr, rs, strSQL, arr, row, col
db = "northwind.mdb"
set adox = CreateObject("ADOX.Catalog")
adox.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
strPath & db & ";"
SQLConnect
for each oTable in adox.Tables
prt "
"
next
rs.Close
set rs = nothing
SQLDisconnect
set adox = nothing
%>
HTH...
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Re: Return the whole field length
am 03.08.2005 19:43:43 von fmatosic
Tried this and isn't what i'm looking for, solved my problem with the
padding
function. Thx alot for trying. Need to go on with project.
"Roland Hall" wrote in message
news:uacYtY5kFHA.2852@TK2MSFTNGP14.phx.gbl...
> "polilop" wrote in message news:uwFO6G4kFHA.3580@TK2MSFTNGP09.phx.gbl...
> : Sorry about posting.
> : After the txt file is created it is uploaded to another site which reads
> the
> : data from the txt file.
> : It reads the data by its length, so each field has to be that length, so
> i
> : have to fill
> : it with space characters if the field is not that long. I know that it
> would
> : be easier if it was delimeted with a tab or something but i didn't do
> the
> : spec's or the program on that other server.
> : So i'm trying to avoid the problem if any new field is added later to
> the
> : db, so i
> : dont have to go back into the code and add that field.
>
> Ok, I'm not sure if this is the correct way to do this but I like this
> better than using adoSchema. I'm using the Northwind.mdb file and I'm
> iterating all tables and columns and in two of the columns, I'm displaying
> the rows. I'm returning the DefinedSize of the fields and with the data,
> you get the length and then use the pad function to write to the file. I
> haven't written a complete example of exactly what you want but I'm giving
> you all you need to get there.
>
> Is there a better way? Perhaps but someone else would have to provide it.
>
> Test page: http://kiddanger.com/lab/adoprop.asp
>
> Source:
> <%@ Language=VBScript %>
> <%
> Option Explicit
> Response.Buffer = True
>
> sub prt(str)
> Response.Write str & vbCrLf
> end sub
>
> sub lprt(str)
> Response.Write str & " " & vbCrLf
> end sub
>
> sub SQLConnect()
> set conn = CreateObject("ADODB.Connection")
> connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strPath & db
> &
> ";"
> conn.open connstr
> end sub
>
> sub SQLDisconnect()
> conn.Close
> set conn = nothing
> end sub
>
> Const strPath = "c:\db\"
> dim adox, db, oTable, oColumn, conn, connstr, rs, strSQL, arr, row, col
> db = "northwind.mdb"
> set adox = CreateObject("ADOX.Catalog")
> adox.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
> strPath & db & ";"
>
> SQLConnect
> for each oTable in adox.Tables
> prt ""
> next
>
> rs.Close
> set rs = nothing
> SQLDisconnect
> set adox = nothing
> %>
>
> HTH...
>
> --
> Roland Hall
> /* This information is distributed in the hope that it will be useful, but
> without any warranty; without even the implied warranty of merchantability
> or fitness for a particular purpose. */
> Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
> WSH 5.6 Documentation -
> http://msdn.microsoft.com/downloads/list/webdev.asp
> MSDN Library - http://msdn.microsoft.com/library/default.asp
>
>
Re: Return the whole field length
am 03.08.2005 23:14:59 von Roland Hall
"polilop" wrote in message news:eKSamLFmFHA.2060@tk2msftngp13.phx.gbl...
: Tried this and isn't what i'm looking for, solved my problem with the
: padding
: function. Thx alot for trying. Need to go on with project.
Actually it's exactly what you asked for after you stated the padding
function solved your issue because you wanted something permanent.
Obviously you won't use the exact code but I showed you how to get the field
size even when you add new fields without modifying your ASP code. I just
gave you an example of showing all tables, and then showing all fields
within two of those tables, showing the size of the fields and showing you
all the records and their length so you could see it could be done.
You can also do it with adoSchema but I just prefer doing it this way.
Good luck with your project.
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp