Page 1 of 1 1
Topic Options
#141915 - 2005-06-16 10:49 PM Correct use of env variable in kix parameter
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Is this the correct use of a %programfiles% inside the READPROFILESTRING?
Code:
 READPROFILESTRING("%ProgramFiles% + "\visionair\visionrecords\file.ini"","Section","Key") 

_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#141916 - 2005-06-16 10:53 PM Re: Correct use of env variable in kix parameter
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
The quotes are wrong.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#141917 - 2005-06-16 10:53 PM Re: Correct use of env variable in kix parameter
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
This looks better...

Code:

$rc = READPROFILESTRING("%ProgramFiles%\visionair\visionrecords\file.ini","Section","Key")


Top
#141918 - 2005-06-17 01:07 AM Re: Correct use of env variable in kix parameter
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Thanks. When would be an appropriate time to concatenate in a string like this? Would it be when using KiX variables like @USERID?
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#141919 - 2005-06-17 02:59 AM Re: Correct use of env variable in kix parameter
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
It is considered "best practice" for compliance with NoVarsInStrings and NoMacrosInStrings to concatenate, such as...

Code:

$rc = SetOption("NoVarsInStrings","ON")
$rc = SetOption("NoMacrosInStrings","ON")

"This is my USERID: " + @USERID ?

$sWKSTA = "\\" + @WKSTA + "\ADMIN$"
"This is the UNC path to my ADMIN$ Share: " + $sWKSTA ?


Top
#141920 - 2005-06-17 12:28 PM Re: Correct use of env variable in kix parameter
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Tch! No (env) vars in strings:
Code:
$rc = READPROFILESTRING(%ProgramFiles%+"\visionair\visionrecords\file.ini","Section","Key")


Top
#141921 - 2005-06-20 06:02 PM Re: Correct use of env variable in kix parameter
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
If I should not use ENV variables in string, then are you saying I should not use %ProgramFiles% in READPROFILESTRING? All of the examples above are using that ENV variable, although they each have a different permutation of it.

If it is obvious, sorry for being slow. I just want to make sure I understand the correct syntax for KiXtart. Thanks!

(EDIT)After looking the codes over again I see that Richard H. does not have %ProgramFiles% inside the double quotes, but concatenates it outside the quotes with a + sign. So am I correct by observing that ENV variables should not be INSIDE quotes that also include a string of characters??


Edited by StarwarsKid (2005-06-20 06:06 PM)
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#141922 - 2005-06-21 04:37 AM Re: Correct use of env variable in kix parameter
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Ways there are many. To results they all lead
_________________________
There are two types of vessels, submarines and targets.

Top
#141923 - 2005-06-21 04:55 AM Re: Correct use of env variable in kix parameter
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no vars in strings.
you specify strings with quotes.
putting your var outside quotes places them AUTOMATICALLY outside of strings too.
isn't that automatic part wonderfull?

there is also a good reading... think it's called kixtart manual. search for string and manipulation keywords.
_________________________
!

download KiXnet

Top
#141924 - 2005-06-21 10:12 AM Re: Correct use of env variable in kix parameter
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
It is bad practice to place variables in strings, whatever the type of variable.

When we say "in strings", we explicitly mean "in string literals", i.e. something that you have typed in between quote characters (" or '). The variable istelf can be used wherever a string literal would be used - just don't put it inside quotes.

When a variable is not used in a string it is expanded, and the value of the variable is used in the expression. If the variable is in quotes this may or may not happen, depending in the variable value and type.

Some variable types (arrays, objects) simply don't work in strings at all. Undeclared variables will return an empty value when not used in strings, but the variable name will be used as-is when used in strings.

See this example:
Code:
"Undeclared=$Undeclared" ?
"Undeclared="+$Undeclared ?


This displays the following:
Quote:

Undeclared=$Undeclared
Undeclared=




Now, one of those results must be wrong!

Also note, when you are using SetOption("Explicit","ON") undeclared variabled will not be caught if they are present in strings.

Not declaring variables in strings future-proofs your code, and means that other people can use your scripts without changing it.

Variables in strings is not forbidden, and support for it is likely to be around for a while. However if you get into the habit of not placing variables in strings you will write code which is more portable, easier to debug and less prone to odd failures.

Top
#141925 - 2005-06-21 07:23 PM Re: Correct use of env variable in kix parameter
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Hey Lonkero. I think a "bada ching" is in order for that comment. LOL

Geeeez guys, I know about THAT reading. I actually read the part about proper use of characters and how they affect the output. But this thread really helped to clarify how ENV variables or KiXtart macros should be used in code.

Thankful I am. Force the way of learning I am.
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

Top
#141926 - 2005-06-21 07:30 PM Re: Correct use of env variable in kix parameter
StarwarsKid Offline
Seasoned Scripter
*****

Registered: 2005-06-15
Posts: 506
Loc: Oregon, USA
Richard, Now THAT'S a 5 star reply. Thanks for teaching me something new!
_________________________
let the wise listen and add to their learning,
and let the discerning get guidance- Proverbs 1:5

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 996 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.233 seconds in which 0.199 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