;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