sree161 Posted August 28, 2017 Share Posted August 28, 2017 I need to run For loop until it has no lines to produce as output. i tried the below code and unable to get output. For $l=1 To @error Step 1 $Out = "$Sp[" & $l & "]:" & $Sp[$l] MsgBox($MB_SYSTEMMODAL , "Split", $Out ) Next Can anyone help me on this?? Thanks in advance. Link to comment Share on other sites More sharing options...
czardas Posted August 28, 2017 Share Posted August 28, 2017 Has an error been thrown? If not then the loop will run 0 times because the start is greater than the end ==> @error = 0. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
sree161 Posted August 28, 2017 Author Share Posted August 28, 2017 Local $Input = _ "sajfkjdsaf" & @CRLF & _ "name" & @CRLF & _ "ajhsdfkajfdajsjdflkjafa" & @CRLF & _ "afdhjsahlfkaf" & @CRLF & _ "ajfkhdsakfasf" & @CRLF & _ "akjfkjafd" & @CRLF & _ "name" & @CRLF & _ "asfjksajf" & @CRLF & _ "kdajsfpa" & @CRLF & _ "alkdshfahsf" & @CRLF & _ "nameajslkfja" & @CRLF & _ "aslkfajnbfajn" $Sp = StringSplit ( $Open , "name" , $STR_ENTIRESPLIT ) For $l=1 To @error Step 1 $Out = "$Sp[" & $l & "]:" & $Sp[$l] MsgBox($MB_SYSTEMMODAL , "Split", $Out ) Next This is my whole pgm and i am not getting any output......can i know the reason where i went wrong?? 1 hour ago, czardas said: Has an error been thrown? If not then the loop will run 0 times because the start is greater than the end ==> @error = 0. Link to comment Share on other sites More sharing options...
czardas Posted August 28, 2017 Share Posted August 28, 2017 Is this what you want? #include <StringConstants.au3> #include <MsgBoxConstants.au3> Local $Input = _ "sajfkjdsaf" & @CRLF & _ "name" & @CRLF & _ "ajhsdfkajfdajsjdflkjafa" & @CRLF & _ "afdhjsahlfkaf" & @CRLF & _ "ajfkhdsakfasf" & @CRLF & _ "akjfkjafd" & @CRLF & _ "name" & @CRLF & _ "asfjksajf" & @CRLF & _ "kdajsfpa" & @CRLF & _ "alkdshfahsf" & @CRLF & _ "nameajslkfja" & @CRLF & _ "aslkfajnbfajn" $Sp = StringSplit ($Input , "name" , $STR_ENTIRESPLIT ) For $l = 1 To $Sp[0] Step 1 $Out = "$Sp[" & $l & "]:" & $Sp[$l] MsgBox($MB_SYSTEMMODAL , "Split", $Out ) Next operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
sree161 Posted August 28, 2017 Author Share Posted August 28, 2017 5 minutes ago, czardas said: Is this what you want? #include <StringConstants.au3> #include <MsgBoxConstants.au3> Local $Input = _ "sajfkjdsaf" & @CRLF & _ "name" & @CRLF & _ "ajhsdfkajfdajsjdflkjafa" & @CRLF & _ "afdhjsahlfkaf" & @CRLF & _ "ajfkhdsakfasf" & @CRLF & _ "akjfkjafd" & @CRLF & _ "name" & @CRLF & _ "asfjksajf" & @CRLF & _ "kdajsfpa" & @CRLF & _ "alkdshfahsf" & @CRLF & _ "nameajslkfja" & @CRLF & _ "aslkfajnbfajn" $Sp = StringSplit ($Input , "name" , $STR_ENTIRESPLIT ) For $l = 1 To $Sp[0] Step 1 $Out = "$Sp[" & $l & "]:" & $Sp[$l] MsgBox($MB_SYSTEMMODAL , "Split", $Out ) Next What if i want to increase my $l count till end. How to terminate loop when there is no output to display?? That is where i get stuck? All the sample programs are going descending in For loop, but i want a ascending loop from 1 to some x...i want the loop to be terminated when there is no output to display. In above program u are going descending. Link to comment Share on other sites More sharing options...
czardas Posted August 28, 2017 Share Posted August 28, 2017 (edited) It does stop when it reaches the array element/item count at $Sp[0] : which is 4 in your example. You can reverse the order by starting at the end instead - negative step value. So you can loop whichever direction you want. For $l = $Sp[0] To 1 Step -1 $Out = "$Sp[" & $l & "]:" & $Sp[$l] MsgBox($MB_SYSTEMMODAL , "Split", $Out ) Next In fact 'Step 1' is never needed and can be removed from the first example. Also you could split the string differently to produce more array elements (using a different delimiter). Try it! $Sp = StringSplit ($Input, @CRLF, $STR_ENTIRESPLIT) I recommend you look at _ArrayDisplay(). It will help you to understand how arrays work. Edited August 28, 2017 by czardas sree161 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
jdelaney Posted August 28, 2017 Share Posted August 28, 2017 You can use: While Not @error SomeFunctionThatReturnsError() Wend Or While True SomeFunctionThatReturnsError() If @error Then ExitLoop Wend IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
sree161 Posted August 29, 2017 Author Share Posted August 29, 2017 Thanks fr ur help....i have solved this issue czardas 1 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