inna 0 Posted yesterday at 05:43 PM Share Posted yesterday at 05:43 PM Hello, I see For...In...Next help which is this: Local $aArray[4] $aArray[0] = "a" $aArray[1] = 0 $aArray[2] = 1.3434 $aArray[3] = "test" Local $sString = "" For $vElement In $aArray $sString = $sString & $vElement & @CRLF ConsoleWrite($sString) Next But what I'm trying to reach (and failed yet) is: ; the number of items on list or array changes and is not fixed (I don't know the count) $list = ['me', 'you', 'him'] for $i in $list ConsoleWrite($i & @LF) Next ; the console should print: ;me ;you ;him How can I reach this? I have a list of names and I should iterate over. Thanks in advance Link to post Share on other sites
ioa747 99 Posted yesterday at 06:17 PM Share Posted yesterday at 06:17 PM Local $aArray[4] $aArray[0] = "a" $aArray[1] = 0 $aArray[2] = 1.3434 $aArray[3] = "test" Local $sString = "" For $x = 0 To UBound($aArray) - 1 ConsoleWrite("$aArray[" & $x & "]=" & $aArray[$x] & @TAB) Next ConsoleWrite("" & @CRLF) Link to post Share on other sites
Solution inna 0 Posted yesterday at 06:17 PM Author Solution Share Posted yesterday at 06:17 PM I got it:) #include <MsgBoxConstants.au3> Local $aDays = StringSplit('me, you, him', ',') For $i = 1 To $aDays[0] ; Loop through the array returned by StringSplit to display the individual values. ConsoleWrite($aDays[$i]) Next Link to post Share on other sites
inna 0 Posted 23 hours ago Author Share Posted 23 hours ago 6 minutes ago, ioa747 said: Local $aArray[4] $aArray[0] = "a" $aArray[1] = 0 $aArray[2] = 1.3434 $aArray[3] = "test" Local $sString = "" For $x = 0 To UBound($aArray) - 1 ConsoleWrite("$aArray[" & $x & "]=" & $aArray[$x] & @TAB) Next ConsoleWrite("" & @CRLF) Thanks, but that's not what I meant. Please compare my post to yours and compare the outputs. Link to post Share on other sites
ioa747 99 Posted 23 hours ago Share Posted 23 hours ago 4 minutes ago, inna said: Please compare my post to yours and compare the outputs. I thought you had a problem because I couldn't figure it out +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. a a 0 a 0 1.3434 a 0 1.3434 test +>20:27:53 AutoIt3.exe ended.rc:0 for this reason it is placed in a series so that it makes some sense +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. $aArray[0]=a $aArray[1]=0 $aArray[2]=1.3434 $aArray[3]=test +>20:35:35 AutoIt3.exe ended.rc:0 Link to post Share on other sites
mistersquirrle 56 Posted 22 hours ago Share Posted 22 hours ago (edited) 2 hours ago, inna said: But what I'm trying to reach (and failed yet) is: $list = ['me', 'you', 'him'] for $i in $list ConsoleWrite($i & @LF) Next You have some syntax errors, which when you ran this the console should point you to the problem. Make sure that you read the errors that come up when you run your script. Here's the correct version: Global $list[] = ['me', 'you', 'him'] For $i In $list ConsoleWrite($i & @LF) Next Mainly, you didn't initialize $list as an array with either $list[] = ['values'] or $list[3] (and with the scope, Global or Local). However typically it's best to use For...To...Step...Next as you can then also get the index of the array. For...In...Next is best for objects or maps where there's not a sequential index. Check out this page for some more tips on using AutoIt: https://www.autoitscript.com/wiki/Best_coding_practices Edited 22 hours ago by mistersquirrle We ought not to misbehave, but we should look as though we could. Link to post Share on other sites
ioa747 99 Posted 21 hours ago Share Posted 21 hours ago This makes some sense Local $aArray[4] $aArray[0] = "a" $aArray[1] = 0 $aArray[2] = 1.3434 $aArray[3] = "test" Local $sString = "" For $vElement In $aArray $sString = $sString & $vElement & @CRLF ;~ ConsoleWrite($sString) Next ConsoleWrite($sString) Link to post Share on other sites
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