"Undefined" Error - Newbie question 
Author Message
 "Undefined" Error - Newbie question

I'm writing a JScript script using FSO that is supposed to read a text
comma-delimeted file and then compare each of the records.  I am using
split() to break the data up into arrays and then eventually make each of
those records an object.

The first split() seems to work properly.

    theFile = theContents.split(/\r/);

this separate each line of the file into an array using /\r/ to read for
Carriage returns.

The second split (theContact = theRecord.split(/\,/); Found in the function
contactRecord()) is where I'm having the error.

The message reads ""undefined" is not an object
                                       line# 78 column 2
Line 78 corresponds to the Second split()

Anyone have suggestions?  (please see the code below for more information)

Thanks
Chris Howie

****************************Begin Code***********************************

/*
     This program reads a text comma-delimited file and then does 2 things

 1) Identifies what can be determined to be a large number of duplicate
           records and then separates them into their own text file.

 2) Deletes duplicate records so that only one main record remains.
           At this point, the the choice of which record to retain for
           the remaining database is purely arbitrary.
*/

var fso, f1, f2, f3, f4;
var ForReading = 1;
var ForWriting = 2;
var theContents = "";
var theFile;
var theRecords = new Array();
var thisRecord = " ";
var splitRecord = " ";

fso = new ActiveXObject("Scripting.FileSystemObject");

// Creates file that will contain final product
f1 = fso.CreateTextFile("c:\\finalDataFile.txt", true);
f1.close();

// Reads the raw data for the Parser
f2 = fso.OpenTextFile("c:\\theRawData.csv", ForReading);
theContents = f2.ReadAll();
f2.close();

// Splits the raw data into an array by separating it by Carriage
// Return or \r
theFile = theContents.split(/\r/);

// split each record into record properties
for (l = 0; l < theFile.length; l++);
{
  theRecords[l] = new contactRecord(theFile[l]);

Quote:
}

// Selects record to check for duplicates
for (j = 0; j < theFile.length; j++)
{
  // compares selected record with list for duplicates
  for (k = 0; k < theFile.length; k++)
  {
  }

Quote:
}

f3 = fso.OpenTextFile("c:\\finalDataFile.txt", ForWriting);
for (i = theFile.length; i >= 0; i--)
{  f3.WriteLine(theFile[i] + "\n");

Quote:
}

f3.close();

function contactRecord( theRecord )
{

  var theContact;
  theContact = theRecord.split(/\,/);

  this.company = theContact[0];
  this.contact = theContact[1];
  this.address1 = theContact[2];
  this.address2 = theContact[3];
  this.city = theContact[4];
  this.state = theContact[5];
  this.zip = theContact[6];
  this.phone = theContact[7];
  this.fax = theContact[8];
  this.email = theContact[9];

Quote:
}



Thu, 20 Dec 2001 03:00:00 GMT  
 "Undefined" Error - Newbie question
I think you're just walking off the end of the theFile array

length is 1-based and the indices is 0-based...

// split each record into record properties
for (l = 0; l < theFile.length-1; l++);
{
  theRecords[l] = new contactRecord(theFile[l]);

Quote:
}

--
Michael Harris


| I'm writing a JScript script using FSO that is supposed to read a text
| comma-delimeted file and then compare each of the records.  I am using
| split() to break the data up into arrays and then eventually make each of
| those records an object.
|
| The first split() seems to work properly.
|
|     theFile = theContents.split(/\r/);
|
| this separate each line of the file into an array using /\r/ to read for
| Carriage returns.
|
| The second split (theContact = theRecord.split(/\,/); Found in the function
| contactRecord()) is where I'm having the error.
|
| The message reads ""undefined" is not an object
|                                        line# 78 column 2
| Line 78 corresponds to the Second split()
|
|
| Anyone have suggestions?  (please see the code below for more information)
|
| Thanks
| Chris Howie
|
| ****************************Begin Code***********************************
|
| /*
|      This program reads a text comma-delimited file and then does 2 things
|
|  1) Identifies what can be determined to be a large number of duplicate
|            records and then separates them into their own text file.
|
|  2) Deletes duplicate records so that only one main record remains.
|            At this point, the the choice of which record to retain for
|            the remaining database is purely arbitrary.
| */
|
|
|
| var fso, f1, f2, f3, f4;
| var ForReading = 1;
| var ForWriting = 2;
| var theContents = "";
| var theFile;
| var theRecords = new Array();
| var thisRecord = " ";
| var splitRecord = " ";
|
|
| fso = new ActiveXObject("Scripting.FileSystemObject");
|
| // Creates file that will contain final product
| f1 = fso.CreateTextFile("c:\\finalDataFile.txt", true);
| f1.close();
|
| // Reads the raw data for the Parser
| f2 = fso.OpenTextFile("c:\\theRawData.csv", ForReading);
| theContents = f2.ReadAll();
| f2.close();
|
| // Splits the raw data into an array by separating it by Carriage
| // Return or \r
| theFile = theContents.split(/\r/);
|
| // split each record into record properties
| for (l = 0; l < theFile.length; l++);
| {
|   theRecords[l] = new contactRecord(theFile[l]);
|
| }
|
| // Selects record to check for duplicates
| for (j = 0; j < theFile.length; j++)
| {
|   // compares selected record with list for duplicates
|   for (k = 0; k < theFile.length; k++)
|   {
|   }
| }
|
| f3 = fso.OpenTextFile("c:\\finalDataFile.txt", ForWriting);
| for (i = theFile.length; i >= 0; i--)
| {  f3.WriteLine(theFile[i] + "\n");
| }
|
| f3.close();
|
|
| function contactRecord( theRecord )
| {
|
|   var theContact;
|   theContact = theRecord.split(/\,/);
|
|   this.company = theContact[0];
|   this.contact = theContact[1];
|   this.address1 = theContact[2];
|   this.address2 = theContact[3];
|   this.city = theContact[4];
|   this.state = theContact[5];
|   this.zip = theContact[6];
|   this.phone = theContact[7];
|   this.fax = theContact[8];
|   this.email = theContact[9];
| }
|
|
|



Thu, 20 Dec 2001 03:00:00 GMT  
 "Undefined" Error - Newbie question
That seems to have done the trick!  Thanks a buch.


Quote:
> I think you're just walking off the end of the theFile array

> length is 1-based and the indices is 0-based...

> // split each record into record properties
> for (l = 0; l < theFile.length-1; l++);
> {
>   theRecords[l] = new contactRecord(theFile[l]);

> }

> --
> Michael Harris



> | I'm writing a JScript script using FSO that is supposed to read a text
> | comma-delimeted file and then compare each of the records.  I am using
> | split() to break the data up into arrays and then eventually make each
of
> | those records an object.
> |
> | The first split() seems to work properly.
> |
> |     theFile = theContents.split(/\r/);
> |
> | this separate each line of the file into an array using /\r/ to read for
> | Carriage returns.
> |
> | The second split (theContact = theRecord.split(/\,/); Found in the
function
> | contactRecord()) is where I'm having the error.
> |
> | The message reads ""undefined" is not an object
> |                                        line# 78 column 2
> | Line 78 corresponds to the Second split()
> |
> |
> | Anyone have suggestions?  (please see the code below for more
information)
> |
> | Thanks
> | Chris Howie
> |
> | ****************************Begin

Code***********************************

- Show quoted text -

Quote:
> |
> | /*
> |      This program reads a text comma-delimited file and then does 2
things
> |
> |  1) Identifies what can be determined to be a large number of duplicate
> |            records and then separates them into their own text file.
> |
> |  2) Deletes duplicate records so that only one main record remains.
> |            At this point, the the choice of which record to retain for
> |            the remaining database is purely arbitrary.
> | */
> |
> |
> |
> | var fso, f1, f2, f3, f4;
> | var ForReading = 1;
> | var ForWriting = 2;
> | var theContents = "";
> | var theFile;
> | var theRecords = new Array();
> | var thisRecord = " ";
> | var splitRecord = " ";
> |
> |
> | fso = new ActiveXObject("Scripting.FileSystemObject");
> |
> | // Creates file that will contain final product
> | f1 = fso.CreateTextFile("c:\\finalDataFile.txt", true);
> | f1.close();
> |
> | // Reads the raw data for the Parser
> | f2 = fso.OpenTextFile("c:\\theRawData.csv", ForReading);
> | theContents = f2.ReadAll();
> | f2.close();
> |
> | // Splits the raw data into an array by separating it by Carriage
> | // Return or \r
> | theFile = theContents.split(/\r/);
> |
> | // split each record into record properties
> | for (l = 0; l < theFile.length; l++);
> | {
> |   theRecords[l] = new contactRecord(theFile[l]);
> |
> | }
> |
> | // Selects record to check for duplicates
> | for (j = 0; j < theFile.length; j++)
> | {
> |   // compares selected record with list for duplicates
> |   for (k = 0; k < theFile.length; k++)
> |   {
> |   }
> | }
> |
> | f3 = fso.OpenTextFile("c:\\finalDataFile.txt", ForWriting);
> | for (i = theFile.length; i >= 0; i--)
> | {  f3.WriteLine(theFile[i] + "\n");
> | }
> |
> | f3.close();
> |
> |
> | function contactRecord( theRecord )
> | {
> |
> |   var theContact;
> |   theContact = theRecord.split(/\,/);
> |
> |   this.company = theContact[0];
> |   this.contact = theContact[1];
> |   this.address1 = theContact[2];
> |   this.address2 = theContact[3];
> |   this.city = theContact[4];
> |   this.state = theContact[5];
> |   this.zip = theContact[6];
> |   this.phone = theContact[7];
> |   this.fax = theContact[8];
> |   this.email = theContact[9];
> | }
> |
> |
> |



Thu, 20 Dec 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. usage of undefined and "undefined"

2. XP Pro, Access, "Undefined Error"

3. "undefined" comparison in ASP form

4. FolderItemVerb.Name returns "Undefined"

5. ADO returns "undefined" value

6. showModalDialog returns "undefined" in IE6

7. Disabling "BACK"/"FORWARD" buttons

8. CreateObject("Excel","//server"), MsgBox output

9. Problem With "window.showmodaldialog("")"

10. newbie: the "this"-parameter/div.innerHTML

11. Disabling "BACK"/"FORWARD" buttons

12. Nearly there "Newbie to VBScript"

 

 
Powered by phpBB® Forum Software