Jump to content

Structures


 Share

Recommended Posts

1- Can the scripting.Dictionnary .key() method return the keys in the order they have been added?

The software I'm currently working on uses Dictionaries, but I need to add duplicate key's, is there another structure I could use instead? Right now I append a number to the duplicated values then remove them, but the way I received the keys(From the keys() method) they are ordered alphabetically so I have to sort them back to their previous order(They dictionary contains function calls...).

Link to comment
Share on other sites

1- Can the scripting.Dictionnary .key() method return the keys in the order they have been added?

The software I'm currently working on uses Dictionaries, but I need to add duplicate key's, is there another structure I could use instead? Right now I append a number to the duplicated values then remove them, but the way I received the keys(From the keys() method) they are ordered alphabetically so I have to sort them back to their previous order(They dictionary contains function calls...).

I don't know much about using dictionaries so my suggestion could be just daft.

Maybe you could do it like this.

If a key is not in dictionary add it with its value. If it is already in the dictionary then add to the next dictioanry or if there isn't one create a new one. So if there are a maximum of N duplicates for any key then you will have N dictionaries. In other words, I am suggesting a variable array of dictionaries and the 5th occurreance of a key (if there is one) will be in dictionary number 5.

EDIT - spelling.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@Zilee: You cannot use duplicate keys in a scripting dictionary object, period. That is part of the definition of the API by Microsoft, not an AutoIt limitation.

You could easily put a wrapper around it that implemented auto-renaming of the key like "KeyName", "KeyName{1}", "KeyName{2}", etc.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Consider switching to a database like SQLite (lookup help file).

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

@Zilee: You cannot use duplicate keys in a scripting dictionary object, period. That is part of the definition of the API by Microsoft, not an AutoIt limitation.

:)

But couldn't you have more than one dictionary as I suggested?
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

But couldn't you have more than one dictionary as I suggested?

Absolutely. I wasn't commenting on your idea, martin. If the dictionary is going to be accessed with wrapper functions anyway though, I think my idea might be slicker.

But it still assumes some unknown reason why a dictionary HAS to be used incorrectly in the first place. Don't really understand the OP's requirement there.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...