The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Undefined variable
slantt
post 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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
slantt
post Dec 24 2011, 06:11 PM
Post #2


Newbie
*

Group: Members
Posts: 18
Joined: 16-November 11
Member No.: 15,867



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

This post has been edited by slantt: Dec 24 2011, 06:12 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Dec 25 2011, 04:31 PM
Post #3


.
********

Group: WDG Moderators
Posts: 6,050
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? unsure.gif (mthstr is an item in the array yrstr, which in turn is an item in the array yrs.)


--------------------
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
slantt
post Dec 25 2011, 05:45 PM
Post #4


Newbie
*

Group: Members
Posts: 18
Joined: 16-November 11
Member No.: 15,867



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? unsure.gif (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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 20th September 2014 - 09:02 PM