Animal_Chin Posted February 23, 2019 Share Posted February 23, 2019 I can't figure out why this is incrementing by 2. The peer length not exceed 9 chars. There's more code to validate and fix if it exceeds 9, but I can't even step through the array and touch each index without incrementing by 2. I'm sure it's simple. Thoughts? Local $peerNamesRaw[5] = ["12","1234","123456", "123456789", "1234567890"] Local $peerNameDiff = 0 Local $peerNameLen = 0 $i = 0 for $i = 0 To UBound($peerNamesRaw) - 1 $peerNameLen = Stringlen($peerNamesRaw[$i]) $peerNameDiff = (9 - $peerNameLen) MsgBox(64, "Index - Raw Len, Calc'd Len, Diff", $i & " - " & $peerNamesRaw[$i] & " " & $peerNameLen & " " & $peerNameDiff) $i = $i + 1 Next Link to comment Share on other sites More sharing options...
Animal_Chin Posted February 23, 2019 Author Share Posted February 23, 2019 I got it. Just different syntax than I was used to I guess. I had to rem the $i var incrementer at the end of the loop and add Step 1 to the for statement. Local $peerNamesRaw[5] = ["12","1234","123456", "123456789", "1234567890"] Local $peerNameDiff = 0 Local $peerNameLen = 0 $i = 0 for $i = 0 To UBound($peerNamesRaw) Step 1 $peerNameLen = Stringlen($peerNamesRaw[$i]) $peerNameDiff = (9 - $peerNameLen) MsgBox(64, "Index - Raw Len, Calc'd Len, Diff", $i & " - " & $peerNamesRaw[$i] & " " & $peerNameLen & " " & $peerNameDiff) ;$i = $i + 1 Next Link to comment Share on other sites More sharing options...
Subz Posted February 23, 2019 Share Posted February 23, 2019 It should be like Example 1 below otherwise you'll get an array error. The second example uses the first row item to be the count of the array. ;~ Example 1 Local $apeerNamesRaw[5] = ["12","1234","123456", "123456789", "1234567890"] Local $ipeerNameDiff = 0 Local $ipeerNameLen = 0 For $i = 0 To UBound($apeerNamesRaw) - 1 $ipeerNameLen = Stringlen($apeerNamesRaw[$i]) $ipeerNameDiff = (9 - $ipeerNameLen) MsgBox(64, "Index - Raw Len, Calc'd Len, Diff", $i & " - " & $apeerNamesRaw[$i] & " " & $ipeerNameLen & " " & $ipeerNameDiff) Next ;~ Or ;~ Example 2 Local $apeerNamesRaw[6] = [4, "12","1234","123456", "123456789", "1234567890"] Local $ipeerNameDiff = 0 Local $ipeerNameLen = 0 For $i = 1 To $apeerNamesRaw[0] $ipeerNameLen = Stringlen($apeerNamesRaw[$i]) $ipeerNameDiff = (9 - $ipeerNameLen) MsgBox(64, "Index - Raw Len, Calc'd Len, Diff", $i & " - " & $apeerNamesRaw[$i] & " " & $ipeerNameLen & " " & $ipeerNameDiff) Next Link to comment Share on other sites More sharing options...
careca Posted February 23, 2019 Share Posted February 23, 2019 (edited) 3 hours ago, Animal_Chin said: I can't figure out why this is incrementing by 2. Thoughts? Local $peerNamesRaw[5] = ["12","1234","123456", "123456789", "1234567890"] Local $peerNameDiff = 0 Local $peerNameLen = 0 $i = 0 for $i = 0 To UBound($peerNamesRaw) - 1 $peerNameLen = Stringlen($peerNamesRaw[$i]) $peerNameDiff = (9 - $peerNameLen) MsgBox(64, "Index - Raw Len, Calc'd Len, Diff", $i & " - " & $peerNamesRaw[$i] & " " & $peerNameLen & " " & $peerNameDiff) $i = $i + 1 Next Yes, this: $i = $i + 1 I explain: ;first loop for $i = 0 To UBound($peerNamesRaw) ;somecode < $i is 0 at this moment $i = $i + 1 ;< you add 1 to $i, so now it becomes 1 Next ;second loop for $i = 0 To UBound($peerNamesRaw) ;$i was 1 from the first loop and now becomes 2 ;somecode < $i is 2 at this moment $i = $i + 1 ;< you add 1 to $i, so now it becomes 3, and in the start of the next loop becomes 4 and so on. Next So if you remove that bit that adds 1 in each loop, the behaviour becomes normal. That is only used with a while or a do loop. Edited February 23, 2019 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
Animal_Chin Posted February 23, 2019 Author Share Posted February 23, 2019 Thanks for explaining why. Appreciated it! Link to comment Share on other sites More sharing options...
Dwalfware Posted February 25, 2019 Share Posted February 25, 2019 (edited) If you need to count the loops add a diffrent $xii = $xii + 1 but not the $xi will increase by two if you add $xi = $xi + 1 thus $xii will be a counter if your wish to do other things like If $xii = 10 then Consolewrite("The loop has done ten failed loops") exitloop Endif $xii = $xii +1 ;Usefull if you are testing something like ping and want to exit the loop after a number of failed tries. Just add exitloop or return or continueloop Good for While 1 loops Edited February 25, 2019 by Dwalfware Link to comment Share on other sites More sharing options...
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