Page 1 of 1 1
Topic Options
#154628 - 2006-01-05 11:28 PM Scripting.Dictionary troubles
PaulG Offline
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
#154629 - 2006-01-05 11:50 PM Re: Scripting.Dictionary troubles
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
the Item is most likely an object.
need to find a ref to it...
_________________________
!

download KiXnet

Top
#154630 - 2006-01-06 12:07 AM Re: Scripting.Dictionary troubles
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep:
http://msdn.microsoft.com/library/en-us/script56/html/8c9581aa-cead-48be-9951-9bc9866c0c55.asp

Item() even though is a property, is a method to kixtart.
and that's all about the bracket () thingies.
those are allowed in function or method but not in properties.

can call this a bug or missing feature but I couldn't find no way around it.
_________________________
!

download KiXnet

Top
#154631 - 2006-01-06 12:11 AM Re: Scripting.Dictionary troubles
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Its a limitation of Kixtart and not a bug. Need to find some kinda object (that has a Value or Text property), so that when you add it to the dictionary and query it back - it returns something you can use, like this:

$objDictionary.Item("atl-dc-01").Value = "Available"

but as it is - cant see anything you can use for that (in scripting anyways)

btw Jooel - this is the very reason I created the DataItem property in kf.net.

Top
#154632 - 2006-01-06 12:33 AM Re: Scripting.Dictionary troubles
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
dataItem?
you not talking about the listItem, the one that doesn't exist in .net?
_________________________
!

download KiXnet

Top
#154633 - 2006-01-06 12:41 AM Re: Scripting.Dictionary troubles
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ja that too. DataItem has a single property called Value and ListItem has two properties Value and Text. Anyways, this is of no use to our friend here - unless you can think of some other std COM Object to steal from.
Top
#154634 - 2006-01-06 01:03 AM Re: Scripting.Dictionary troubles
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, as far as I see it, dictionary is kinda useless for kixtart.
weird...
what's the supposed diff between item() and key()?

they look just the same to me...
_________________________
!

download KiXnet

Top
#154635 - 2006-01-06 01:06 AM Re: Scripting.Dictionary troubles
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
paul, if you really need to use the dictionary object, go with the remove/re-add way.
this is the only usable way with kix.
_________________________
!

download KiXnet

Top
#154636 - 2006-01-06 06:08 AM Re: Scripting.Dictionary troubles
Howard Bullock Offline
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

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#154637 - 2006-01-06 08:17 AM Re: Scripting.Dictionary troubles
PaulG Offline
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
Page 1 of 1 1


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

Who's Online
0 registered and 920 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.032 seconds in which 0.012 seconds were spent on a total of 12 queries. Zlib compression enabled.

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