Shyke Posted November 14, 2006 Share Posted November 14, 2006 $a = StringSplit($input, "") For $i = 1 to $a[0] If $a[$i] = "|" And $a[$i + 1] = "\" And $a[$i + 2] = "/" And $a[$i + 3] = "|" Then $output = $output & "m" $i = $i + 4 EndIf Next That's a clippet of my code. It runs into errors when it tries to test $a[$i + 1] if it is already at the end of $a[0] as expected. How do I work around this so I don't hit this terminal error? Link to comment Share on other sites More sharing options...
PaulIA Posted November 14, 2006 Share Posted November 14, 2006 $a = StringSplit($input, "") For $i = 1 to $a[0] If $a[$i] = "|" And $a[$i + 1] = "\" And $a[$i + 2] = "/" And $a[$i + 3] = "|" Then $output = $output & "m" $i = $i + 4 EndIf Next That's a clippet of my code. It runs into errors when it tries to test $a[$i + 1] if it is already at the end of $a[0] as expected. How do I work around this so I don't hit this terminal error?Don't ever modify a loop variable inside the loop itself. It will bring you really bad karma. How about: $a = StringSplit($input, "") $i=1 while $i <= $a[0] - 3 If $a[$i] = "|" And $a[$i + 1] = "\" And $a[$i + 2] = "/" And $a[$i + 3] = "|" Then $output = $output & "m" EndIf $i = $i + 4 wend Auto3Lib: A library of over 1200 functions for AutoIt Link to comment Share on other sites More sharing options...
Shyke Posted November 14, 2006 Author Share Posted November 14, 2006 (edited) Err... Here's a bigger piece of my code: $a = StringSplit($input, "") For $i = 1 To $a[0] If $a[$i] = "|" And $a[$i + 1] = "\" And $a[$i + 2] = "/" And $a[$i + 3] = "|" Then $output = $output & "m" $i = $i + 4 ElseIf $a[$i] = "|" And $a[$i + 1] = "-" And $a[$i + 2] = "|" Then $output = $output & "h" $i = $i + 3 ElseIf $a[$i] = "|" And $a[$i + 1] = "\" And $a[$i + 2] = "|" Then $output = $output & "n" $i = $i + 3 EndIf Next Edited November 14, 2006 by Shyke Link to comment Share on other sites More sharing options...
PaulIA Posted November 14, 2006 Share Posted November 14, 2006 (edited) $a = StringSplit($input, "") $i = 1 while $i < $a[0] if $i < $a[0] - 4 then If $a[$i] = "|" And $a[$i + 1] = "\" And $a[$i + 2] = "/" And $a[$i + 3] = "|" Then $output = $output & "m" $i = $i + 4 endif endif if $i < $a[0] - 3 then If $a[$i] = "|" And $a[$i + 1] = "-" And $a[$i + 2] = "|" Then $output = $output & "h" $i = $i + 3 ElseIf $a[$i] = "|" And $a[$i + 1] = "\" And $a[$i + 2] = "|" Then $output = $output & "n" $i = $i + 3 EndIf endif Next Same principal, just different checks. Edit: Misplaced an endif Edited November 14, 2006 by PaulIA Auto3Lib: A library of over 1200 functions for AutoIt 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