junkew Posted February 11, 2016 Share Posted February 11, 2016 this confuses me a little Local $mMap[] $mMap["String"] = "String Map" $mMap[0] = "Integer Map" $mMap[0.1] = "Float Map" $mMap[True] = "Bool Map" MsgBox(0, 0, $mMap["String"] & @CRLF & $mMap[0] & @CRLF & $mMap[0.1] & @CRLF & $mMap[True] & @CRLF) $mMap[01/01/2016] = "?????? Map" MsgBox(0, 0, $mMap["String"] & @CRLF & $mMap[0] & @CRLF & $mMap[0.1] & @CRLF & $mMap[True] & @CRLF & $mMap[01/01/2016] & @CRLF) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
jchd Posted February 11, 2016 Share Posted February 11, 2016 This is expected. Read again the beta help file under Variables > Arrays and Maps: "Maps are better for records/dictionary type access and have a single dimension. They are indexed using either integer or string keys (integers do not refer to the order of elements) and are dynamically resized as values are added or removed. A value can only be accessed by using the original key - these keys can be iterated using the TableKeys function." The important part is in bold here. Since floats aren't valid as keys, a key 0.1 evaluates to integer 0 just as 01/01/2016 since it evaluates as the series of divisions 1 / 1 / 2016 = 1 / 2016 --> 0 Maybe you meant the key '01/01/2016' instead. 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...
junkew Posted February 11, 2016 Share Posted February 11, 2016 ok less confused as its by design. Nice certification questions on paper. What is expected output of below #include <date.au3> Local $mMap[] $mMap["String"] = "String Map" $mMap[0] = "Integer Map" $mMap[0.1] = "Float Map" $mMap[True] = "Bool Map" consolewrite("***** 2,3 or 4 items in the map *****" & @CRLF) consolewrite($mMap["String"] & @CRLF & $mMap[0] & @CRLF & $mMap[0.1] & @CRLF & $mMap[True] & @CRLF) ;- Add n items to the map??? $mMap[01/01/2016] = "?????? Map" $mMap[_now()]= "today" $mMap[_now()+1]= "tomorrow?" consolewrite("***** 2,3,4,5 or 6 items in the map *****" & @CRLF) consolewrite( $mMap["String"] & @CRLF & $mMap[0] & @CRLF & $mMap[0.1] & @CRLF & $mMap[True] & @CRLF & $mMap[01/01/2016] & @CRLF & $mMap[_now()]& @CRLF) consolewrite("***** Just only these keys in the map *****" & @CRLF) For $key In $mMap.keys() consolewrite("Key: " & $key & ";" & "Key type: " & VarGetType($key)& @CRLF) Next consolewrite("***** Just only these items in the map *****" & @CRLF) For $item In $mMap consolewrite("Item: " & $item & @CRLF) Next FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
jchd Posted February 11, 2016 Share Posted February 11, 2016 This is again quite logical: #include <date.au3> Local $mMap[] $mMap["String"] = "String Map" $mMap[0] = "Integer Map" $mMap[0.1] = "Float Map" ; 0.1 as key evaluates to integer 0 hence overwrites $mMap[0] $mMap[True] = "Bool Map" ; True evaluates to 1, so this is $mMap[1] ; only 3 entries consolewrite("***** 2,3 or 4 items in the map *****" & @CRLF) consolewrite($mMap["String"] & @CRLF & $mMap[0] & @CRLF & $mMap[0.1] & @CRLF & $mMap[True] & @CRLF) ;- Add n items to the map??? $mMap[01/01/2016] = "?????? Map" ; 1 / 1 / 2016 evaluates to 0, hence overwrites $mMap[0] $mMap[_now()]= "today" ConsoleWrite(_Now() & @LF) ; this string is the key above $mMap[_now()+1]= "tomorrow?" ; _Now() + 1 evaluates as "12/02/2016 00:48" + 1 ; the string is passed thru Number, which gives integer 12 ; then 12 + 1 = 13 ; so the key above is integer 13 consolewrite("***** 2,3,4,5 or 6 items in the map *****" & @CRLF) consolewrite( $mMap["String"] & @CRLF & $mMap[0] & @CRLF & $mMap[0.1] & @CRLF & $mMap[True] & @CRLF & $mMap[01/01/2016] & @CRLF & $mMap[_now()]& @CRLF) consolewrite("***** Just only these keys in the map *****" & @CRLF) For $key In $mMap.keys() consolewrite("Key: " & $key & ";" & "Key type: " & VarGetType($key)& @CRLF) Next consolewrite("***** Just only these items in the map *****" & @CRLF) For $item In $mMap consolewrite("Item: " & $item & @CRLF) Next 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...
junkew Posted February 12, 2016 Share Posted February 12, 2016 Based on the help file with only support for integer and string key its indeed logical. if you reason from real logic you can argue with doing above that you would have 7 items in the map. On first sight that is what above code shows. Anyway I learned better how maps work in AutoIT feature request on maps: whatever is between [ and ] should be used as a key But for that we probably need other types like date. And for float I can imagine that when doing calculations you get rounding mismatches. And for functions/expressions as key life gets more complicated and $mMap[TRUE] can lead to discussion on how to interpret ("TRUE", TRUE, 1, ..) Certainly for dates I can workaround by transforming to string first FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
TheDcoder Posted February 12, 2016 Share Posted February 12, 2016 5 minutes ago, junkew said: other types like date They is not datatype called date EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
junkew Posted February 12, 2016 Share Posted February 12, 2016 I know that but that would be a nice enhancement also in AutoIT FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
TheDcoder Posted February 12, 2016 Share Posted February 12, 2016 @junkew Use strings as keys: "DD/MM/YY" "12/02/16" ; Example key EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
junkew Posted February 12, 2016 Share Posted February 12, 2016 Quote Certainly for dates I can workaround by transforming to string firs thank you for what I already posted FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
TheDcoder Posted February 12, 2016 Share Posted February 12, 2016 Did not saw that EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
diepfeile Posted May 7, 2019 Share Posted May 7, 2019 How do you create a Const Map? Link to comment Share on other sites More sharing options...
water Posted May 7, 2019 Share Posted May 7, 2019 What have you tried so far and didn't work? 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 More sharing options...
diepfeile Posted May 7, 2019 Share Posted May 7, 2019 Normally I fill them like this: Local $mMap[] $mMap['sdf'] = 234 Have tried all that: ;Const $mMap[] = [['asd',11],['sdf',22]] ;Const $mMap[] = [[1,11],[2,22]] ;Const $mMap[] = [1,2,3] ;Const $mMap[] = 3 Const $mMap[] $mMap['sdf'] = 234 MapAppend($mMap,'asd') Link to comment Share on other sites More sharing options...
iamtheky Posted May 8, 2019 Share Posted May 8, 2019 The syntax necessary for Const makes me think you will always be creating arrays in maps clothing. But is this closer to your goal? Const $mMap[] = ['testmap'] local $m2[] MapAppend($m2 , $mMap) MapAppend($m2 , 'test entry 2') msgbox(0, '' , $mMap[MapKeys($m2)[0]] & @LF & $m2[1]) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
diepfeile Posted May 8, 2019 Share Posted May 8, 2019 Sorry no, it's not closer. This is also not working: Local $mM[] $mM['sdf'] = 234 MapAppend($mM,'asd') MapAppend($mM,'asdf') Const $mMap[] = $mM So I'm out of ideas. Link to comment Share on other sites More sharing options...
iamtheky Posted May 8, 2019 Share Posted May 8, 2019 sure it does, you just dont need the brackets Local $mM[] $mM['sdf'] = 234 MapAppend($mM,'asd') MapAppend($mM,'asdf') Const $mMap = $mM msgbox(0, '' , $mMap['sdf']) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
TheDcoder Posted May 8, 2019 Share Posted May 8, 2019 If anyone has difficulties visualizing maps, my Map UDF has a handy _Map_Display function which displays the contents of a map in a neat GUI Skysnake 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
TheDcoder Posted May 8, 2019 Share Posted May 8, 2019 23 hours ago, diepfeile said: How do you create a Const Map? Good question, I guess a constant map isn't really useful since there is no initialization syntax (as far as I am aware) to set the initial values (which would be constant). But I am pretty sure that your end goal doesn't really demand for constant maps. So it would be better if you could tell us what you are trying to do EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
diepfeile Posted May 10, 2019 Share Posted May 10, 2019 iamtheky way works in theory but not in practice: Func MapToString(Const ByRef $mMap) Local $sString = "Count: " & UBound($mMap) For $vKey In MapKeys($mMap) $sString &= @CRLF & $vKey & ": " & $mMap[$vKey] Next Return $sString EndFunc ;==>MapToString Func TimeStamp($sSeparator = ":") Return @HOUR & $sSeparator & @MIN & $sSeparator & @SEC EndFunc ;==>TimeStamp Func CW($sText) ConsoleWrite(TimeStamp("-") & " " & $sText & @CRLF) EndFunc ;==>CW #cs Func FillMap() Local $mM[] $mM["sdf"] = 234 MapAppend($mM, "asd") MapAppend($mM, "asdf") Return $mM EndFunc ;==>FillMap Global Const $mMap = FillMap() #ce Local $mM[] $mM["sdf"] = 234 MapAppend($mM, "asd") MapAppend($mM, "asdf") Global Const $mMap = $mM CW(MapToString($mMap)) MapAppend($mMap, "no work or does it") CW(MapToString($mMap)) Can still change the map in both cases! Link to comment Share on other sites More sharing options...
diepfeile Posted May 10, 2019 Share Posted May 10, 2019 I wanted to create a HTML entity replacer. I solved it with a local static and an if-clause: expandcollapse popupFunc HTMLDecode(ByRef $sHTML) $aEntities = StringRegExp($sHTML, '&(?>[A-z]+|#\d{2,4});', 3) ;_ArrayDisplay($aEntities,'$aEntities') ;CW('UBound($aEntities) ' & UBound($aEntities) & ' ' & IsArray($aEntities)) If IsArray($aEntities) = False Then Return ; nothing to replace... Local $mDistictEntities[] For $i = 0 To UBound($aEntities) - 1 $mDistictEntities[$aEntities[$i]] += 1 Next ;_ArrayDisplay(MapKeys($mDistictEntities),'MapKeys($mDistictEntities)') ;CW(MapToString($mDistictEntities)) ;FileWrite('HTML Entities.txt', MapToString($mDistictEntities) & @CRLF & @CRLF) Local Static $mHTMLEntities[] ; https://de.wikipedia.org/wiki/Hilfe:Sonderzeichenreferenz If UBound($mHTMLEntities) = 0 Then $mHTMLEntities['"'] = '"' $mHTMLEntities['"'] = '"' $mHTMLEntities['&'] = '&' ; 38 $mHTMLEntities['''] = "'" $mHTMLEntities['>'] = '>' ; 62 $mHTMLEntities[' '] = ' ' ; 160 $mHTMLEntities[' '] = ' ' ; 160 $mHTMLEntities['©'] = '©' $mHTMLEntities['©'] = '©' ; 169 $mHTMLEntities['«'] = '«' ; 171 Guillemet linksweisend („französisches Anführungszeichen“) $mHTMLEntities['«'] = '«' ; 171 Guillemet linksweisend („französisches Anführungszeichen“) $mHTMLEntities['­'] = '' ; 173 Trennmöglichkeit, weiches Trennzeichen (soft hyphen) $mHTMLEntities['»'] = '»' ; 187 Guillemet rechtsweisend („französisches Anführungszeichen“) $mHTMLEntities['»'] = '»' ; 187 Guillemet rechtsweisend („französisches Anführungszeichen“) $mHTMLEntities['Á'] = 'Á' ; 193 $mHTMLEntities['É'] = 'É' ; 201 $mHTMLEntities['é'] = 'é' $mHTMLEntities['Ä'] = 'Ä' $mHTMLEntities['Ä'] = 'Ä' ; 196 $mHTMLEntities['Ö'] = 'Ö' $mHTMLEntities['Ö'] = 'Ö' ; 214 $mHTMLEntities['Ü'] = 'Ü' $mHTMLEntities['Ü'] = 'Ü' ; 220 $mHTMLEntities['ß'] = 'ß' $mHTMLEntities['ß'] = 'ß' $mHTMLEntities['ä'] = 'ä' $mHTMLEntities['ä'] = 'ä' $mHTMLEntities['è'] = 'è' $mHTMLEntities['ö'] = 'ö' $mHTMLEntities['ö'] = 'ö' $mHTMLEntities['ü'] = 'ü' $mHTMLEntities['ü'] = 'ü' $mHTMLEntities['ı'] = 'ı' ; Turksprachen, ähnlich 'i' $mHTMLEntities['ş'] = 'ş' ; Turksprachen, Deutsch: sch $mHTMLEntities['̈'] = '̈' ; Kombinierendes Trema: macht aus normalen Buchstaben Umlaute $mHTMLEntities[' '] = ' ' ; schmales Leerzeichen $mHTMLEntities[' '] = ' ' ; 8201 schmales Leerzeichen $mHTMLEntities['​'] = '' ; breitenloses Leerzeichen (Trennmöglichkeit) $mHTMLEntities['–'] = '–' ; 8211 Halbgeviertstrich (Gedankenstrich) $mHTMLEntities['–'] = '–' ; 8211 Halbgeviertstrich (Gedankenstrich) $mHTMLEntities['‘'] = '‘' ; einfaches Anführungszeichen (englisch: öffnend, deutsch: schließend) $mHTMLEntities['’'] = '’' ; einfaches Anführungszeichen schließend (englisch); typographisch korrekter Apostroph $mHTMLEntities['‚'] = '‚' ; einfaches Anführungszeichen unten (deutsch öffnend) $mHTMLEntities['“'] = '“' ; 8220 $mHTMLEntities['„'] = '„' ; 8222 ;
 ??? $mHTMLEntities['€'] = '€' ; 8364 $mHTMLEntities['€'] = '€' ; 8364 $mHTMLEntities['★'] = '★' ; Schwarzer Stern EndIf For $vKey In MapKeys($mDistictEntities) If MapExists($mHTMLEntities, $vKey) = False Then ClipPut($vKey) MsgBox(0, 'HTML Entity Decode missing!', $vKey) EndIf ;CW($vKey& ' - ' & $mHTMLEntities[$vKey]) $sHTML = StringReplace($sHTML, $vKey, $mHTMLEntities[$vKey], 0, 1) Next EndFunc ;==>HTMLDecode Skysnake 1 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