Jump to content

Map/Dictionary questions


Recommended Posts

What is the current expert word on creating a dictionary-type object?

I see a lot of references to Maps in the forum, but it seems they've been in beta for many years.  I assume they aren't close to ready yet?

Then I've seen posts that suggest using scripting.dictionary instead.  Which I went ahead and did, and it seemed to work fine.  Until I tried to create a second one, and then flaky things happened.  As in, a _GUICtrlListView_GetItem() call correctly returns the text for one of the ListView items.  Then I call ObjCreate() to create a dictionary (the second one created by the script), add a few values to the dictionary.  Then make the exact same _GUICtrlListView_GetItem() call (literally 6 lines in the script later), and it returns a null string.  So that seems really suspicious.

I found this page in the forum by Jefrey:

which presents a Scripting Dictionary UDF, and specifically says it 'accepts multiple Scripting Dictionary objects around your script'.  Which pretty strongly suggests that, without this, multiple Scripting Dictionary objects are a bad idea.

So:

  1. Is it true that, unenhanced, multiple scripting.dictionary objects are taboo?
  2. Is Jefrey/GaryFrost's UDF pretty generally regarded as a tried-and-true way to have multiple dictionaries?
  3. Is there a better way?

Thanks!

/John

EDIT:  Also have run across Nutster's AssocArray.au3, which looks promising.

Edited by DrJohn
Link to comment
Share on other sites

9 hours ago, DrJohn said:

Is it true that, unenhanced, multiple scripting.dictionary objects are taboo?

Not that I'm aware of

Quote

Is Jefrey/GaryFrost's UDF pretty generally regarded as a tried-and-true way to have multiple dictionaries?

Can't say because I haven't used it

Quote

Is there a better way?

There's a new beta version out that has fixed several of the known issues related to the maps feature, so you could always give that a try.

Quote

Then I've seen posts that suggest using scripting.dictionary instead.  Which I went ahead and did, and it seemed to work fine.  Until I tried to create a second one, and then flaky things happened.

Can you reproduce this behavior in a short script that you could post here?

Link to comment
Share on other sites

5 hours ago, Danp2 said:

Not that I'm aware of

Well I wouldn't have thought so either, but for the fact that Jefrey's post rather suggested it.

5 hours ago, Danp2 said:

Can't say because I haven't used it

I thought maybe it might have a well-known reputation for being the bomb.

In any case, I tried it, and it didn't solve the problem I was having (see below).

5 hours ago, Danp2 said:

There's a new beta version out that has fixed several of the known issues related to the maps feature, so you could always give that a try.

I'd be interested to see how it looks.  But for developing something I hope to use, I wouldn't want to rely on a beta version.

I re-implemented using Nutster's AssocArray UDF, and it seems to work pretty swimmingly.

5 hours ago, Danp2 said:

Can you reproduce this behavior in a short script that you could post here?

So it turned out, I think, that the problem wasn't that I was creating a second scripting dictionary, per se.  The problem seems to be that one of the items I put into the dictionary is the window handle of the very ListView that I'm subsequently trying to do the _GUICtrlListView_GetItem() call on.

On my machine, the problem is reproduced in this code:

#include <GUIConstantsEx.au3>
#include <GuiListView.au3>


CreateMainGUI()


func CreateMainGUI()

    $gui = GUICreate("Test", 600, 600, -1, -1)
    GUISetState(@SW_SHOW, $gui)

    $lv = _GUICtrlListView_Create($gui, "", 100, 100, 400, 200)
    _GUICtrlListView_InsertColumn($lv, 0, "Window Title", 200)
    _GUICtrlListView_InsertColumn($lv, 1, "Class", 200)
    _GUICtrlListView_AddItem($lv, "Foo", 0)
    _GUICtrlListView_AddSubItem($lv, 0, "foo", 1)
    _GUICtrlListView_AddItem($lv, "Bar", 1)
    _GUICtrlListView_AddSubItem($lv, 1, "bar", 1)

    $b = GUICtrlCreateButton("OK", 120, 400, 50, 30)

    while True
        $msg = GuiGetMsg()
        select

            case ($msg = $b)
                $s = _GUICtrlListView_GetItem($lv, 0)[3]
                MsgBox(64, "Test", "ListView item has text " & StringFormat("[%s]", $s))
                $d = ObjCreate('scripting.dictionary')
                $d.Add("x", 42)
                $d.Add("y", $lv)
                $d.Add("z", "qux")
                $s = _GUICtrlListView_GetItem($lv, 0)[3]
                MsgBox(64, "Test", "ListView item has text " & StringFormat("[%s]", $s))

            case ($msg = $GUI_EVENT_CLOSE)
                exitloop

        endselect
    wend

    GUIDelete()

endfunc

The first _GUICtrlListView_GetItem() call properly returns the data from the item ("Foo").  Then I create a scripting dictionary, and one of the items I put in it is $lv, the handle to the ListView.  The subsequent _GUICtrlListView_GetItem() call returns a null string.

If the $d.Add("y", $lv) line is commented out, it works as expected.

Both ListView and scripting.dictionary are sufficiently black boxes to me so that I'd have no good idea why, but it seems fishy.

/John

Edited by DrJohn
Link to comment
Share on other sites

  • Moderators

DrJohn,

Are you working in an x64 environmment? If so then the problem is because the MS scripting dictionary will only accept x32 numeric values, as I found out when trying to rewrite _ArrayUnique function. If you look in that code you will see that I ended up saving x64 values (such as handles) as concatenated "VarGetType & String(Value)" strings and then recreating them as x64 values once the "unique" values were found. Nothing we can do about it - it is a MS design decision.

I have used Nuster's AssocArrays UDF a lot - however, there are still some bugs hidden away inside so be very careful.

But Maps may well be coming to the next full release of AutoIt - Jon has been working hard on them and the current Betas have shown good Map stability. Keep your fingers crossed and you may be lucky!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

2 hours ago, Melba23 said:

Are you working in an x64 environment?

Yes I am.

 

2 hours ago, Melba23 said:

If so then the problem is because the MS scripting dictionary will only accept x32 numeric values, as I found out when trying to rewrite _ArrayUnique function. If you look in that code you will see that I ended up saving x64 values (such as handles) as concatenated "VarGetType & String(Value)" strings and then recreating them as x64 values once the "unique" values were found. Nothing we can do about it - it is a MS design decision.

Wow.  That would have been over my head to figure out.  (As my login name says, I'm a doctor, not a programmer).

It makes sense though.  Thanks!  I appreciate the information.

 

2 hours ago, Melba23 said:

I have used Nuster's AssocArrays UDF a lot - however, there are still some bugs hidden away inside so be very careful.

It's comforting that it should get something of an endorsement from you.  I'll watch out for bugs.  I'm really only using it in the most vanilla ways possible -- literally just putting values into an AssocArray and then looking them up.  Hopefully I'm not stress-testing it too much.

2 hours ago, Melba23 said:

But Maps may well be coming to the next full release of AutoIt - Jon has been working hard on them and the current Betas have shown good Map stability. Keep your fingers crossed and you may be lucky!

I'll be on the lookout.

Thanks all!

/John

Edited by DrJohn
Link to comment
Share on other sites

  • Moderators

DrJohn,

Quote

just putting values into an AssocArray and then looking them up

That should not give you any problems - it was a few of the more esoteric functions that were playing up.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 months later...

I noticed that there is a reference to maps in the AutoIT help file and tried to implement it. It failed at the first hurdle. In the help file it says to set up a map you put something like local $mdata[]

I did this in my script and got the error message

"U:\Documents\.....\Test.au3" (262) : ==> Variable subscript badly formatted.:
Local $LanguageText[]
Local $LanguageText[^ ERROR

Blessings

Link to comment
Share on other sites

Which version of AutoIt do you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...