Click to See Complete Forum and Search --> : What is wrong with my JScript array?


ReddMurphy
02-05-2007, 02:21 PM
Hi,

I am looping through a small recordset using JScript and getting strange results. Here's the relevant code:

Code:


theArray = new Array();
theCount = 0;
while(!rst.EOF){
theArray[theCount] = rst("columnname");
theCount++; rst.MoveNext();
}


I happen to have 5 records in the recordset: "Home", "Search", "Exercises", "Workflow", and "Help".

In my loop, I added some Response.Writes so I could watch the value of each element in the array.
After the first iteration, theArray[0]="Home" as expected.
After the second iteration, both [0] and [1] are set to "Search".
After the third iteration, [0],[1], and [2] are all set to "Exercises" and so on...

I can only assume that I do not understand how arrays work because this seems very simple to me. Perhaps there is some difference between JScript and javascript that is causing my confusion?

Any help is GREATLY appreciated!

Thanks
Reply With Quote

ReddMurphy
02-05-2007, 04:28 PM
Figured it out. I needed a ".Value" added on to my recordset reference like this:


theArray[theCount] = rst("columnname").Value;


I am converting some vbscript code to jscript code. In this loop, I was getting a reference to the recordset object (actually fields.item I think - feel free to correct me), NOT the actual value. This confused me because in vbscript I was passing the actual value without having to specify ".Value".

I hope this helps someone down the road.