Forum Moderators: open

Message Too Old, No Replies

function arrays issue

function arrays

         

adrianbromfield

4:23 pm on Nov 18, 2008 (gmt 0)

10+ Year Member



Hi guys, im having an issues with arrays within a function and for the life of me i cannot understand why, it appears to be fine my loop is running, but as soon as the loop ends i cannot access any of the data within the array. heres my code for the function.


function getImages(pid){
try{
var rsimg;
var counter = 0;
var arrImgs2 = new Array();
var sql = "SELECT * FROM property_image WHERE Property_ID=" + pid;
var cmd = new ActiveXObject("ADODB.Command");
cmd.ActiveConnection = dbConn;
cmd.CommandText = sql;
rsimg = cmd.Execute();
while(!rsimg.EOF){
counter = counter + 1;
arrImgs2[counter] = rsimg("ID");
WScript.Echo(arrImgs2[counter]);
rsimg.MoveNext();
}
WScript.Echo(arrImgs2[1]);
return arrImgs2;
}
catch(e){
WScript.Echo("Error getting images - " + e.name + " " + e.message + ".");
}
}

The line underneath arrImgs2[counter] = rsimg("ID") is to display the data of the array, and as you can see after the while loop ends i have done another one to check the data, the id numbers get put to the screen within the loop but when the one outside the loop tries, it fails.

any help would be really appreciated.

Thanks,

Adrian

daveVk

11:18 pm on Nov 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it fails

What exactly happens ? Does the catch error message occur ?

Try removing try/catch and see what error is reported.

adrianbromfield

10:03 am on Nov 19, 2008 (gmt 0)

10+ Year Member



Hi daveVk, yes sorry the catch message does usually appear, I have just tried it without the try/catch to see if i get a different error but i get the same one which is:
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

And it tells me that this is happening on the line with the echo just after the loop.

adrianbromfield

1:44 pm on Nov 19, 2008 (gmt 0)

10+ Year Member



woohoo ive solved it!..
the line:
arrImgs2[counter] = rsimg("ID");
needs to be written as:
arrImgs2[counter] = String(rsimg("ID"));
or int depending on your needs, just incase anybody else ever has this issue i thought id post the fix.
cheers for the help.

Adrian