Page 1 of 1 1
Topic Options
#208058 - 2013-11-26 07:50 PM Setoption ('Explicit', ON) with execute ("blah blah")
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
In reference to my HASH UDF...

http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=208057#Post208057

The code defines and uses variables within an execute statement. When setting Setoption ('Explicit', ON), KiX tags defined variables within the execute statement as undeclared.

I can't wrap my mind around an way to handle this generically. So far I can only set Explicit to OFF.

Can anyone provide insight that may address this issue? The arrays in question need to be global and I defined them that within the UDF. One of my concerns is that each "execute" statement is a script unto itself, yet they need to access these global arrays. Adding Dim to them would seem to isolate the data. Using Global again seem silly.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#208059 - 2013-11-26 11:39 PM Re: Setoption ('Explicit', ON) with execute ("blah blah") [Re: Howard Bullock]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Not really sure how to answer your question... but when I was messing around the Powershell COM thingy... hash tables was one of my examples.... check it out...

Com Interface to Powershell -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=199178#Post199178

Top
#208060 - 2013-11-27 03:29 AM Re: Setoption ('Explicit', ON) with execute ("blah blah") [Re: Allen]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I also previously coded a COM solution using VBscript object "Scripting.Dictionary". The Hash UDFs are just a pure KiX solution for implementing a tied pair of arrays that mimics a hash/associative array.

I am trying to avoid the installation of anything new on the clients.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#208066 - 2013-11-27 02:04 PM Re: Setoption ('Explicit', ON) with execute ("blah blah") [Re: Howard Bullock]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
execute does function as a call would. it does have (at least when I last used it) have access to global vars.
_________________________
!

download KiXnet

Top
#208067 - 2013-11-27 02:09 PM Re: Setoption ('Explicit', ON) with execute ("blah blah") [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
 Code:
global $

$=setoption("explicit","on")

global $myvar
$myvar = 1

$ = execute("$$myvar=$$myvar*3")

"and my var is: " $myvar ?

get $


so, am I not understanding the issue at hand?
_________________________
!

download KiXnet

Top
#208070 - 2013-11-27 02:43 PM Re: Setoption ('Explicit', ON) with execute ("blah blah") [Re: Lonkero]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
The global variable needs to be defined by the HASH() UDF since the global variable is determine. The problem manifests in the support UDFs. In order to test you will need to use the three UDFs together in script using the sample code with explicit=ON.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#208079 - 2013-11-28 06:23 AM Re: Setoption ('Explicit', ON) with execute ("blah blah") [Re: Howard Bullock]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
try this. the del does not work. and naming your vars something more cryptic instead of just $hashkey (aka $colorskey) might be beneficial...

and this code needs to have isdeclared checks also in delete to prevent bogging out if trying to remove from non-existent hash table

 Code:
;Sample code for use
Hash("Colors","Green","Favorite Color")
Hash("Colors","Red","Traffic Ticket")
Hash("Colors","Blue","")
Hash("grass","Green","Good Lawn")

? "Green grass= " + Hash("grass","Green")
? Hash("Colors","Green")
? Hash("Colors","Red")
? "Now delete key for hash=Colors, key=Green"
DelHashKey("Colors","Green")
? "Red Color= " + Hash("Colors","Red")
? "Green Color= " + Hash("Colors","Green")
? "Green grass= " + Hash("grass","Green")
? "Blue Color= " + Hash("Colors","Blue")


get $


;FUNCTION         Hash()
;
;AUTHOR           Howard A. Bullock (habullock@verizon.net)
;
;VERSION          1.1 
;
;DATE             2013-11-24
;
;ACTION           Creates and maintains a set of associatice arrays
;
;SYNTAX           Hash($HashName, $Key, $Value)
;
;PARAMETERS       $HashName (Required) -  String value
;                 $Key (Required) -  String value
;                 $Value (Optional) (0=stop or 1=start or 7=Pause)
;
;REMARKS          This function creates and maintains a pair of arrays and manipulates
;                 in a such that the function yields multiple hashses.
;                 Given the hash name, the function either sets a key and value pair or
;                 returns the value of the specofed hash and key.
;
;RETURNS          Value if no $value is input
;
;DEPENDENCIES
;
;EXAMPLES         Hash("Colors","Green","Favorite Color") Sets a hash value
;                 ? "Green Color= " + Hash("Colors","Green") return a hash value
;
Function Hash($HashName, $Key, optional $Value)
;   Dim $KeyLimit, $key, $found, $x, $y, $rc
   Dim $KeyLimit, $found, $x, $y, $rc
   if not isdeclared($HashKey)
    global $HashKey
   endif
   if not isdeclared($HashValue)
    global $HashValue
   endif
   if not isdeclared($$$HashKey)
    global $$$HashKey[0], $$$HashValue[0]
   endif
   $HashKey = $HashName + "key"
   $HashValue = $HashName + "value"
   $Hash = chr(0)
   $y = '

   $$KeyLimit = Ubound($$$HashKey)

   If VarTypeName($$Value) <> "Empty"
      If $$KeyLimit = -1
         ;Global $$$HashKey[0], $$$HashValue[0]
         $$$HashKey[$$KeyLimit+1] = $$Key
         $$$HashValue[$$KeyLimit+1] = $$Value
      Else
         ; Set a value
         $$found = Ascan($$$HashKey, $$Key)

         If $$found = -1
            Redim Preserve $$$HashKey[$$KeyLimit+1]
            Redim Preserve $$$HashValue[$$KeyLimit+1]
            $$$HashKey[$$KeyLimit+1] = $$Key
            $$$HashValue[$$KeyLimit+1] = $$Value
         Endif
      Endif
   Else
      ; Read a value
      $$found = Ascan($$$HashKey, $$Key)
      If $$found = -1
         $$Hash = "Key ($$Key) Not Defined"
      Else
         $$Hash = $$$HashValue[$$found]
      Endif
   Endif'
   $rc = execute($y)
Endfunction

;FUNCTION         HashKeys()
;
;AUTHOR           Howard A. Bullock (habullock@verizon.net)
;
;VERSION          1.1 
;
;DATE             2013-11-24
;
;ACTION           Creates and maintains a set of associatice arrays
;
;SYNTAX           HashKeys($HashName)
;
;PARAMETERS       $HashName (Required) -  String value
;
;REMARKS          This function returns an array of values that represent keys of
;                 the HASH named $HashName.
;
;RETURNS          Array
;
;DEPENDENCIES
;
;EXAMPLES         $array = HashKeys("Colors")
;
;
Function HashKeys($HashName)
   Dim $Key, $rc, $HashKey
   $HashKey = $HashName + "key"
   $rc = execute("$$HashKeys = $$$HashKey")
Endfunction


;FUNCTION         DelHashKey()
;
;AUTHOR           Howard A. Bullock (habullock@verizon.net)
;
;VERSION          1.1 
;
;DATE             2013-11-24
;
;ACTION           Creates and maintains a set of associatice arrays
;
;SYNTAX           DelHashKey($HashName, $Key)
;
;PARAMETERS       $HashName (Required) -  String value
;                 $Key (Required) -  String value
;
;REMARKS          This function deletes the key/value pair from the hash named $HashName.
;
;RETURNS          Nothing
;
;DEPENDENCIES
;
;EXAMPLES         DelHashKey("Colors","Green")
;
Function DelHashKey($HashName, $Key)
;   Dim $KeyLimit, $Key, $found, $x, $y, $rc
   Dim $KeyLimit, $found, $x, $y, $rc
   $HashKey = $HashName + "key"
   $HashValue = $HashName + "value"
   $Hash = chr(0)
   $y = '
   $$KeyLimit = Ubound($$$HashKey)

   If VarTypeName($$Key) <> "Empty"
      ; Delete a value
      $$found = Ascan($$$HashKey, $$Key)
      For $$x=0 to $$KeyLimit
         If  $$found > -1 and $$x < $$KeyLimit
            $$$Hashkey[$$x] = $$$Hashkey[$$x+1]
            $$$HashValue[$$x] = $$$HashValue[$$x+1]
         Endif
      Next
      If $$found > -1
         Redim Preserve $$$HashKey[$$KeyLimit-1]
         Redim Preserve $$$HashValue[$$KeyLimit-1]
         exit 0
      Else
      	exit 2
      Endif
   Endif'
   $rc = execute($y)
Endfunction
_________________________
!

download KiXnet

Top
#208088 - 2013-11-28 10:42 PM Re: Setoption ('Explicit', ON) with execute ("blah blah") [Re: Lonkero]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Hi Lonk, thanks for taking a look.

The "DelHashKey()" UDF works in the posted UDF.

I can't get your sample code to run yet. The use of a function such as "isdeclared($$$HashKey)" that uses three $'s causes an error outside of the "execute".

ERROR : invalid method/function call: missing ')'!
Script: C:\data\Scripts\Kix\junk2.kix
Line : 58

The variables ($Hashkey, $Hashvalue) do not need to be global and I have added them the Hash "Dim" statement to declare them as locals.

I will look into incorporating isdeclared(), but do not see why it needed.

Yes I agree that the array names used for the function could be made more unique to avoid any naming collision with variable in the balance of the script.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#208090 - 2013-11-28 11:17 PM Re: Setoption ('Explicit', ON) with execute ("blah blah") [Re: Lonkero]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Lonkero, thanks for the suggestion of using "IsDeclared()". After looking at the code a little longer, I added the following to the Hash() UDF which permitted it to run with explicit=on.
 Code:
   If isdeclared($$$HashKey)
   	$$KeyLimit = Ubound($$$HashKey)
   Else
	$$KeyLimit=-1
   Endif


Edited by Howard Bullock (2013-11-28 11:18 PM)
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#208093 - 2013-11-29 05:09 PM Re: Setoption ('Explicit', ON) with execute ("blah blah") [Re: Howard Bullock]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that funny.

I did omit from the start:
 Code:
global $
$=setoption("explicit","on")


but that should not make the code not working. yet, indeed it does. I am not sure why. with explicit on it worked fine.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 793 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.062 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