Languages ASP / VbScript Object Oriented Programming (OOP)  

Add records to a custom Record Set by Read a Text file (fix length fields)

download download home home  
important code information
Gabriel Garcia
minimum requirements:
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.
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 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 (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
Fieldname = Field(LenFieldname)
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 "" 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:

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.
User reviews

Write a review:
1 2 3 4 5 6 7 8 9 10
1=poor 10=excellent
Write review*
Your name*
  (Comments are moderated, and will not appear on this site until the editor has approved them)
Rate me
supported os
downloads 1828
size in Kb 6
popularity   36784/7916593
user rating 5/10

New Code
Popular Code