Add records to a custom Record Set by Read a Text file (fix length fields) description
The purpose of this code is to read a text file and put it into a record set. The code does not depend on DNS and programmer has full control of record set properties.
If you want to read a text file to a record set and you do not want to create
a DNS this code will help you to read it directly by using a custom record set and
a custom record class.
Project items.
1) ADOVBS.inc
2) clsRecord.asp 'Custom class where fields are defined
3) Readme.txt 'This file
4) source.txt 'File to read. The file contain all records and fields are fix length
5) TxtToRS.asp 'This file custom your record set and load text file into it
The code will help you to read a text file to a record set.
To test the code
1) Unzip TxtToRS.zip to a directory of your choice on your server.
2) Edit file TxtToRS.asp and set the Property objRec.Path to the actual path where you
put all files on TxtToRS.zip (this project). This is really a path to your source text file.
3) Open file TxtToRS.asp on internet explorer something like this
If you already test the project and you want to modified code to read your file
follow the steps below.
Edit clsRecord.asp and change the following sections:
1) "Fields variables"
list all fields names on your text file. DO NOT DELETE "CrLf" this will hold the end of line
for each record.
2) "Fields length variables"
list all fields listed on "fields variable section" and add "Len" to the beginning of each variable name.
3) "Set record length"
Set "RecLen" to your record length and add 2 units for crlf
4) "Read one field at a time" list all fields one at a time
example:
Fieldname = Field(LenFieldname)
DO NOT REMOVE THE FOLLOWING LINE
CrLf = Field(LenCrLf) 'End of record
At this point you are done with changes to your record class.
Now you have to customize a Record Set. Follow the steps below
5) Set the following properties
objRec.FileName = "YourSource.txt"
objRec.Path = "C:\PhisicalPathToYourSourceDocument\" include a "\" at the end
6) Custom your Record Set
Add all fields you want on your record set
objRS.fields.append "FieldName", adDouble, objRec.LenFieldName 'Notice that objRec.LenFieldName is the length you
set on your class. The field type is listed on "ADOVBS.inc" file and you can chose any field type you want in
this example the field type is 'adDouble' .
7) Add record to your Record Set. On section commented as "Append record to Record Set"
objRS.addnew array ( "FieldName1", ... , "FieldName2"), _
array(objRec.FieldName1, ... , objRec.FieldName2)
Add as many fields you need. notice that objRec.FieldName1, ... , objRec.FieldName2 are the same fields defined
on your class clsRecord.asp
File List:
@PSC_ReadMe_6872_4.txt
1Kb
TxtToRS/ADOVBS.inc
7Kb
TxtToRS/Readme.txt
3Kb
TxtToRS/TxtToRS.asp
2Kb
TxtToRS/clsRecord.asp
2Kb
TxtToRS/source.txt
1Kb
Similar code
VBScript Calendar Class
(Popularity: ) : VBScript code to create a monthly/yearly calendar. Code is encapsulated in a VB script class to make it easy to use and modify. It is intended to demonstrate the value of using VB script classes by providing basic calendar functionality ... A better BFCTemplate (ver2)
(Popularity: ) : This is a modified version of my original template object. This one allows tags that mimic the <div> tag in HTML. The syntax for the tags is different, so this version isn't compatible with the previous one.