Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lifecycle of an Array

    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

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Where did you populate the array?
    Maybe you access it before you populated it.

  • #5
    New to the CF scene
    Join Date
    Oct 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •