theycallmebruce
(Lurker)
2005-09-30 03:42 AM
Data structures

In the script I am currently writing, a linked list would be extremely useful. At the moment, I either need to process data twice to calculate the required array size, or continually redim arrays.

Are there any plans for kixtart to provide data structures such as linked lists, and possibly associative arrays?


Richard H.Administrator
(KiX Supporter)
2005-09-30 09:45 AM
Re: Data structures

In most (all?) cases you may use an INI file for associative arrays. I've used them for this in the past, sanitizing keys and data when needed. If your data and keys are simple enough you can use the file directly without any extra coding.

Linked lists are also fairly easy implement with an array:
Code:
Dim $avData[3,x]
; $avData[0,x] = Data
; $avData[1,x] = Reverse pointer
; $avData[2,x] = Forward pointer



I'm not saying that linked lists and associative arrays are not a good suggestion - they are an excellent suggestion - but while we wait for them to appear you can use these work-arounds.


Howard Bullock
(KiX Supporter)
2005-09-30 09:53 PM
Re: Data structures

If you want associate arrays (Hashes in Perl) you can easily use COM to access VBS dictionary objects.

Code:

Object that stores data key, item pairs.

Remarks
A Dictionary object is the equivalent of a PERL associative array. Items can be any form of data, and are stored in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually a integer or a string, but can be anything except an array.

The following code illustrates how to create a Dictionary object:

[VBScript]
Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
d.Add "a", "Athens" ' Add some keys and items.
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
...
Methods
Add Method (Dictionary) | Exists Method | Items Method | Keys Method | Remove Method | RemoveAll Method

Properties
Count Property | Item Property | Key Property

See Also
FileSystemObject Object | TextStream Object



Just convert the VBS syntax to KiXtart.