| 
| 
| 
| #208058 - 2013-11-26 07:50 PM  Setoption ('Explicit', ON) with execute ("blah blah") |  
| Howard Bullock   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.
 |  
| Top |  |  |  |  
| 
| 
| #208060 - 2013-11-27 03:29 AM  Re: Setoption ('Explicit', ON) with execute ("blah blah")
[Re:  Allen] |  
| Howard Bullock   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.
 |  
| Top |  |  |  |  
| 
| 
| #208070 - 2013-11-27 02:43 PM  Re: Setoption ('Explicit', ON) with execute ("blah blah")
[Re:  Lonkero] |  
| Howard Bullock   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.
 |  
| Top |  |  |  |  
| 
| 
| #208079 - 2013-11-28 06:23 AM  Re: Setoption ('Explicit', ON) with execute ("blah blah")
[Re:  Howard Bullock] |  
| Lonkero   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
 
 
 
;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   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.
 |  
| Top |  |  |  |  
| 
| 
| #208090 - 2013-11-28 11:17 PM  Re: Setoption ('Explicit', ON) with execute ("blah blah")
[Re:  Lonkero] |  
| Howard Bullock   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.
 
   If isdeclared($$$HashKey)
   	$$KeyLimit = Ubound($$$HashKey)
   Else
	$$KeyLimit=-1
   Endif
 Edited by Howard Bullock (2013-11-28 11:18 PM)
 |  
| Top |  |  |  |  
 Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
 
 | 
| 
 
| 0 registered
and 739 anonymous users online. 
 | 
 |  |