Page 1 of 1 1
Topic Options
#123922 - 2004-07-26 05:19 PM function and 2 dimmentional array problem
expodium Offline
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
#123923 - 2004-07-26 05:51 PM Re: function and 2 dimmentional array problem
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
ah yeah,

you need to declare the Array as GLOBAL first

sample:

Code:
break on


global $RegIntValArray[0]

$RegIntValArray[0] = "DA","00000406","DAN","Denmark"

$_ = test()

exit 1

function test()
$test = $RegIntValArray[0][1]
messagebox($test,"array test",0)
endfunction



Edited by Jochen (2004-07-26 05:52 PM)
_________________________



Top
#123924 - 2004-07-26 05:52 PM Re: function and 2 dimmentional array problem
Shawn Administrator Offline
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
#123925 - 2004-07-26 05:53 PM Re: function and 2 dimmentional array problem
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Anyone hear the theme from Twilight Zone playing ? I just did.
Top
#123926 - 2004-07-26 05:53 PM Re: function and 2 dimmentional array problem
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Two characters, one message

Edited by Jochen (2004-07-26 05:55 PM)
_________________________



Top
#123927 - 2004-07-26 05:54 PM Re: function and 2 dimmentional array problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I bet you not talking 2unlimited's twilight zone
_________________________
!

download KiXnet

Top
#123928 - 2004-07-26 06:23 PM Re: function and 2 dimmentional array problem
expodium Offline
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 Offline
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
#123930 - 2004-07-27 02:50 PM Re: function and 2 dimensional array problem
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The $= silences the return code from going to the console. Yes it is better to pass a var as an argument than to make it global.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#123931 - 2004-07-27 02:51 PM Re: function and 2 dimensional array problem
solostyle Offline
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
#123932 - 2004-07-27 03:00 PM Re: function and 2 dimensional array problem
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
this is why I don't like women in power, they have way too many nice thoughts and thus enforce change

solo, your thinking is somewhat correct.
but, bad coding style versus easy scripting, that has been the problem of kixtart for ages.
_________________________
!

download KiXnet

Top
#123933 - 2004-07-27 03:01 PM Re: function and 2 dimensional array problem
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#123934 - 2004-07-27 03:06 PM Re: function and 2 dimensional array problem
solostyle Offline
Fresh Scripter

Registered: 2004-07-20
Posts: 15
Loc: maryland, us
bah!
_________________________
kickin it solo

Top
Page 1 of 1 1


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

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.077 seconds in which 0.034 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