Page 1 of 1 1
Topic Options
#61909 - 2002-01-07 01:08 PM Public Array in UDF?
JohnGH Offline
Fresh Scripter

Registered: 2002-01-03
Posts: 27
Hi,

How can I make an array public in a udf?
For example:

code:

;Kixtart.kix
call myfunctions.udf
CreateArray()
UseArray()
;End Kixtart

;myfunctions.udf
Function CreateArray()
Dim $arrGroups[0]
$Index = 0
DO
$Group = ENUMGROUP($Index)
REDIM PRESERVE $arrGroups[$Index]
$arrGroups[$I]=$Group
$Index=$Index+1
UNTIL Len($Group) = 0
;? Ubound($arrGroups)
EndFunction

Function UseArray()
;? Ubound($arrGroups)
For Each $Group In $arrGroups
? "GROUP $Group"
Next
EndFunction


When I enable the Ubound It gives the right number of groups in CreateArray, but it gives 0 in the UseArray.
How can I get this to work?

John

Top
#61910 - 2002-01-07 01:17 PM Re: Public Array in UDF?
Alex.H Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 406
Loc: France
Move Dim $arrGroups[0] to the main part of the script
If a varaible is dimmed in a function, scope of the variable will be limited to the function

code:

;Kixtart.kix
Dim $arrGroups[0]
call myfunctions.udf
CreateArray()
UseArray()
;End Kixtart

_________________________
? getobject(Kixtart.org.Signature)

Top
#61911 - 2002-01-07 02:25 PM Re: Public Array in UDF?
JohnGH Offline
Fresh Scripter

Registered: 2002-01-03
Posts: 27
Doesn't seem to work either.
Ubound returns 0 both times now.

John

Top
#61912 - 2002-01-07 02:49 PM Re: Public Array in UDF?
JohnGH Offline
Fresh Scripter

Registered: 2002-01-03
Posts: 27
Nevermind found the problem.
I didn't know there was a Dim and a Global to define variables. Now using that I'm using the Global it works.

John

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 837 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.053 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org