UnderwareDESIGN

PlayBASIC => Beginners => Topic started by: basil99 on April 02, 2008, 02:33:18 AM

Title: How to make Arrays GLOBAL
Post by: basil99 on April 02, 2008, 02:33:18 AM
Hi !

A bit stuck with it.

Say, I declas Array in the beginning of the prg, like

dim MyArray( ElementsNumber )

Then, I need to make it visible from any Function  and/or Psub, like this

Fuction MyFunc( param )

             ...........

             ; Sample operation
              var1 - Myarray( param )

             .............

EndFunction


Is it possible ?
Title: Re: How to make Arrays GLOBAL
Post by: Adaz on April 02, 2008, 03:03:38 AM
Yes, that array is global because you declared it outside the function.
Title: Re: How to make Arrays GLOBAL
Post by: kevin on April 02, 2008, 09:45:58 AM
 PlayBASIC is top -> down compiler.   Items such as arrays/variables need to be declared prior to their use.  

In this sample the Names$() array is visible to all of the code bellow this declaration.

[pbcode]
   Dim Name$(100)

   SetName(1,"Bill")

Function SetName(Pos,Name$)
   Name$(pos)=Name$
EndFunction

[/pbcode]


In this sample names$() isn't visible and will error.


[pbcode]

Function SetName(Pos,Name$)
   Name$(pos)=Name$
EndFunction


   Dim Name$(100)

   SetName(1,"Bill")


[/pbcode]



More Reading See   HELP -> ABOUT -> PROGRAMLAYOUT (http://playbasic.com/help.php?page=ABOUT.PROGRAMLAYOUT)