Jump to content

Recommended Posts

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)

 

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
5 minutes ago, junkew said:

other types like date

They is not datatype called date


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

@junkew Use strings as keys:

"DD/MM/YY"
"12/02/16" ; Example key

 


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

Did not saw that :P


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

What have you tried so far and didn't work?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (NEW 2019-11-07 - Version 1.3.0.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

 

 


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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

 


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

Share this post


Link to post
Share on other sites

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


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites
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 :)


A cross-platform implementation of the AutoIt language

My contributions to the AutoIt Community ##AutoIt at freenode, real-time chat

3fHNZJ.gif

Spoiler

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) intend to do that to anybody.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
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

×
×
  • Create New...