...

View Full Version : Lifecycle of an Array



Hans-Joerg
10-22-2003, 03:59 PM
Hi,

me problem is, that I want to use an Array to store data on it and use it lateron in serveral functions.
I declared an array like this:

<BODY>
<script language="JavaScript">
<!--
var i = 1 ;
var MeinArray = new Array(100);
//-->
</script>



Lateron I want to use this Array in another function, which I declared in the <HEAD> section.

It looks like:



function sammle(x)
{
var x;
/*document.write("bin drin");*/
document.write(i);

/*MeinArray[i]=x;
document.write(i);
document.write(MeinArray[i]);*/

if ( i == 100 )
{
document.write("HaltStop 100");
}
if ( MeinArray[i] == "Enter" )
{
document.write("Berechne");
}
i++;
}

Now, at runtime I get the answer that "MeinArray" is not definded
in this particlure function.

I knew, that variable must be declared as globol for to use it
in all "places". But I cant find any hint what's about array declarations. Is it possible to use the same array in several functions, whithout losing data?

Best Regards

Hans-Joerg

liorean
10-22-2003, 07:11 PM
It's entirely possible. There SHOULD be no loss of data.
Do you think you could give us a link to the page in question?

scroots
10-22-2003, 08:16 PM
declare the array as the first thing inside your script tags, this will ensure that it is defoned before anything tries to acess it.

as i think you are doing this:

Trying to acess array

defining it

which should be the other way round.


scroots

glenngv
10-23-2003, 04:29 AM
Where did you populate the array?
Maybe you access it before you populated it.

Hans-Joerg
10-23-2003, 08:14 AM
Hi,
thanks for Your time in spending to answers my Question.
With Your Help I found my mistakes. First, the was a logical
error , but the main reason, the script not work is, that I called the array, before I hat assigned it.

Thefore many thanks and
best regards

Hans-Joerg



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum