Page 1 of 1 1
Topic Options
#21326 - 2002-05-08 12:23 AM declaring a varialbe inside an IF statement or sub
j95661 Offline
Getting the hang of it

Registered: 2001-02-27
Posts: 84
Loc: sacramento,ca usa
I have looked in the kixstart manual, and Im confused on defining variables.

the manual states that if you implicitly declare a variable

$x =10

It is considered a global variable. Is this true for inside an IF statement or a subroutine. I have not been declaring my varibles inside IF statements for all my scripts...

I know this screams newbie.... I'll admit.
_________________________
WonderBoy Constantly learning everyday, how much I dont know :-)

Top
#21327 - 2002-05-08 12:28 AM Re: declaring a varialbe inside an IF statement or sub
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Master Shawn will be with you momentarily...
Top
#21328 - 2002-05-08 12:33 AM Re: declaring a varialbe inside an IF statement or sub
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
He's working on it I'm sure. Any moment now it should be ready.
Top
#21329 - 2002-05-08 12:34 AM Re: declaring a varialbe inside an IF statement or sub
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Yeah, its true. they're all global. Its not the assignment that makes it global, its the DIMing or lack there-of. But I would suggest you NOT declare vars inside IF statements - i know thats what the manual says you can do, but to be honest, that would confuse the hell out of anybody.

I wouldn't get too worked-up about scope. The only time you should need to consider is with UDF's, just DIM vars local and you should be cool.

-Shawn

p.s. Ron's word is "Hell, I rarely DIM them... I just use them. I'm a bad boy"

[ 08 May 2002, 00:37: Message edited by: Shawn ]

Top
#21330 - 2002-05-08 12:42 AM Re: declaring a varialbe inside an IF statement or sub
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
And Shawn's reply was "ME TOO !"

Best practice is to declare them in the beginning of your code. That way if you start to work with another language you won't pick up bad habits.

Top
#21331 - 2002-05-08 02:07 AM Re: declaring a varialbe inside an IF statement or sub
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Are we supposed to declare variables? [Roll Eyes]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#21332 - 2002-05-08 07:58 AM Re: declaring a varialbe inside an IF statement or sub
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
I win my $5 Shawn [Big Grin] [Big Grin] [Big Grin]
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
0 registered and 507 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.057 seconds in which 0.024 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