Page 2 of 2 <12
Topic Options
#168243 - 2006-09-22 11:19 PM Re: Mini-Golf Round 01
PaulyT Offline
Fresh Scripter
*****

Registered: 2005-08-24
Posts: 8
Loc: Madtown Wisco
Appriciate the feed back. I certainly hurt my brain looking at the regular Kix Golf sometimes and the solutions that are created.
Top
#168244 - 2006-09-22 11:27 PM Re: Mini-Golf Round 01
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
You're kidding... Your snippets did the same thing as ours, and how many lines did you use?
Top
#168245 - 2006-09-22 11:34 PM Re: Mini-Golf Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Okay here is another solution as well.

Then let's discuss some of the pros/cons of the coding everyone has posted.


Dim $Key, $Value
$Key = 'HKEY_CURRENT_USER\Software\Golfing'
$Value = ReadValue($Key,'Round1')
If InStr($Value,'Enterprise|Terminal|Server|')
'Found value' ?
Else
'Value not found' ?
EndIf

Top
#168246 - 2006-09-22 11:41 PM Re: Mini-Golf Round 01
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
My first thought is that we all overthought the whole process. In my case I kept thinking about how to ensure that all possible errors were handled.
Top
#168247 - 2006-09-22 11:42 PM Re: Mini-Golf Round 01
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Well - My version looks like a novell, but being a function makes it a bit usefull.. BUT, not happy about how it goes thro the reg. Your versions doesn't lack error-checking tho - so I see no point in using a novell over a fewer lines of code...

Edited by Björn (2006-09-22 11:44 PM)

Top
#168248 - 2006-09-23 12:28 AM Re: KiXtart Learning Series - Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Comments on Gargoyle's code



Dim $SO,$Re ,$R, $S, $J
; Dimming variables is a good practice
; Potential issues:
; A.) No issues in small one off scripts
; B.) In a large script single letter variables can be difficult to manage

$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
$SO=SETOPTION("WrapAtEOL", "ON")
BREAK ON
; Setting options is a good practice
; Most admins would rather not have BREAK ON for a Logon script, using
If Not @LogonMode
Break On
EndIf
; As recently posted, used by Witto would appear to be a good practice as well


; Semi personal preference but single quotes ' would go within double quotes "
; My own preference has been to now use the single for most scripting
; However again this is not necessarilly a Best Practice more so than a preference
; Knowing that single within double is the key point to remeber when coding more
; complex scripts where needed.

$R = ReadValue("HKCU\Software\Golfing","Round1")

$S = Split($R,"|")

$J = Join($S," ")

; Using CHR(20) or similar as needed is another option/choice when dealing with complex scripting


Edited by NTDOC (2006-09-23 12:30 AM)

Top
#168249 - 2006-09-23 12:35 AM Re: KiXtart Learning Series - Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Comments on Paul's code


; No vars declared, not a best practice for production scripting 
; Use of single character vars can be difficult to manage in large scripts
; and scope issues could easily creep in.

$ = ReadValue('HKCU\Software\Golfing', 'Round1')

; Nice use of InStr and SubStr for others to see examples of possible methods
; of locating specific data
Do
$ = SubStr($, 1, InStr($, '|') - 1) + ' ' + SubStr($, InStr($, '|') + 1, Len($))
Until InStr($, '|') = 0
If Rtrim($) = 'Enterprise Terminal Server'
? 'Value Present'
EndIf

Top
#168250 - 2006-09-23 01:02 AM Re: KiXtart Learning Series - Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Comments on Bjorn's code



If NOT @LOGONMODE
Break On
EndIf

Dim $SO,$Key,$wr
$SO = SetOption("Explicit","On")
$SO = SetOption("NoVarsInStrings","On")
$SO = SetOption("NoMacrosInStrings","On")

; Good practice setting the options, including the break on method.


; Minor observation so that other new scripters are aware
; KiXtart can use abbeviations for some of the main Registry keys


;Registry Functions
;All registry functions use the following format to specify registry subkeys:
;[\\remote_computer_name\][Key\]Subkey
;Remote_computer_name can be any valid computer name in UNC format (preceded by two backslashes).
;If you do not specify a remote_computer_name, the program defaults to the local registry.
;Key can be any of the main registry trees: HKEY_LOCAL_MACHINE (or HKLM in short),
;HKEY_USERS (HKU), HKEY_CLASSES_ROOT (HKCR), HKEY_CURRENT_USER (HKCU) or
;HKEY_CURRENT_CONFIG (HKCC). If you do not specify a root key, KiXtart will use
;HKEY_CURRENT_USER as the default.


$key='HKEY_CURRENT_USER\Software\','Golfing','Round1','Enterprise Terminal Server'

; A best practice for a production script would be to use var names that have some
; type of meaning that is easily understood.
$wr=FindMe($key) ; will return a code to @error: 0 for true, and 1 for not true
@error

Function FindMe($key)
Dim $ch,$found,$index,$valuename,$KeyF,$JoinKey,$Valuename2,$wr,$split,$inst

; Using $key[0] is optomistic. If a user missed a comma or similar typo the
; UDF would end abnormally.
; I'd have to think about how best to modify it without completely changing your code.
$ch=KeyExist($key[0]) ; Does the HKEY_CURRENT_USER_\Software\ exist?

; In many cases just an If $var is good enough, but be aware there are times that
; this is not sufficient and could lead to unexpected results.
if $ch

; This is along the lines of the $key[0] issue and you've set it so that there
; is a known value to start with which is good.
$found=0
$index=0 ;Setting values so the while-statement will not run forever..


while @error=0 and $found=0
$ValueName = ENUMKEY($key[0],$index)
if $ValueName = $Key[1] $found=1
; Need to be careful or at least aware of data types when concatenating data
$KeyF=$key[0],$ValueName
$JoinKey=Join($KeyF,'')
$wr=ReadValue($JoinKey,$Key[2])
$split=Split($wr,'|')
$wr=Join($split,' ')
$inst=Instr($wr,$Key[3])
if $inst exit 0 else exit 1 endif
else
$Index = $Index + 1
endif
loop
exit @error
endif

EndFunction

; Overall I'm not comfortable with the calls to array elements without
; some type of prior initialization as it could easily lead to a script abend.

Top
#168251 - 2006-09-23 01:08 AM Re: KiXtart Learning Series - Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
REMINDER: These are My comments and they may not fully agree with other long term / old time scripters.

At this time if other Admins or Moderators or those with a good understanding of KiXtart want to comment please do, but don't post just to bump your post count.

Please be constructive in nature.

Top
#168252 - 2006-09-23 01:29 AM Re: KiXtart Learning Series - Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
And for those who want a Golfed down version here is an example.

Note though that for production scripts they should contain meaningful variable names and perform at least minimal error checking as well as some amount of documentation on what the script is doing.


Code:
 IIF(InStr(ReadValue('HKCU\Software\Golfing','Round1'),'Enterprise|Terminal|Server|'),0,1)     


Top
#168253 - 2006-09-23 03:29 AM Re: KiXtart Learning Series - Round 01
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Using the IIF statement works if you understand the returns to put in. Since you are allowed to put in anything you want, an explanation of why 0 and 1 are used are in order I believe.

The primary reason for bringing this up is that I would have used -1 and 0, and that comes from using KiXforms.

Top
#168254 - 2006-09-23 03:29 AM Re: KiXtart Learning Series - Round 01
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Also would like to see your comments on Section/Solution 2 of my post.
Top
#168255 - 2006-09-23 05:25 AM Re: KiXtart Learning Series - Round 01
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Gargoyle,
I can see what you are saying:

-1 = True
0 = False

I often think that way too but it is probably because I am more familiar with KiXforms.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#168256 - 2006-09-23 05:26 AM Re: KiXtart Learning Series - Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Well I'm sure there are times when -1 is appropriate but in this case we're simply looking for a flag to show that we did not find the value so anything aside from 0 would indicate it was not found.

Comments for your 2nd solution similar to first with regards to using var names with meaning if used in larger script, though not the case here.

Good idea for splitting based upon Reg Type

Here is a method to remove the space from your output check.

$J = Trim(Join($S," "))

Top
#168257 - 2006-09-23 07:58 AM Re: KiXtart Learning Series - Round 01
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Never thought of Trim (then again that is why I am participating here). Any insight on why the Ubound($S)-1 did not work?

My thinking was just grab one less element and all would be good, but it continued to error on me.

Top
#168258 - 2006-09-24 05:25 PM Re: KiXtart Learning Series - Round 01
PaulyT Offline
Fresh Scripter
*****

Registered: 2005-08-24
Posts: 8
Loc: Madtown Wisco
I learned something new! I am a util kix scripter and always trying to find better ways of getting the task done. I was going with that we were to find if 'Enterprise Terminal Server' was present.

Code:

DIM $Round1Value
$Round1Value = Split(ReadValue('HKCU\Software\Golfing', 'Round1'), '|')
? IIF(Trim(Join($Round1Value, ' ',UBound($Round1Value))) = 'Enterprise Terminal Server', 'Value Present', 'Value Not Present')



I like Learning Series better than Mini Golf. Following the principles of best coding practice can only improve beginners and intermediate scripters. I never had used IIF or Join in my production environment, but you know for sure I will review some of my scripts to see if they can be improved. You can teach an old dog new tricks. Good stuff!

Top
#168259 - 2006-09-25 09:10 AM Re: KiXtart Learning Series - Round 01
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Thank you Doc for this - It's really been a learing experience! I'll try to follow your feedback as much as I can!
But to get back to our discussion we had eariler regarding my array's, could you or someone else care to share the real way to handle 'em?

Quote:

I like Learning Series better than Mini Golf. Following the principles of best coding practice can only improve beginners and intermediate scripters. I never had used IIF or Join in my production environment, but you know for sure I will review some of my scripts to see if they can be improved. You can teach an old dog new tricks. Good stuff!




I agree! Never used join nor IIF either

Top
#168260 - 2006-09-26 05:57 AM Re: KiXtart Learning Series - Round 01
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
Quote:

Never used join nor IIF either


Then you should see what wonders a SPLIT-JOIN can do
_________________________
There are two types of vessels, submarines and targets.

Top
Page 2 of 2 <12


Moderator:  NTDOC, ShaneEP, Mart, Radimus, Glenn Barnas, Jochen, Allen 
Hop to:
Shout Box

Who's Online
0 registered and 700 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.126 seconds in which 0.071 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