Undefined variable |
Undefined variable |
slantt |
Dec 24 2011, 06:04 PM
Post
#1
|
Newbie Group: Members Posts: 18 Joined: 16-November 11 Member No.: 15,867 |
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 This post has been edited by slantt: Dec 24 2011, 06:12 PM |
slantt |
Dec 24 2011, 06:11 PM
Post
#2
|
Newbie Group: Members Posts: 18 Joined: 16-November 11 Member No.: 15,867 |
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 This post has been edited by slantt: Dec 24 2011, 06:12 PM |
Christian J |
Dec 25 2011, 04:31 PM
Post
#3
|
. Group: WDG Moderators Posts: 9,656 Joined: 10-August 06 Member No.: 7 |
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.) |
slantt |
Dec 25 2011, 05:45 PM
Post
#4
|
Newbie Group: Members Posts: 18 Joined: 16-November 11 Member No.: 15,867 |
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 |
Lo-Fi Version | Time is now: 25th April 2024 - 06:51 AM |