Posted by: slantt Dec 24 2011, 06:04 PM
I have a variable that is being flagged as undefined even though I've used it in previous routines in the same way in the same script. The basic script is as follows:
yrix = yrix + 1;
yrstr = yrs[yrix]; // get to a specific place in an array
mthinx = 0;
mthstr = yrstr[mthinx]; // get to a specific place in the picked array
I'm being told yrstr is 'undefined' in the 'mthstr = yrstr[mthinx]' statement.
At entry to this routine yrstr has been used many times. So I thought something going on with yrix. At entry, yrix = 0 and I bump it by one so yrix equals 01, both of which I prove by document.write of the values at entry and after the bump by one. The validator didn't pick up anything . When I run it through MS debugger I'm told yrstr is null or not an object. Interesting thing is if I substitute 01 for yrix in the 'yrstr = yrs[yrix] statement so that yrstr = yrs[01] everything works. And if I set yrix = 1 instead of bumping it it also works fine.
I have a work-around but I'd like to know what caused the undefined error.
Jim
Posted by: slantt Dec 24 2011, 06:11 PM
QUOTE(slantt @ Dec 24 2011, 06:04 PM)
I have a variable that is being flagged as undefined even though I've used it in previous routines in the same way in the same script. The basic script is as follows:
yrix = yrix + 1;
yrstr = yrs[yrix]; // get to a specific place in an array
mthinx = 0;
mthstr = yrstr[mthinx]; // get to a specific place in the picked array
I'm being told yrstr is 'undefined' in the 'mthstr = yrstr[mthinx]' statement.
At entry to this routine yrstr has been used many times. So I thought something going on with yrix. At entry, yrix = 0 and I bump it by one so yrix equals 01, both of which I prove by document.write of the values at entry and after the bump by one. The validator didn't pick up anything . When I run it through MS debugger I'm told yrstr is null or not an object. Interesting thing is if I substitute 01 for yrix in the 'yrstr = yrs[yrix] statement so that yrstr = yrs[01] everything works. And if I set yrix = 1 instead of bumping it it also works fine.
I have a work-around but I'd like to know what caused the undefined error.
script is at www.185talltimbers.info/date-test
Jim
Never mind - I found the problem. When I first set up yrix I turned it into a string value and it was being used the first time after that transfiguration. ooops...my bad..
Jim
Posted by: Christian J Dec 25 2011, 04:31 PM
CODE
yrstr = yrs[yrix]; // get to a specific place in an array
mthstr = yrstr[mthinx]; // get to a specific place in the picked array
This might be true if you're using multi-dimensional (nested) arrays --do you?
(
mthstr is an item in the array
yrstr, which in turn is an item in the array
yrs.)
Posted by: slantt Dec 25 2011, 05:45 PM
QUOTE(Christian J @ Dec 25 2011, 04:31 PM)
CODE
yrstr = yrs[yrix]; // get to a specific place in an array
mthstr = yrstr[mthinx]; // get to a specific place in the picked array
This might be true if you're using multi-dimensional (nested) arrays --do you?
(
mthstr is an item in the array
yrstr, which in turn is an item in the array
yrs.)
Exactly - I have a year array, month array, and a dates of solstice/equinox array all tied together.. Once I got away from using a string variable as an index it all worked.
Jim