Returning a Dictionary

Hello All,

The implementation of Dictionaries in HSLExtensions is really neat and useful. I was wondering if there is a way of returning a Dictionary from a submethod or is it only scoped (very) locally. Just returning the name and checking if it exists after the submethod returns false, indicating the dictionary is scoped to where its being called and not globally.

I’m pretty sure I’m missing something here, especially around handling dictionaries via their name rather than their object. Any ideas what I could do to return a dictionary?


@sgils - Dictionaries in VENUS via HSLExtensions are global, once they have been instantiated, so you don’t need to worry about managing them as a data object (except for the name) via parameters if you are intending to access them in various levels of your method architecture.

Once the dictionary has been created, you should be able to access it in any library or method, regardless of layer, as long as you have access to its name, managed as a string variable. Because dictionaries are default global, I often manage their names as global, or atleast task local depending on the scenario.

When querying whether a dictionary exists (or any function that access a dictionary for that matter), as long as the name variable matches the name of a dictionary that has been instantiated in that run, the function will return hslTrue.

Let me know if you have any other questions!



Thanks @NickHealy_Hamilton!

1 Like

@NickHealy_Hamilton ,

One more question - Can values be Sequences?


@sgils - Unfortunately no, and I have wished for the same functionality in the past. The reason is because in VENUS, dictionary functionality is ultimately a Microsoft scripting object exposed through HSL, and not functionally native to HSL. That is more or less where HSLExtensions gets it’s name, as many of it’s libraries extend the functionality of VENUS by tapping into various Windows features not natively supported by HSL. Because Windows has no idea what a sequence is, they are not a supported item type for dictionaries.

I believe the supported items are variant types integer, float and string.

That being said, you can circumvent these limitations with additional programming if desired. Delimited strings can contain all sorts of nested data schemas (i.e. store sequence data), and still consist of a single string variable. I would suggest checking out this post where much of this is discussed in greater detail.

The base data structure of sequences are composed of individual strings (labware ID and position ID). Using the HSLSeqLib (default) and the String library of HSL extensions, you could write brief helper functions that would parse and store a sequence as a string, which could then be stored in the dictionary. Another helper function would convert the formatted string back into a sequence usable by VENUS. I have totally used this technique in the past.

Similar techniques can be used to store arrays as a delimited string in a dictionary. This is also discussed in the linked post.



Got it, Thank you Nick!

1 Like