The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> 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
 
Reply to this topicStart new topic
Replies
Christian J
post Dec 25 2011, 04:31 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,653
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 #3


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

Posts in this topic


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: 19th April 2024 - 05:48 PM