Jump to content

Recommended Posts

Posted

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)

 

Posted

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

Posted

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

 

Posted

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

Posted

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

  • 3 years later...
Posted

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

 

Posted

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')

Posted

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])

 

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted

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.

Posted

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'])

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted
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

Posted

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!

Posted

I wanted to create a HTML entity replacer. I solved it with a local static and an if-clause:

 

Func 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['&#34;'] = '"'
        $mHTMLEntities['&quot;'] = '"'
        $mHTMLEntities['&amp;'] = '&' ; 38
        $mHTMLEntities['&#39;'] = "'"
        $mHTMLEntities['&gt;'] = '>' ; 62

        $mHTMLEntities['&#160;'] = ' ' ; 160
        $mHTMLEntities['&nbsp;'] = ' ' ; 160
        $mHTMLEntities['&#169;'] = '©'
        $mHTMLEntities['&copy;'] = '©' ; 169
        $mHTMLEntities['&#171;'] = '«' ; 171 Guillemet linksweisend („französisches Anführungszeichen“)
        $mHTMLEntities['&laquo;'] = '«' ; 171 Guillemet linksweisend („französisches Anführungszeichen“)
        $mHTMLEntities['&shy;'] = '­' ; 173 Trennmöglichkeit, weiches Trennzeichen (soft hyphen)

        $mHTMLEntities['&#187;'] = '»' ; 187 Guillemet rechtsweisend („französisches Anführungszeichen“)
        $mHTMLEntities['&raquo;'] = '»' ; 187 Guillemet rechtsweisend („französisches Anführungszeichen“)

        $mHTMLEntities['&Aacute;'] = 'Á' ; 193
        $mHTMLEntities['&Eacute;'] = 'É' ; 201
        $mHTMLEntities['&#233;'] = 'é'

        $mHTMLEntities['&#196;'] = 'Ä'
        $mHTMLEntities['&Auml;'] = 'Ä' ; 196
        $mHTMLEntities['&#214;'] = 'Ö'
        $mHTMLEntities['&Ouml;'] = 'Ö' ; 214

        $mHTMLEntities['&#220;'] = 'Ü'
        $mHTMLEntities['&Uuml;'] = 'Ü' ; 220

        $mHTMLEntities['&#223;'] = 'ß'
        $mHTMLEntities['&szlig;'] = 'ß'
        $mHTMLEntities['&#228;'] = 'ä'
        $mHTMLEntities['&auml;'] = 'ä'
        $mHTMLEntities['&#232;'] = 'è'
        $mHTMLEntities['&#246;'] = 'ö'
        $mHTMLEntities['&ouml;'] = 'ö'
        $mHTMLEntities['&#252;'] = 'ü'
        $mHTMLEntities['&uuml;'] = 'ü'

        $mHTMLEntities['&#305;'] = 'ı' ; Turksprachen, ähnlich 'i'
        $mHTMLEntities['&#351;'] = 'ş' ; Turksprachen, Deutsch: sch

        $mHTMLEntities['&#776;'] = '̈' ; Kombinierendes Trema: macht aus normalen Buchstaben Umlaute

        $mHTMLEntities['&#8201;'] = ' ' ; schmales Leerzeichen
        $mHTMLEntities['&thinsp;'] = ' ' ; 8201 schmales Leerzeichen

        $mHTMLEntities['&#8203;'] = '' ; breitenloses Leerzeichen (Trennmöglichkeit)
        $mHTMLEntities['&#8211;'] = '–' ; 8211 Halbgeviertstrich (Gedankenstrich)
        $mHTMLEntities['&ndash;'] = '–' ; 8211 Halbgeviertstrich (Gedankenstrich)

        $mHTMLEntities['&#8216;'] = '‘' ; einfaches Anführungszeichen (englisch: öffnend, deutsch: schließend)
        $mHTMLEntities['&#8217;'] = '’' ; einfaches Anführungszeichen schließend (englisch); typographisch korrekter Apostroph
        $mHTMLEntities['&#8218;'] = '‚' ; einfaches Anführungszeichen unten (deutsch öffnend)

        $mHTMLEntities['&ldquo;'] = '“' ; 8220
        $mHTMLEntities['&bdquo;'] = '„' ; 8222
        ;&#8232; ???
        $mHTMLEntities['&#8364;'] = '€' ; 8364
        $mHTMLEntities['&euro;'] = '€' ; 8364

        $mHTMLEntities['&#9733;'] = '★' ; 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

 

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
  • Recently Browsing   0 members

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