Sign in to follow this  
Followers 0
MCP

How can I correctly initialize an array?

7 posts in this topic

It is yet not clear to me how an array should be declared and initialized.

Local $my = 'my' 
Local $sApp = $my & '.exe' 
Local $sIni = $my & '.ini' 
Local $sUpdatesExt = 'upd' , _
        $sVersion = FileGetVersion($sApp)
  
Local $aUpdater[2]
$aUpdater['Name'  ] = StringLower($my & '-' & $sVersion & '.' & $sUpdatesExt)
$aUpdater['Version'  ] = $sVersionoÝ÷ Øa¢è!¶+pjÊh²Èëh²Ö«µ«ºÚ"µÍØØ[ ÌÍØU]    ÌÍØU]ÉÌÎNÓ[YIÌÎNÈHHÝ[ÓÝÙ  ÌÍÛ^H    [È ÌÎNËIÌÎNÈ [È ÌÍÜÕÚ[Û   [È ÌÎNËÌÎNÈ  [È ÌÍÜÕ]Ñ^
B   ÌÍØU]ÉÌÎNÕÚ[ÛÌÎNÈHH ÌÍÜÕÚ[ÛoÝ÷ Úȧqëayú%"¬½©bu«­¢+Ù1½°ÀÌØíÍMÑÉ¥¹ôÌäí½¹±Ñݼ±Ñ¡É±½ÕÈÌäì)1½°ÀÌØíÉÉä(ÀÌØíÉÉäôMÑÉ¥¹MÁ±¥Ð ÀÌØíÍMÑÉ¥¹°Ìäì°Ìäì¤

Is there any place I can look at to learn more on the arrays sintax?

Share this post


Link to post
Share on other sites



It is yet not clear to me how an array should be declared and initialized.

Local $my = 'my' 
Local $sApp = $my & '.exe' 
Local $sIni = $my & '.ini' 
Local $sUpdatesExt = 'upd' , _
        $sVersion = FileGetVersion($sApp)
  
Local $aUpdater[2]
$aUpdater['Name'  ] = StringLower($my & '-' & $sVersion & '.' & $sUpdatesExt)
$aUpdater['Version'  ] = $sVersionoÝ÷ Øa¢è!¶+pjÊh²Èëh²Ö«µ«ºÚ"µÍØØ[ ÌÍØU]    ÌÍØU]ÉÌÎNÓ[YIÌÎNÈHHÝ[ÓÝÙ  ÌÍÛ^H    [È ÌÎNËIÌÎNÈ [È ÌÍÜÕÚ[Û   [È ÌÎNËÌÎNÈ  [È ÌÍÜÕ]Ñ^
B   ÌÍØU]ÉÌÎNÕÚ[ÛÌÎNÈHH ÌÍÜÕÚ[ÛoÝ÷ Úȧqëayú%"¬½©bu«­¢+Ù1½°ÀÌØíÍMÑÉ¥¹ôÌäí½¹±Ñݼ±Ñ¡É±½ÕÈÌäì)1½°ÀÌØíÉÉä(ÀÌØíÉÉäôMÑÉ¥¹MÁ±¥Ð ÀÌØíÍMÑÉ¥¹°Ìäì°Ìäì¤oÝ÷ Ø-êÞj|©§!Ƨ$jÛhæ«j+zíæ«­¬¬²)íkêº^¦¦W¬¡÷(®·¶Ì§µ¬_¢¸§Ø+"«­¬¬~º&Úòx^®¶­sdFÒb33c´'&³%ÓÕ³2ÂrãRÂgV÷C·7G&ærgV÷CµÒÂb33c¶'&³UÒÒ³ÂBÂRÂÂФFÒb33c´w&E³%Õ³EÓÕµ²gV÷CµVÂgV÷C²ÂgV÷C´¦ÒgV÷C²ÂgV÷Cµ&6&BgV÷C²ÂgV÷C´Æ÷V2gV÷CµÒ³CRãCBÂcãcÂ#sRãbÂ3#ãÕФFÒb33cµFW7E³UÒÒ³2ÂÂ7G&æu7ÆBgV÷C´&WĦ6·Ä&ö&'ÄÖ'GgV÷C²ÂgV÷C·ÂgV÷C²Â6÷2ÐoÝ÷ Ø¥²+¢×~éܶ*'~æÊÇ¥~Ú"+bjX¬y©ezW¦z{l¡ö§jºÚÊÚ²øvö¥¹æ®¶­sdFÒb33c¶×'&³SÕ³%Ð ¥ô'&æFÆ6Rb33c¶×'&ÂgV÷C´TÕEgV÷C² ¤gVæ2ô'&æFÆ6R'&Vbb33c¶'&Âb33cµfÇVRÒb33²b33²  f÷"b33c¶&÷rÒFòT&÷VæBb33c¶'&ÃÒ7FW f÷"b33c¶6öÂÒFòT&÷VæBb33c¶'&Ã"Ò7FW b33c¶'&²b33c¶&÷uÕ²b33c¶6öÅÒÒb33cµfÇVP æW@ æW@ ¤VæDgVæ

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

It is yet not clear to me how an array should be declared and initialized.

Is there any place I can look at to learn more on the arrays sintax?

The help file has lots of good information. First things first, though: In AutoIt the indexes are all numeric. Period. Your first two elements will be indexed as [0] and [1]. You can use a variable: [$n]. But you cannot use string names as in your examples with 'Name' and 'Version'. By arbitrarily designating the [0] element as the 'Name' and the [1] element as 'Version', you could declare and initialize the array in one step with:

Dim $aUpdater[2] = [StringLower($my & '-' & $sVersion & '.' & $sUpdatesExt), $sVersion]

Getting the name out will be $aUpdater[0], and the version will be $aUpdater[1].

Now, there is such a thing as a list of string-named items and their values. It's called a scripting.dictionary object, and AutoIt can use the API for it provided by Windows. Perhaps you were already familiar with such arrays from another language and thought AutoIt's internal arrays worked that way, but they don't. The scripting.dictionary in AutoIt comes from an outside object available from the Windows environment.

<_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Examples of correct syntax for initialising arrays from DIM entry in help

Thank you so much, Bowmore.

I do not know how to declare and initialize the array that uses strings as indexes instead of numbers and how to loop it thru to get back the key and the value.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Perhaps you were already familiar with such arrays from another language and thought AutoIt's internal arrays worked that way, but they don't. The scripting.dictionary in AutoIt comes from an outside object available from the Windows environment.

Yes. I thought it was possible to have a function like this:

Func ShowElements(ByRef $aKeyAndValue)
    If Not IsArray($aKeyAndValue) Then Return
    
    For $a In $aKeyAndValue
        MsgBox(0, 'Key: ' & $a, 'Element: ' & $aKeyAndValue[$a])
    Next
EndFunc   ;==>ShowElements

:)

EDIT: It can be compiled but it generates an error at runtime.

<_<

Edited by MCP

Share this post


Link to post
Share on other sites

Yes. I thought it was possible to have a function like this:

Func ShowElements(ByRef $aKeyAndValue)
    If Not IsArray($aKeyAndValue) Then Return
    
    For $a In $aKeyAndValue
        MsgBox(0, 'Key: ' & $a, 'Element: ' & $aKeyAndValue[$a])
    Next
EndFunc   ;==>ShowElementsoÝ÷ Ø@ÈLjvÞr©Wnëb¶§z¶­zƧzºè­«kº{bçhú®¢×¢»h}.q©î±áh¯ò'¶¶Ø^½©nzÆî¶z-¶¢×±N¬Â䱫­¢+Ù¥´ÀÌØíÙÑlÑtôlÅÕ½Ðí=¹ÅÕ½Ðì°ÅÕ½ÐíQݼÅÕ½Ðì°ÅÕ½ÐíQ¡ÉÅÕ½Ðì°ÅÕ½Ðí½ÕÈÅÕ½Ðít)M¡½Ý±µ¹ÑÌ ÀÌØíÙѤ()Õ¹M¡½Ý±µ¹ÑÌ¡   åIÀÌØí-å¹Y±Õ¤(%9½Ð%ÍÉÉä ÀÌØí-å¹Y±Õ¤Q¡¸IÑÕɸ((1½°ÀÌØí¸ôÀ(½ÈÀÌØí%¸ÀÌØí-å¹Y±Õ(5Í   ½à À°Ìäí-äèÌäìµÀìÀÌØí¸°Ìäí±µ¹ÐèÌäìµÀìÀÌØí¤($$ÀÌØí¸¬ôÄ(9áÐ)¹Õ¹ìôôÐíM¡½Ý±µ¹Ñ

<_<


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Now, there is such a thing as a list of string-named items and their values. It's called a scripting.dictionary object, and AutoIt can use the API for it provided by Windows.

Thus, to use an associative array in AutoIt, I could write something like this:

Local $oFTP = ObjCreate("Scripting.Dictionary")
$oFTP.add ('Server', 'my.ftp.site')
$oFTP.add ('UserID', 'myUser')
$oFTP.add ('UserPassword', 'myPassword')
$oFTP.add ('Path', 'myPath')oÝ÷ Ø    ݶ§ºg«j×­êk¢«¶'¬¶¢YhÂ)àjëh×6For $a In $oFTP.Keys ()
    MsgBox(0, $a, $oFTP.Item ($a))
Next

EDIT : A quick link to GaryFrost's post on the Scripting.Dictionary oject

EDIT : Small text fixes.

Thank you so much. HTH other newbies too.

Edited by MCP

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
Sign in to follow this  
Followers 0