amokoura Posted April 17, 2007 Posted April 17, 2007 (edited) Hello, I try to use this:Dim $aArray[1][4] = [[0, 1, 2, 3]] FOR $element IN $aArray[0] MsgBox(0, "test", $element ) NEXT But I get error:Array variable has incorrect number of subscripts or subscript dimension range exceeded.: FOR $element IN $aArray[0] FOR $element IN ^ ERROR AutoIt Version 3.2.2.0 If the array was one-dimensional, the problem wouldn't occur. Edited April 17, 2007 by amokoura
BrettF Posted April 17, 2007 Posted April 17, 2007 Hello, I try to use this:Dim $aArray[1][4] = [[0, 1, 2, 3]] FOR $element IN $aArray[0] MsgBox(0, "test", $element ) NEXToÝ÷ Ø"zºèÊx ëk+Ú®&èZ²)Ü¢ºÞrÙî·«¡û.nÇ+l¢».nÇ+]g§²*'©àyìyç^w97éé^éí Ý7é +¬½×Owätß§¥zg§´DEýÊx Uz»"¢}öÛB¶®¶²Á«(çbéìÚØ^¦ºé°¢é]m¡Ç.¯ú®¢×¢ë-YgyçmërÝv)ȨÊ-áNFX§zZ(Ë(ëax%GºÚ"µÍÜ ÌÍÙ[[Y[[ ÌÍØP^VÌWVÍ See if that works and tell us how you go. Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
amokoura Posted April 17, 2007 Author Posted April 17, 2007 (edited) For $element In $aArray[1][4]oÝ÷ Ûú®¢×©ä±»ËbX(¶Ø^±©zºè®È³z쥩ì·)^ Error:E:\AUTOIT\test.au3 (8) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $aTest = $aArray[0] $aTest = ^ ERROR I can't copy the [0,1,2,3]-array to $aTest. Edited April 17, 2007 by amokoura
PsaltyDS Posted April 17, 2007 Posted April 17, 2007 Why are you using a 2D array with only one element in the first dimension? Shouldn't that be: Dim $aArray[4] = [0, 1, 2, 3] FOR $element IN $aArray MsgBox(0, "test", $element ) NEXToÝ÷ Ù8b²+²Ö§uªÝ)Â+ak`Ú®¶²jëh×6$aTest = "" Dim $aArray[2][4] = [[0, 10, 20, 30], [5, 15, 25, 35]] For $a = 0 To 1 For $b = 0 To 3 $aTest &= "[" & $a & "][" & $b & "] = " & $aArray[$a][$b] & @LF Next Next MsgBox(64, "2D Array", $aTest) It doesn't look like For/In/Next accepts a 2D array. More than one dimension requires more than one index, and For/In/Next only creates a single index - so it can only use 1D arrays. At least, that's how it looks to me... 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
amokoura Posted April 17, 2007 Author Posted April 17, 2007 ....It doesn't look like For/In/Next accepts a 2D array....Yes that's how it looks. But still, how can I extract an array from a 2D-array? What's the problem here:$aTest = "" Dim $aArray[1][4] = [[0, 1, 2, 3]] $aTest = $aArray[0]
GaryFrost Posted April 17, 2007 Posted April 17, 2007 Yes that's how it looks. But still, how can I extract an array from a 2D-array? What's the problem here:$aTest = "" Dim $aArray[1][4] = [[0, 1, 2, 3]] $aTest = $aArray[0] SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
amokoura Posted April 17, 2007 Author Posted April 17, 2007 (edited) Dim $aArray[1][4] = [[0, 1, 2, 3]] For $x = 0 To UBound($aArray) - 1 For $y = 0 To UBound($aArray,2) - 1 MsgBox(0,"Test",$aArray[$x][$y],10) Next Next Thanks for the workaround. Was there some bad code in my example or should I create a bug report? From the manual: A unique feature in AutoIt is the ability to copy arrays like this: $mycopy = $myarray Edited April 17, 2007 by amokoura
PsaltyDS Posted April 17, 2007 Posted April 17, 2007 (edited) Thanks for the workaround. Was there some bad code in my example or should I create a bug report? Your code was bad because you tried to use the wrong number of indexes. You provided only one subscript (or index) when the array needed 2: $aTest = $aArray[0]oÝ÷ Ù(hºW[yú+{¦¦WºÚ"µÍÌÍØUÝH ÌÍØP^VÌVÉÌÍØW Since For/In/Next will only create a single variable, you can't do that with multi-dimensional arrays. Just use nested For/Next like gafrost and I both gave examples of. P.S. This does not answer, however, why you wouldn't just use a 1D array instead of a 2D array with only one subscript in the first dimension? Edited April 17, 2007 by PsaltyDS 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
amokoura Posted April 17, 2007 Author Posted April 17, 2007 Your code was bad because you tried to use the wrong number of indexes. You provided only one subscript (or index) when the array needed 2: $aTest = $aArray[0]oÝ÷ Ù(hºW[yú+{¦¦WºÚ"µÍÌÍØUÝH ÌÍØP^VÌVÉÌÍØWoÝ÷ Øô+¡ë'¢Ö§³«½êð,¨» .Ù÷öØî²Û¬yCjºÚÊ)ìµæ¡ö¶ ªëk,"¶'*'z˱Êâ¦Ø§¶»-v)Ȩú®¢×v÷öÜÛh{kiËZ²)àëÚ箴ߦ®¶²#§¶Ø^jºÚÊ)ì×¢·Múh ëk-æâÇ+HßÙæx.±ë6 ªëk+×±¶¶¶)ඪºbw«ªê-jºÚÊ+,¢gg¬ºÇºQÞíý±©è¶«{¦¦W¨}©Ú®¶²rrx¶×¦¦Ö®¶sdFÒb33c¶'&ôg'VG5³%Õ³%ÒÒ²²gV÷C¶&æægV÷C²ÂgV÷C·VÆÆ÷rgV÷CµÒ²gV÷C¶ÆRgV÷C²ÂgV÷C¶w&VVâgV÷CµÒТb33c¶'&ôÆRÒb33c¶'&ôg'VG5³ÐSame error still...
PsaltyDS Posted April 17, 2007 Posted April 17, 2007 (edited) Here's another example of an array copying attempt:Dim $array_Fruits[2][2] = [ ["banana", "yellow"], ["apple", "green"] ] $array_Apple = $array_Fruits[1]oÝ÷ Ù&¦yê뢻-Yªê-y8^³)íkî²×hzÉ÷öÜ(®KajÜÊ)ÀºÚ´êÞßÛ m®'$²v÷öÙ'£áyÊ'µéí²Úªëk'¥zg§µÆ§mæ§¢Ø^éí·®¶²jëh×6Dim $avEven[5] = [0, 2, 4, 6, 8] Dim $avOdd[5] = [1, 3, 5, 7, 9] Dim $avDigits[2] = [$avEven, $avOdd] $Test = $avDigits[0] $Msg = "" For $d = 0 To UBound($Test) - 1 $Msg &= $Test[$d] & @LF Next ConsoleWrite("Even digits:" & $Msg)oÝ÷ ØË¥¶'béìÚªëk+jw(Ö¢k'béìÚªëk+±é^éí³}Î}Ê.®Ç+*º'$&Þr²Ê&w[¢%x¢je{§vÉhÂÚÅç.µëajÙè®f¥¥ê)毢'b´ Þʧ¢¹Ò!ü¨»§¶Ú.±æ§jºÚÊØZ¶+¢{Zwv§¶«jºÚË*.«Þ¶(§(¢ë_»-"{ay¦è½ë®*m×(¦'¢ëm£MúMë-o&®¶sbb33cµFW7BÒb33c¶dFvG5³oÝ÷ Ù8b±ú+{¦¦W¡ë'¢Ü(®F®¶sdFÒb33c¶dWfVå³UÒÒ³Â"ÂBÂbÂФFÒb33c¶döFE³UÒÒ³Â2ÂRÂrÂÐ ¤FÒb33c¶dFvG5³%ÒÒ²b33c¶dWfVâÂb33c¶döFEÐ ¢b33c´×6rÒgV÷C²gV÷C°¤f÷"b33c¶BÒFòT&÷VæBb33c¶dFvG5³ÒÒ b33c´×6rf׳Òb33c¶dFvG5³Õ²b33c¶EÒfײÄ`¤æW@¤6öç6öÆUw&FRgV÷C´öFBFvG3¢gV÷C²fײb33c´×6r Edited April 17, 2007 by PsaltyDS 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
amokoura Posted April 18, 2007 Author Posted April 18, 2007 The syntax just doesn't work that way in AutoIt.Pity But, here's an AutoIt trick some don't know. The contents of an array element can be another entire array: Dim $avEven[5] = [0, 2, 4, 6, 8] Dim $avOdd[5] = [1, 3, 5, 7, 9] Dim $avDigits[2] = [$avEven, $avOdd]I though $avEven and [2,4,6] are both arrays, exactly the same?? Sometimes OK. Thank you very much for the help!
PsaltyDS Posted April 18, 2007 Posted April 18, 2007 That really boggles my mind: Dim $avDigits[2] = [$avEven, $avOdd] ;works Dim $avDigits[2] = [[2,4,6],[1,3,5]] ;doesn't work for sub-array copyingoÝ÷ Øa¢è!Ó~¼KÞ©ÝÛæè¶«¬¬{¶ëïêº^"y²{¦¦W´ß¦¯÷§Ó~¼ç]jwtߦ¯("¶Æ«y©ejºÚÊÍ7é«Ã²+Ô6«¬°ØhÂ¥zg§¶ÍÝH±ëmç(×§¶Ê¶,zÜ(zW¦z{l¶§jºÚËbr¬º{¬¹©ZÙè¶·¢i×NÆ¢¨~Ø^jºÚÊÍ7é«Ä½éÚÝ7é«ÎuÔáyé^éí²í²Ú+yÖ«¬¬q©ç¢ÖÞi×kzËw~*ìµÊ)Ê)ඦ¢ëm¡¬(®H§ö«¦å{MúMë-y²{¦¦WyÊ&zƵ ªëk"'Ê«x©bÍ«b¢zÓ~¼8 ÛnÞÊ©®âuè§Ø,Ú¶*'~íÂbéììnëm櫬¨¡jÊ'yئz{"¢|"¶p¡é^éí±8^rëyË_¢¹¨~ØZ· .ØZ½æÞzv®¶sdFÒb33c¶dFvG5³%Õ³5ÒÒµ³"ÂBÂeÒ³Â2ÂUÕÐoÝ÷ Ù.Â¥vØ^¯zÚqǬ²+n²)à· "×±zÆ®¶sbb33c´çVÒÒb33c¶dFvG5³Õ³%Ò²&VG2b33³bb33° 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
ChrisL Posted April 18, 2007 Posted April 18, 2007 you can use my _ArrayDisplay2() function if you need to look at your array if it helps, it can display 1d or 2d arrays expandcollapse popupFunc _ArrayDisplay2(Const ByRef $avArray, $sTitle = "") If (Not IsArray($avArray)) Then SetError(1) Return 0 EndIf #include<guiConstants.au3> Local $iRows = 0, $iCols = 0, $cHeaders, $iCnt = 0, $lv ,$lCnt = 0, $tCnt = 0, $rtext, $cButton,$lvGui,$lvGuiMsg $iRows = Ubound($avArray) -1 $icols = Ubound($avArray,2) $cHeaders = "I/C |0|" For $iCnt = 1 to $iCols -1 $cHeaders &= $iCnt & "|" Next $lvGui = GuiCreate($sTitle,400,300) $lv= GuiCtrlCreateListview($cHeaders,20,20,360,220) If $icols <> 0 then For $lCnt = 0 to $iRows $rtext = "[" & $lCnt &"]|" For $tCnt = 0 to $icols -1 $rText &= $avArray[ $lcnt][$tcnt] & "|" Next GUICtrlCreateListViewItem($rText,$lv) Next Else For $lCnt = 0 to $iRows $rtext = "[" & $lCnt &"]|" & $avArray[$lCnt] GUICtrlCreateListViewItem($rText,$lv) Next EndIf $cButton = GuiCtrlCreateButton("Close", 150, 260, 110, 30) GuiSetState() While 1 $lvGuiMsg = GuiGetMsg(1) Select Case $lvGuiMsg[0] = $GUI_EVENT_CLOSE or $lvGuiMsg[0] = $cButton If $lvGuiMsg[1] = $lvGui then ExitLoop Case Else ;;; EndSelect WEnd SetError(0) Return 1 EndFunc [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
jvanegmond Posted April 18, 2007 Posted April 18, 2007 For..In..Next loops are only to be used with objects!. For..Next loops are useful for Arrays. github.com/jvanegmond
PsaltyDS Posted April 18, 2007 Posted April 18, 2007 (edited) For..In..Next loops are only to be used with objects!. For..Next loops are useful for Arrays. Not true. It works with collection objects because they are arrays! Dim $avDigits[10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] For $d In $avDigits ConsoleWrite($d & @LF) Next Edited April 18, 2007 by PsaltyDS 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
hmsSurprise Posted April 18, 2007 Posted April 18, 2007 Sure am glad y'all had this discussion as I am about to implement a 3D array. And what good are arrays if you can't traverse them with for loops? Thanks, jh
amokoura Posted April 19, 2007 Author Posted April 19, 2007 ...In your initialization of $avDigits above you provide initialization for two dimensions but the array only has one dimension with two elements....OK I can see clearly now, thanks! I'm a child of PHP and it tought me array handling. I recall it had a more flexible array handling system regarding to dimensions and elements. I mistakenly expected AutoIt arrays to work the same way. Or do I remember wrong? Any PHP guys?you can use my _ArrayDisplay2() function if you need to look at your array if it helps, it can display 1d or 2d arraysThanks a lot! Will come in handy.
therks Posted April 19, 2007 Posted April 19, 2007 OK I can see clearly now, thanks! I'm a child of PHP and it tought me array handling. I recall it had a more flexible array handling system regarding to dimensions and elements. I mistakenly expected AutoIt arrays to work the same way. Or do I remember wrong? Any PHP guys? Thanks a lot! Will come in handy. I had a feeling you might have come from PHP, I did also and was also confused by the way AutoIt handled their multi-dimensional arrays. As you know, in PHP a multi-dimensional array is actually an array within an array, and you can access it as such. In AutoIt it doesn't behave that way, it acts ONE array, with multiple dimensions, and you have to access it from the base of the entire array... I have a hard time explaining it, since as near as I know, PHP can't behave the same way at all. I'll try to describe it as such. With PHP, you can do something like this: $myarray = array(1, 2, 3, 4, array(1, 2, 3, 4)); print_r($myarray); And you get something like this: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) ) Notice how it says that index [4] of the first array IS an array? Now, if you could use print_r() on this array (an example I saw previously), you'd perhaps get something like the following: ; Array example Dim $array_Fruits[2][2] = [ ["banana", "yellow"], ["apple", "green"] ] ; and example print_r output Array ( [0,0] => banana [0,1] => yellow [1,0] => apple [1,1] => green ) Hmm.. bah, I don't know how well that works. I'm really not good at this explaining thing. Hopefully this doesn't create more confused than before. My AutoIt Stuff | My Github
amokoura Posted April 19, 2007 Author Posted April 19, 2007 (edited) ...In AutoIt it doesn't behave that way, it acts ONE array, with multiple dimensions, and you have to access it from the base of the entire array... I have a hard time explaining it, since as near as I know, PHP can't behave the same way at all. ...OK thanks, that finally verifies my thoughts.I PHP arrays. In the old days I built houses by using them. Edited April 19, 2007 by amokoura
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