#154628 - 2006-01-05 11:28 PM
Scripting.Dictionary troubles
|
PaulG
Lurker
Registered: 2005-12-02
Posts: 3
|
Hello folks,
I got the next code (translated to KiX from the original M$ VBscript page):
Code:
$objDictionary = CreateObject("Scripting.Dictionary") $objDictionary.Add("atl-dc-01", "No status") $objDictionary.Add("atl-dc-02", "No status") $objDictionary.Add("atl-dc-03", "No status")
$colKeys = $objDictionary.Keys For Each $strKey in $colKeys ? $strKey + " " + $objDictionary.Item($strKey) Next
? "==================="
;$objDictionary.Item("atl-dc-01") = "Available" ;$objDictionary.Item("atl-dc-02") = "Available" ;$objDictionary.Item("atl-dc-03") = "Unavailable"
$colKeys = $objDictionary.Keys For Each $strKey in $colKeys ? $strKey + " " + $objDictionary.Item($strKey) Next ??
This works well, but uncomment the 3 lines and run again.... frustrating...
How is it possible? Is an object of this type readonly? The error i got is: Code:
ERROR : unexpected command! Script: D:\Data\Work\Development\Scripts\KIX\dictionary.kix Line : 26 Line 26 is in this example line 10... I got some commentcode above this snippet.
Can someone help me? Thanks...
|
Top
|
|
|
|
#154636 - 2006-01-06 06:08 AM
Re: Scripting.Dictionary troubles
|
Howard Bullock
KiX Supporter
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Try this: Code:
$objDictionary = CreateObject("Scripting.Dictionary")
DictionarySetValue($objDictionary, "atl-dc-01", "No status") DictionarySetValue($objDictionary, "atl-dc-02", "No status") DictionarySetValue($objDictionary, "atl-dc-03", "No status")
$colKeys = $objDictionary.Keys For Each $strKey in $colKeys ? $strKey + " = " + $objDictionary.Item($strKey) Next
? "==================="
DictionarySetValue($objDictionary, "atl-dc-01", "Available") DictionarySetValue($objDictionary, "atl-dc-02", "Available") DictionarySetValue($objDictionary, "atl-dc-03", "Unavailable") DictionarySetValue($objDictionary, "atl-dc-04", "No status")
$colKeys = $objDictionary.Keys For Each $strKey in $colKeys ? $strKey + " " + $objDictionary.Item($strKey) Next ??
function DictionarySetValue($DictionaryObject, $key, $value) if vartypename($DictionaryObject) <> "Object" exit 13 endif if vartypename($key) = "Empty" exit 13 endif
if $DictionaryObject.Exists($key) $DictionaryObject.Remove($key) endif
$DictionaryObject.Add($key, $value) exit @error endfunction
|
Top
|
|
|
|
#154637 - 2006-01-06 08:17 AM
Re: Scripting.Dictionary troubles
|
PaulG
Lurker
Registered: 2005-12-02
Posts: 3
|
Folks,
Many thanks. Jooel gives the answer for me and Howard did the scripting...:) That's nice work.
Strange thing that prop and methods stuff with objects (in KiX I mean). But that is a other discussion.
Thanks. an greetings.
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 718 anonymous users online.
|
|
|