#123922 - 2004-07-26 05:19 PM
function and 2 dimmentional array problem
|
expodium
Fresh Scripter
Registered: 2004-07-14
Posts: 35
|
hi,
i have a 2 dim. array and i want to use it in a function but get everytime a error.
when i use the 2 dim array not in a function, its work but when i use it in a function, it dont work. why???
example with 2 dim array in function:
$RegIntValArray[0] = "DA","00000406","DAN","Denmark"
test()
Function test() $test = $RegIntValArray[0][1] MessageBox($test,"array test",0) EndFunction
its give me a error.
example using 2 dim array without a function
$RegIntValArray[0] = "DA","00000406","DAN","Denmark" $test = $RegIntValArray[0][1] MessageBox($test,"array test",0)
its give me 00000406
who can help me?
many thanks in advance
expodium
|
|
Top
|
|
|
|
#123924 - 2004-07-26 05:52 PM
Re: function and 2 dimmentional array problem
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Got to scope your array global, this is a gotcha that gets me everytime too, like this:
Code:
Break On Global $RegIntValArray[0] $RegIntValArray[0] = "DA","00000406","DAN","Denmark" $= test() Function test() $test = $RegIntValArray[0][1] $= MessageBox($test,"array test",0) EndFunction
-Shawn
|
|
Top
|
|
|
|
#123928 - 2004-07-26 06:23 PM
Re: function and 2 dimmentional array problem
|
expodium
Fresh Scripter
Registered: 2004-07-14
Posts: 35
|
many many thanks,
its working 
expodium
|
|
Top
|
|
|
|
#123929 - 2004-07-27 02:40 PM
Re: function and 2 dimensional array problem
|
solostyle
Fresh Scripter
Registered: 2004-07-20
Posts: 15
Loc: maryland, us
|
I don't get $= test(). Or $= MessageBox. Why the $=?
And wouldn't it be better to write a function that stands totally on its own? Like one that takes an array as an argument? That way you don't need globals?
Code:
Break On
;Global $RegIntValArray[0]
$RegIntValArray[0] = "DA","00000406","DAN","Denmark"
$= test($RegIntValArray)
Function test($twoDArray)
$test = $twoDArray[0][1]
$= MessageBox($test,"array test",0)
EndFunction
I would say, as well, to use a variable for [0] and [1] pointers. Just to keep it general.
Edited by solostyle (2004-07-27 02:42 PM)
_________________________
kickin it solo
|
|
Top
|
|
|
|
#123931 - 2004-07-27 02:51 PM
Re: function and 2 dimensional array problem
|
solostyle
Fresh Scripter
Registered: 2004-07-20
Posts: 15
Loc: maryland, us
|
Additionally, I'm reading the kixtart manual, and it says this:
Quote:
$GlobalVariable = 10
if it's the first reference to that variable, it declares it implicitly as a GLOBAL variable, "visible everywhere and in every script during this KiXtart session." When you say:
Quote:
DIM $LocalVariable
then it's a local variable only visible in the current script. Actually this brings up a question: theoretically, it's bad style to do this: Code:
for each $group in $groups ?$group $Message = $Message + " blah" + @crlf next $Message = $Message + " more blah" + @crlf
isn't it? In my opinion, it shouldn't even recognize $Message outside of the for loop. But it does recognize it because $Message is declared implicitly as a Global. This encourages bad style.
Keep on kiXin it solo style!
_________________________
kickin it solo
|
|
Top
|
|
|
|
#123933 - 2004-07-27 03:01 PM
Re: function and 2 dimensional array problem
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Les - You did not plug the FAQ for not showing 1s and 0s! 
Kent
|
|
Top
|
|
|
|
#123934 - 2004-07-27 03:06 PM
Re: function and 2 dimensional array problem
|
solostyle
Fresh Scripter
Registered: 2004-07-20
Posts: 15
Loc: maryland, us
|
bah!
_________________________
kickin it solo
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Henriques)
and 2516 anonymous users online.
|
|
|