Page 1 of 2 12>
Topic Options
#168223 - 2006-09-21 10:14 PM KiXtart Learning Series - Lesson 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
In response to this post I've come up with a very mini challenge
OT (off)/ OT (on) : Golfing / Minigolf
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=168388

    RULES
  • No KiXtart.org Moderators or Administrators aside from myself are allowed to post in this thread.
  • (This is for those with less experience to learn, not for bored, experienced users to bump their post count)
  • (If you're able to easily do this task then please don't participate with any solutions)
  • (If the task is too easy then I'll increase the difficulty level next time)
  • No using IM,PM or Google to locate/find an answer (you're on the honor system here).


Objective: Check if registry key contains an expected value of "Enterprise Terminal Server"

Using REGEDIT.EXE create the key Golfing under HKEY_CURRENT_USER\Software
Then under the new Golfing key create a new Multi-String Value named Round1 and
enter the following value.
Enterprise {press enter key}
Terminal {press enter key}
Server {press enter key}

Now using KiXtart check if that value exists or not.

DO NOT Post any solution for this though until Friday, Sep 22

Top
#168224 - 2006-09-22 12:57 AM Re: Mini-Golf Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
For those that want an easy method to create the key I've provided
a .REG file you can download and run to create the key for this objective.

Download golfing.reg

Top
#168225 - 2006-09-22 02:18 AM Re: Mini-Golf Round 01
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Doc,
Could you clarify, do you want this as a code snippet or a function?
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#168226 - 2006-09-22 02:31 AM Re: Mini-Golf Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Just a script method is fine. Does not need to be a UDF.

Want to see if the user knows how to do it.

I agree with Gargoyle that it might be nice to at least briefly explain what your code is doing or what you "think" your code is doing so that if needed it can be critiqued.

I'm in no way wanting to slam anyone for their code or explanation. Just want to help others to get better at scripting overall.

Top
#168227 - 2006-09-22 10:16 AM Re: Mini-Golf Round 01
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
When are we ok'ed to post timewise? it's friday, and I think I've got it
Top
#168228 - 2006-09-22 05:03 PM Re: Mini-Golf Round 01
PaulyT Offline
Fresh Scripter
*****

Registered: 2005-08-24
Posts: 8
Loc: Madtown Wisco
I am ready too! When please? Ready set go...
Top
#168229 - 2006-09-22 05:09 PM Re: Mini-Golf Round 01
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Mine is ready as well...
Top
#168230 - 2006-09-22 07:00 PM Re: Mini-Golf Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Please post your solutions now. Thanks.

I may be away from the computer for a bit but will respond soon.

Top
#168231 - 2006-09-22 07:12 PM Re: Mini-Golf Round 01
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Code:

Dim $SO,$Re ,$R, $S, $J

;Script Options
$SO=SETOPTION("Explicit", "ON")
$SO=SETOPTION("NoMacrosInStrings", "ON")
$SO=SETOPTION("NoVarsInStrings", "ON")
$SO=SETOPTION("WrapAtEOL", "ON")
BREAK ON

;Read the value at the given location
$R = ReadValue("HKCU\Software\Golfing","Round1")

;Split the value as a Reg_Multi will include the | character
$S = Split($R,"|")

;Now take each of the elements and put them back together
;with a space to check the value = what we want

$J = Join($S," ")

;Does it match?
If $J = "Enterprise Terminal Server ";space added at end as the join adds one
    ? "We have a match. The string returned was: " $J
Else
    ? "No match found. The string returned was: " $J
EndIf

;The value of $J was verified by printing out each of the elements of
;$S Array with the following code

/*

For $ = 0 to Ubound($S)
?
$S[$]
Next

*/

;When attempting to do the join, with the optional "count", it did not work.
;I was unable to determine why the following would not work

/*
$J = Join($S," ",Ubound($s)-1)
*/



;To make this more robust one should verify that the value exist first
;then they should read the value type and write a routine to know how the
;expected return is going to be formatted, by no means should the following
;snippet be deemed fully functional, one would need to evaluate the returns
;of the different data types and build the appropriate "CASE" statement for
;that scenario

;Example

/*

If KeyExist("HKCU\Software\Golfing\Round1") = 1
   
$Type = Readtype("HKCU\Software\Golfing","Round1")
   
$R = ReadValue("HKCU\Software\Golfing","Round1")
   
   
Select
        Case $Type = "Reg_Multi_SZ"
            $S = Split($R,"|")
           
$J = Join($S," ")
       
Case $Type = "Reg_SZ"
            $J = $S
        Case 1
           
@Error = 5
   
EndSelect

Else
    Exit 1
EndIf

*/


Top
#168232 - 2006-09-22 07:39 PM Re: Mini-Golf Round 01
PaulyT Offline
Fresh Scripter
*****

Registered: 2005-08-24
Posts: 8
Loc: Madtown Wisco
I had two solutions.

Solution 1
Code:

$ = ReadValue('HKCU\Software\Golfing', 'Round1')
Do
$ = SubStr($, 1, InStr($, '|') - 1) + ' ' + SubStr($, InStr($, '|') + 1, Len($))
Until InStr($, '|') = 0
If Rtrim($) = 'Enterprise Terminal Server'
? 'Value Present'
EndIf



Solution 2
Code:
  
$ = Split(ReadValue('HKCU\Software\Golfing', 'Round1'), '|')
For Each $a in $
If InStr('Enterprise Terminal Server', $a) = 0
Exit
EndIf
Next
? 'Value Present'


Top
#168233 - 2006-09-22 10:01 PM Re: Mini-Golf Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Good Gargoyle... top solution works as expected.

Your bottom posted code though does not return a value for me, please review your code so that it provides the expected results.

Top
#168234 - 2006-09-22 10:02 PM Re: Mini-Golf Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Thanks for the solutions Paul, both work as expected.

Though upon reviewing your code I'm not so sure I'd place you in the noobie category.
That's okay though as we progress the task will become more difficult.

I'll post another solution once Bjorn is done unless someone else posts similar code.



Edited by NTDOC (2006-09-22 10:20 PM)

Top
#168235 - 2006-09-22 10:06 PM Re: Mini-Golf Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Okay, waiting for Bjorn to post his.
Top
#168236 - 2006-09-22 10:11 PM Re: Mini-Golf Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Further reading to help learn more about the Registry

Registry
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=81601

Top
#168237 - 2006-09-22 10:51 PM Re: Mini-Golf Round 01
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Well, took some time to get to work again, but here it is, one warning - it's long

Code:

/* Minigolfing 01*/

If NOT @LOGONMODE
Break On
EndIf

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

$key='HKEY_CURRENT_USER\Software\','Golfing','Round1','Enterprise Terminal Server'
;The first two is the key, third is the value, and forth the data we are looking for.

$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
$ch=KeyExist($key[0]) ; Does the HKEY_CURRENT_USER_\Software\ exist?
if $ch ;If it does....
$found=0
$index=0 ;Setting values so the while-statement will not run forever..

while @error=0 and $found=0 ;While no errors and $found is still 0
$ValueName = ENUMKEY($key[0],$index) ;Lists the subkey, $index points to the 'number' in the list
if $ValueName = $Key[1] $found=1 ;If the subkey is the same as the $Key[1] (second val in array), $found is set to 1
$KeyF=$key[0],$ValueName ;make an array out of $Key[0] and $ValueName
$JoinKey=Join($KeyF,'') ;Join 'em together
$wr=ReadValue($JoinKey,$Key[2]) ;Reads the data of value in the key
$split=Split($wr,'|') ;Current format is seperated by '|', therefore remove those
$wr=Join($split,' ') ; and join 'em together
$inst=Instr($wr,$Key[3]) ;Does $wr contain the same as $Key[3] ?
if $inst exit 0 else exit 1 endif ; If it does, exit with a 0, otherwise exit with a 1
else
$Index = $Index + 1 ;$ValueName wasn't the same as $Key[1], continues to look for matches.
endif
loop

exit @error ; In case of an unexpected error comes along, just exit with it (dunno if really needed)

endif

EndFunction


Top
#168238 - 2006-09-22 10:53 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 second piece was not meant to be functional and was never tested. However at your request...

Code:

Dim $Type, $S, $J, $R

If KeyExist("HKCU\Software\Golfing") = 1
   
$Type = Readtype("HKCU\Software\Golfing","Round1")
   
$R = ReadValue("HKCU\Software\Golfing","Round1")
   
   
Select
        Case $Type = "Reg_Multi_SZ"
            $S = Split($R,"|")
           
$J = Join($S," ")
       
Case $Type = "Reg_SZ"
            $J = $R
        Case 1
           
@Error = 5
   
EndSelect
If
$J = "Enterprise Terminal Server ";space added at end as the join adds one
    ? "We have a match. The string returned was: " $J
Else
    ? "No match found. The string returned was: " $J
EndIf


Else
    Exit 1
EndIf


Top
#168239 - 2006-09-22 10:54 PM Re: Mini-Golf Round 01
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Nice going Garg! You acctually added what I was thinking about - what kind of entry it was! I see some similarities in our code
Top
#168240 - 2006-09-22 10:55 PM Re: Mini-Golf Round 01
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
To much time around the likes of Doc and Jooel can do that to you.
Top
#168241 - 2006-09-22 10:58 PM Re: Mini-Golf Round 01
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Well I must say quite an innovative method, did not expect a UDF as such.

The code appears to be operational though.

I have to run for a bit, but will come back and post another solution as well as start some discussion on pros/cons of methods used.

Top
#168242 - 2006-09-22 11:02 PM Re: Mini-Golf Round 01
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Garg - you've got a message!
Doc, well.. urhnm, you know how my 'coding' is

Top
Page 1 of 2 12>


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

Who's Online
1 registered (Allen) and 382 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.075 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org