Jump to content

AutoIt v3.3.15.3 Beta & maps


lorenz
 Share

Recommended Posts

hi all,

I'm playing around with maps and mostly get them to do what I want 8-)

But there is one point where I'm not sure if what I want to do is supposed to work or not, or if I'm doing something wrong.

Local $map1[]
Local $map2[]

$map2.foo = 0
$map2.bar = $map1

$map2.bar.baz = "so far so good"

MsgBox(0, "", $map2.bar.baz & @CRLF & $map2.bar["baz"])

$map2.bar["baz"] = 0

the last line should be equivalent to the line just before the message box.
But after closing the box I get a runtime error

---------------------------
AutoIt Error
---------------------------
Line 11  (File "C:\Users\lenhardt\Desktop\AutoIt v3 Script (neu) (2).au3"):

$map2.bar["baz"] = 0
$map2.bar["baz"] ^ ERROR

Error: Variable must be of type "Object".
---------------------------

Originally I tried

$map2.bar[0] = 1

after that failed, I tried the other variants.

So, is this a bug, or not supposed to work?

 

Lorenz

Link to comment
Share on other sites

You have a choice of syntaxes:

Local $map1[]
Local $map2[]

$map1["what gives?"] = 4
$map2.foo = 5
$map2.bar = $map1

$map2.bar.baz = "so far so good"

MsgBox(0, "", $map2.bar.baz & @CRLF & $map2.bar["baz"])

$map2.bar.baz = 3
$map2.bar.baz *= 3
$map2["bar"]["baz"] *= 10

$map2["bar"]["what gives?"] = -6

vd($map2)

vd() is a homebrew variable dump which yields:

Map[2]
      ['foo']                => Int32              5
      ['bar']                => Map[2]
            ['what gives?']        => Int32              -6
            ['baz']                => Int32              90

 

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

Thanks.

But that confirms my suspicion that their is still a "feature" here 8-)

Because I don't think it's on purpose that $map2.bar["baz"] can be used to access the value of the entry, but not to assign a value to it.


Lorenz

Link to comment
Share on other sites

  • Moderators

lorenz,

It does seem rather strange that only 1 of the 4 syntax options fails on assignment:

#AutoIt3Wrapper_Run_AU3Check=n

Local $map1[]
Local $map2[]

$map2.foo = 0
$map2.bar = $map1


$map2["bar"]["baz"] = "fred"

MsgBox(0, "", $map2.bar.baz & @CRLF & $map2.bar["baz"] & @CRLF & $map2["bar"].baz & @CRLF & $map2["bar"]["baz"])

$map2.bar.baz = "dick"

MsgBox(0, "", $map2.bar.baz & @CRLF & $map2.bar["baz"] & @CRLF & $map2["bar"].baz & @CRLF & $map2["bar"]["baz"])

$map2["bar"].baz = "dora"

MsgBox(0, "", $map2.bar.baz & @CRLF & $map2.bar["baz"] & @CRLF & $map2["bar"].baz & @CRLF & $map2["bar"]["baz"])

$map2.bar["baz"] = "oops"

MsgBox(0, "", $map2.bar.baz & @CRLF & $map2.bar["baz"] & @CRLF & $map2["bar"].baz & @CRLF & $map2["bar"]["baz"])

I will point Jon towards the thread.

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

Aaaaannnd the next "feature" 8-)

Global $mainMap[]

Global $childMap[]
$childMap[0] = "map0"

Global $childArray[] = ["array0"]


$mainMap.map   = $childMap
$mainMap.array = $childArray

MsgBox(0, "", $mainMap.map[0] & @CRLF & $mainMap.array[0])

$mainMap["map"][0]   = "works"

$mainMap["array"][0] = "not"
$mainMap.array[0]    = "neither"

sadly the solution for the sub-map problem does not work for a sub-array.

 

Lorenz

Link to comment
Share on other sites

That's one of the reason why I often recommend against nested arrays, maps or combinations thereof.

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

It looks like the square bracket syntax takes precedence over the dot syntax in the parser.

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

  • Moderators

jchd,

Quote

That's one of the reason why I often recommend against nested arrays, maps or combinations thereof.

I do it a lot - but I always extract the "inner" arrays/maps to a temporary variable before doing anything with them. And especially if I will be changing their content - after which I reassign them to their place in the "container".

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

Yeah but it's clumsy. Often enough other data structures are more efficient and maintainable. Yet there are contexts where such structures are beneficial.

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

20 hours ago, jchd said:

[...] Often enough other data structures are more efficient and maintainable. Yet there are contexts where such structures are beneficial.

That was my thought too when playing around with basic bar graphs. I needed a means to bundle all relevant informations pertaining a graph, so that handling multiple graphs got possible without much hassle ("playing" as in nothing serious, getting to know autoits GUI... functions).

in C, C++, Pascal or other such languages a struct (or class) would have been the prefered solution.
Having used gawk (with its associative arrays, aka maps), I knew maps to be an usable alternative.

I hope maps will mature over time, getting rid of the remaining flaws.

In the meantime I will try M23s workaround (reassigning subarrays/maps after changes)

Lorenz

Edited by lorenz
Link to comment
Share on other sites

Alternatively you can use scripting.dictionary object(s), potentially nested, if you need .

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

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