c.haslam Posted March 19, 2018 Share Posted March 19, 2018 (edited) I was surprised to find that, if a map has no elements, MapKeys() returns an array with no dimensions: Local $map[] Local $mapKeys = MapKeys($map) MsgBox(0,'',UBound($mapKeys,0)&','&UBound($mapKeys,1)) shows 0,0 It would be more logical to me for MapKeys() to return a 1-d array with zero elements. It would then work with For $key in MapKeys($map) ... Next as does a map with elements. Also, to my knowledge this is the only case where a 0-d array can exist in AutoIt. (Correct me if I am wrong.) I also note that the value of @error is 1 for both the argument being an empty map, and for it being a variable or constant other than a map. I do not see why MapKeys() returns @error=1 for a map with no elements, because to me getting the keys in a map with no elements is not necessarily an error. Further, the Help says that on failure MapKeys() returns "a zero based array". As I see it, a 0-d array is not based. Thoughts? I do have a work-around: Local $map[] Local $mapKeys = cMapKeys($map) Func cMapKeys($map) Local $mapKeys = MapKeys($map) If @error Then If IsMap($map) Then Local $mapKeys[0] Else MsgBox(0,'Error','Argument to cMapKeys() is a '&VarGetType($map)) Exit EndIf EndIf Return $mapKeys EndFunc Edited March 19, 2018 by c.haslam Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Bilgus Posted March 19, 2018 Share Posted March 19, 2018 You Must be using the Beta? Link to comment Share on other sites More sharing options...
c.haslam Posted March 19, 2018 Author Share Posted March 19, 2018 Yes. 3.3.15.0 Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
jchd Posted March 20, 2018 Share Posted March 20, 2018 7 hours ago, c.haslam said: Also, to my knowledge this is the only case where a 0-d array can exist in AutoIt. (Correct me if I am wrong.) This isn't a 0D array (that could qualify a flat variable), but a different unicorn: it's a 1D array with zero row. AutoIt allows array dimension(s) to be 0: Local $a[0] is perfectly valid, just like $a[0][3] (a 2D array of zero row of three columns each, or $a[0][2][5] (a 3D array of zero planes of 2 rows by 5 columns). All of this is perfectly sensible, as functions returning an array should return a suitable dimensionned array with zero rows when there is no data to return. That would save extra code in applications and verbiage in help. Unfortunately this possibility is relatively recent and older UDFs do return anything like an empty string or an error in such case, which is plain wrong IMVHO. If you're the only child and someone asks for the number of brothers/sisters you have, you say "zero" or "none" but you never reply "error" or "" (an empty string). mLipok 1 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
iamtheky Posted March 20, 2018 Share Posted March 20, 2018 (edited) what if you are a string and someone asks about the boundaries of your dimensions? $mapKeys = "this is a thing that is not an array" MsgBox(0,'',UBound($mapKeys,0)&','&UBound($mapKeys,1)) I'm not saying zero is an incorrect response, but still debate worthy IM-even humbler-O. Edited March 20, 2018 by iamtheky wordiness ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
c.haslam Posted March 20, 2018 Author Share Posted March 20, 2018 jchd, I think that you are mistaking which is the dimension (number of subscripts) value, so below I have an example using AutoIt $ constants: #include <AutoItConstants.au3> Local $ar2d[5][8] MsgBox(0,'',UBound($ar2d,$UBOUND_DIMENSIONS)&':'&UBound($ar2d,$UBOUND_ROWS)&','&UBound($ar2d,$UBOUND_COLUMNS)); shows 2:5,8 so 5 rows and 8 columns Local $ar1d[3] MsgBox(0,'',UBound($ar1d,$UBOUND_DIMENSIONS)&':'&UBound($ar1d,$UBOUND_ROWS)) ; shows 1:3 so 3 rows Local $map2[] $map2.one = 1 $map2.two = 2 $map2.three = 3 $map2.four = 4 Local $keyAr = MapKeys($map2) MsgBox(0,'',UBound($keyAr,$UBOUND_DIMENSIONS)&':'&UBound($keyAr,$UBOUND_ROWS)) ; shows 1:4 so 4 elements Local $map1[] $map1.one = 1 Local $keyAr = MapKeys($map1) MsgBox(0,'',UBound($keyAr,$UBOUND_DIMENSIONS)&':'&UBound($keyAr,$UBOUND_ROWS)) ; shows 1:1 so 1 element Local $map0[] $keyAr = MapKeys($map0) MsgBox(0,'',UBound($keyAr,$UBOUND_DIMENSIONS)) ; shows 0 so neither rows nor columns I would expect the last example to be: Local $map0[] $keyAr = MapKeys($map0) MsgBox(0,'',UBound($keyAr,$UBOUND_DIMENSIONS)&':'&UBound($keyAr,$UBOUND_ROWS)) ; should show 1:0 so 0 elements Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
jchd Posted March 20, 2018 Share Posted March 20, 2018 I ain't mistaking anything: I never pretended that MapKeys was correct! ConsoleWrite(@LF & "! Array returned by MapKeys" & @LF) Local $map0[] Local $keyAr = MapKeys($map0) ConsoleWrite("MapKeys of empty Map = bug! " & @TAB & VarGetType($keyAr) & @TAB & Ubound($keyAr, 0) & '-D : (' & Ubound($keyAr, 1) & ')' & @LF) ; demonstrates bug of MapKeys: array is ill-formed ReDim $keyAr[3] ConsoleWrite("ReDim [3] of above " & @TAB & VarGetType($keyAr) & @TAB & Ubound($keyAr, 0) & '-D : (' & Ubound($keyAr, 1) & ')' & @LF) ; yet array can de ReDim-ed $map0[17] = "Hello World!" $keyAr = MapKeys($map0) ConsoleWrite("MapKeys of non-empty Map " & @TAB & VarGetType($keyAr) & @TAB & Ubound($keyAr, 0) & '-D : (' & Ubound($keyAr, 1) & ')' & @LF) ; nos bug here: array is correct ; this has to do mith MapKeys only ConsoleWrite(@LF & "+ Declared and ReDim-ed arrays" & @LF) Local $a[0] ConsoleWrite("Local $a[0] " & @TAB & VarGetType($a) & @TAB & Ubound($a, 0) & '-D : (' & Ubound($a, 1) & ')' & @LF) ReDim $a[3] ConsoleWrite("ReDim $a[3] " & @TAB & VarGetType($a) & @TAB & Ubound($a, 0) & '-D : (' & Ubound($a, 1) & ')' & @LF) ReDim $a[0][3] ConsoleWrite("ReDim $a[0][3] " & @TAB & VarGetType($a) & @TAB & Ubound($a, 0) & '-D : (' & Ubound($a, 1) & ', ' & Ubound($a, 2) & ')' & @LF) ; no more bug ReDim $a[2][3] ConsoleWrite("ReDim $a[2][3] " & @TAB & VarGetType($a) & @TAB & Ubound($a, 0) & '-D : (' & Ubound($a, 1) & ', ' & Ubound($a, 2) & ')' & @LF) Local $a[2][3] ConsoleWrite("Local $a[2][3] " & @TAB & VarGetType($a) & @TAB & Ubound($a, 0) & '-D : (' & Ubound($a, 1) & ', ' & Ubound($a, 2) & ')' & @LF) Local $a[0][2][0][3][1][5][0] ConsoleWrite("Local $a[0][2][0][3][1][5][0]" & @TAB & VarGetType($a) & @TAB & Ubound($a, 0) & '-D : (' & Ubound($a, 1)) For $i = 2 To UBound($a, 0) ConsoleWrite(', ' & UBound($a, $i)) Next ConsoleWrite(')' & @LF & @LF) 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
c.haslam Posted March 20, 2018 Author Share Posted March 20, 2018 (edited) We now understand each other: there is a bug in MapKeys. I did not find it in Trac, so should I create a ticket? Edited March 20, 2018 by c.haslam Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 20, 2018 Moderators Share Posted March 20, 2018 c.haslam, As it says in the Beta Help file for all the Map* functions: Warning: This feature is experimental. It may not work, may contain bugs or may be changed or removed without notice.DO NOT REPORT BUGS OR REQUEST NEW FEATURES FOR THIS FEATURE. So please do not. And as I understand it the whole Map datatype is broken and so may be removed a t any time - so do not get too attached to it. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
c.haslam Posted March 20, 2018 Author Share Posted March 20, 2018 M23, OK, I won't create a ticket. I don't see the warning in 3.3.15.0 Help. Perhaps you would tell me where I can find the warning. I looked in Function Reference > Map Management, in the page for each of the Map*() functions, and in Language Reference > Variables. I am only using maps to report their values in my cDebug . I can easily remove this feature. Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 20, 2018 Moderators Share Posted March 20, 2018 c.haslam, Sorry, I am running a pre-release v3.3.15.1 where the warning is in a large red-bordered box at the top of each Map* function page. I have just checked the v3.3.15.0 Help file and you are quite correct - it does not appear there, which I find quite strange as I was sure we had added it. Anyway, it will be in the next Beta release - and my comments above still stand. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
c.haslam Posted March 20, 2018 Author Share Posted March 20, 2018 Thank you for the info. Does 3.3.15.1 fix the bug in MapKeys()? Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
kylomas Posted March 21, 2018 Share Posted March 21, 2018 Since it has warnings about the "bug", probably not! Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
jchd Posted March 21, 2018 Share Posted March 21, 2018 AFAIK there are deeper and more serious issues with the current implementation of Maps, e.g. vanishing entries and such. I'd find it terribly unfortunate if Jon decided to drop Maps as they are a real improvement. 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
c.haslam Posted March 21, 2018 Author Share Posted March 21, 2018 I agree with you 100%: they add much to AutoIt. It must be very hard to determine why entries go missing. Spoiler CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now