Page 1 of 1 1
Topic Options
#183312 - 2007-12-05 09:02 PM Collection or Dictionary Object
phatfish Offline
Wasted

Registered: 2007-12-05
Posts: 6
Loc: England
Hi,

I would like to create a Collection or Dictionary Object, the same as used in VB6; and populate it with some data.

Is it possible to create either in a Kixtart script?

Thanks

Top
#183313 - 2007-12-05 09:50 PM Re: Collection or Dictionary Object [Re: phatfish]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
 Code:
Break On
Dim $RC
$RC = SetOption("Explicit", "On")
$RC = SetOption("NoMacrosInStrings", "On")
$RC = SetOption("NoVarsInStrings", "On")
Dim $oDictionary
$oDictionary=CreateObject("Scripting.Dictionary")
;etc

Scripting Runtime Library Dictionary Object


Edited by Witto (2007-12-05 10:19 PM)
Edit Reason: Added link to "Scripting Runtime Library Dictionary Object"

Top
#183316 - 2007-12-05 10:28 PM Re: Collection or Dictionary Object [Re: Witto]
phatfish Offline
Wasted

Registered: 2007-12-05
Posts: 6
Loc: England
Ah, its Scripting.Dictionary (and Scripting.Collection i guess) i wasn't sure what to reference with CreateObject.

Thanks Witto \:\)

Top
#183317 - 2007-12-05 10:36 PM Re: Collection or Dictionary Object [Re: phatfish]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I presume a collection is just an array
Look in the KiXtart v4.60 kix2010.doc at page 22
 Code:
Break On
;Array of four elements
Dim $Array[3]

Top
#183330 - 2007-12-06 10:22 AM Re: Collection or Dictionary Object [Re: Witto]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
 Originally Posted By: Witto
I presume a collection is just an array
Look in the KiXtart v4.60 kix2010.doc at page 22


Not quite. This object is an associative array, sometimes called a hashed or named pair. You can think of it as a very simple database table comprising a single key and a single data field.

This type of array uses an arbitrary key that you define as the index instead of a numeric index, so for example you could do:
 Code:
$asRipeFruitArray["Banana"]="Yellow"
"A ripe banana is "+$asRipeFruitArray["Banana"]+@CRLF


Associative arrays come up for discussion quite regularly.

Top
#183332 - 2007-12-06 10:45 AM Re: Collection or Dictionary Object [Re: Richard H.]
phatfish Offline
Wasted

Registered: 2007-12-05
Posts: 6
Loc: England
Yes Richard, thats what i was looking for. As far as i can tell Kixtart doesn't support associative arrays.

However there is an issue with handling the Dictionary object in Kixtart as described here http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=8&Number=154637
that has meant i cant achieve exactly what i want.

There is a workaround described in that post that i might end up using, but its not ideal.

Top
#183337 - 2007-12-06 12:05 PM Re: Collection or Dictionary Object [Re: phatfish]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Another work-around is to use temporary INI files. Depending on the requirements of your project they can work very well if a bit slower.

You can also use wrapper UDFs to provide associative array functionality on top of plain old arrays. I'm pretty sure I did just that a while back - I'll dig the code out if I get a chance.

Top
#183342 - 2007-12-06 01:23 PM Re: Collection or Dictionary Object [Re: Richard H.]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Just googling a bit. When working with Scripting.Dictionary, don't you create and work with collections?
Top
#183353 - 2007-12-06 05:34 PM Re: Collection or Dictionary Object [Re: Witto]
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
I have already posted a number of UDFs that emulate Perl HASHes. These may be a useful alternative. This code uses KiX arrays. It is slower then using the COM dictionary object.

There are also examples of using the COM dictionary objects. I think I even posted their use as part of a Golf outing.





Edited by Howard Bullock (2007-12-06 05:35 PM)
Edit Reason: spelling
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


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

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.064 seconds in which 0.027 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