LukeJrs Posted August 4, 2007 Share Posted August 4, 2007 I'm trying to stop a loop. Like if found match values using _IEDocReadHTML($soIE1) then execute command once and finish next and just execute the next following command line MsgBox(0, "YAY LOOP:", "STOPPED"). CODE#include <IE.au3> #include <String.au3> #include <array.au3> $soIE1 = _IECreate("http://www.freewebs.com/lukejrs/testvar.html", 1, 1) ;OPEN BROWNSER URL $sText1 = _IEDocReadHTML($soIE1) ;READ FROM HTML CODE ON WEBSITE $feature = _StringBetween($sText1, 'teleFeature.code = "', '";') ; FEATURE For $a = 0 To UBound($feature) - 1 ; maybe $i = 1 if you needn't the count. if $feature[$a] == "68819" Then MsgBox(0, "WE FOUND", "68819") ElseIf $feature[$a] == "68818" then MsgBox(0, "WE FOUND", "68818") ElseIf $feature[$a] == "73417" or "72146" Then MsgBox(0, "WE FOUND", "73417 and 72146") _IENavigate($soIE1, "http://www.freewebs.com") EndIf Next MsgBox(0, "YAY LOOP:", "STOPPED") Can you help? I been driving my brain to a DEAD END >< Link to comment Share on other sites More sharing options...
NELyon Posted August 4, 2007 Share Posted August 4, 2007 ExitLoop Link to comment Share on other sites More sharing options...
LukeJrs Posted August 4, 2007 Author Share Posted August 4, 2007 (edited) tried but i dont want to close the script like if i have two loop and i want exit one loop but the other one continue looping CODE #include <IE.au3> #include <String.au3> #include <array.au3> $number = "1" For $i1 = 0 To 9999 $soIE1 = _IECreate("http://www.freewebs.com/lukejrs/testvar.html", 1, 1) ;OPEN BROWNSER URL MsgBox(0, "Counting", $number) $sText1 = _IEDocReadHTML($soIE1) ;READ FROM HTML CODE ON WEBSITE $feature = _StringBetween($sText1, 'teleFeature.code = "', '";') ; FEATURE For $a = 0 To UBound($feature) - 1 ; maybe $i = 1 if you needn't the count. if $feature[$a] == "68819" Then MsgBox(0, "WE FOUND", "68819") _IENavigate($soIE1, "http://www.google.com") exitloop ElseIf $feature[$a] == "68818" then MsgBox(0, "WE FOUND", "68818") _IENavigate($soIE1, "http://www.yahoo.com") exitloop ElseIf $feature[$a] == "73417" or "72146" Then MsgBox(0, "WE FOUND", "73417 and 72146") _IENavigate($soIE1, "http://www.freewebs.com") exitloop EndIf Next MsgBox(0, "YAY LOOP:", "STOPPED") $number += 1 Next P.S Never mind lol i'm idiot thanks for your help i had it right what happen was causing an error i forgot one of the command i had $$ money sign which was causing my script to fail Edited August 4, 2007 by LukeJrs Link to comment Share on other sites More sharing options...
ssubirias3 Posted August 4, 2007 Share Posted August 4, 2007 tried but i dont want to close the script like if i have two loop and i want exit one loop but the other one continue loopingTo exit the current loop use ExitLoop like Senton-Bomb suggested. To exit the script use the Exit command. From what I can see your script is going to loo[ 9999 times and open 9999 browser windows before quiting. If you want the scritp to end before all 9999 loops have been completed you need to use the Exit command. Another thing that I noticed was your last condition does not match your msgbox. ElseIf $feature[$a] == "73417" Or "72146" Then MsgBox(0, "WE FOUND", "73417 and 72146") _IENavigate($soIE1, "http://www.freewebs.com") ExitLoop EndIf The above is saying if either 73417 OR 72146 are found then to display the message you found both numbers. In order for your message to be correct you will need to either change the ElseIf statement from OR to AND .... or change the message to say "73417 or 72146". The other thing to consider is what should the script do if none of these values are found? Not a big deal just things to consider. Link to comment Share on other sites More sharing options...
LukeJrs Posted August 5, 2007 Author Share Posted August 5, 2007 I have lot of Elseif command let say the value i was looking wasn't found if $feature[$a] == "73417" and not equal to anything i have like CODE Elseif Not $feature[$a] == "68819" or $feature[$a] == "68818" or $feature[$a] == "73417" or $feature[$a] == "72148" or $feature[$a] == "72157" or $feature[$a] == "72191" or $feature[$a] == "63657" or $feature[$a] == "72145" or $feature[$a] == "62647" or $feature[$a] == "63654" or $feature[$a] == "69902" or $feature[$a] == "72147" or $feature[$a] == "72150" or $feature[$a] == "68844" or $feature[$a] == "72159" or $feature[$a] == "73502" or $feature[$a] == "73503" or $feature[$a] == "71667" or $feature[$a] == "58791" or $feature[$a] == "68846" or $feature[$a] == "68274" or $feature[$a] == "63660" or $feature[$a] == "71615" Then MsgBox(0, "WE FOUND", "nothing") exitloop Any idea? cause i have lots else if like 34 of them i have tried Case command i have no luck. Link to comment Share on other sites More sharing options...
ssubirias3 Posted August 5, 2007 Share Posted August 5, 2007 (edited) I have lot of Elseif command let say the value i was looking wasn't found if $feature[$a] == "73417" and not equal to anything ...... i have lots else if like 34 of them i have tried Case command i have no luck.Will these 34 codes be static or will they be dynamic (changing based on time or events)? Thanks to many of the MVPs here like PsaltyDS, I'm slowly starting to understand the importance of arrays in programming. That said you might want to hold your codes in an array. I'm still way too new to dare suggest how to do this on the fly. Let us know about the 34 codes and their nature (static / dynamic). Meanwhile I'll see if I can think of something that might help you before Thanksgiving. No seriously, I'm that new and slow. What takes me months to do, many of the others here can do in 3 seconds and that's after yawning and a good stretch. EDIT: Also if you know if you're only going to want to take a certain action on 3 or 4 of the possible 34 codes you'll probably want to do something like IF $feature <> $values Then MsgBox(0,"No Match", "Sorry Charlie no dice"). Edited August 5, 2007 by ssubirias3 Link to comment Share on other sites More sharing options...
ssubirias3 Posted August 5, 2007 Share Posted August 5, 2007 Here it's the code. The only thing it does read the url hml and grab a stringbetween then use $feature[0], $feature[2], $feature[3], $feature[4], and $feature[5] and keep at it until all string been search if value not match else feature elseif not $feature[$a] == "value" then MsgBox(0, "nada", "Nothing")Read up on _ArraySearch and look at the example in the help file. I think this will give you what you want! If you get this working, please post your finished code. I think you're on the right track! Keep up the good work. Link to comment Share on other sites More sharing options...
MHz Posted August 5, 2007 Share Posted August 5, 2007 I have lot of Elseif command let say the value i was looking wasn't found if $feature[$a] == "73417" and not equal to anything i have like CODE Elseif Not $feature[$a] == "68819" or $feature[$a] == "68818" or $feature[$a] == "73417" or $feature[$a] == "72148" or $feature[$a] == "72157" or $feature[$a] == "72191" or $feature[$a] == "63657" or $feature[$a] == "72145" or $feature[$a] == "62647" or $feature[$a] == "63654" or $feature[$a] == "69902" or $feature[$a] == "72147" or $feature[$a] == "72150" or $feature[$a] == "68844" or $feature[$a] == "72159" or $feature[$a] == "73502" or $feature[$a] == "73503" or $feature[$a] == "71667" or $feature[$a] == "58791" or $feature[$a] == "68846" or $feature[$a] == "68274" or $feature[$a] == "63660" or $feature[$a] == "71615" Then MsgBox(0, "WE FOUND", "nothing") exitloop Any idea? cause i have lots else if like 34 of them i have tried Case command i have no luck.Issues using Not like in your other topic I see. Moving a long, you could perhaps consider using a Switch...Case...EndSwitch to clean up the code or even put all the numbered conditions into a array to compare within a loop. Switch $feature[$a] Case 68819, 68818, 73417, 72148, 72157 ContinueCase Case 72191, 63657, 72145, 62647, ... MsgBox(0, "WE FOUND", "nothing") EndSwitchoÝ÷ Ù8^méhÂ+'¢Ö¥tò¢ìÛhr©j·½ªâi¹^¶¢wb¶*'¶§Ê§yçm¢·©y«mëÚ®&ì"¶r(«Ê'jëh×6 ElseIf $feature[$a] == "73417" or "72146" ThenoÝ÷ ÚX¤zØ^méhÁ«¢+رÍ%ÀÌØíÑÕÉlÀÌØítôôÅÕ½ÐìÜÌÐÄÜÅÕ½Ðì½ÈÀÌØíÑÕÉlÀÌØítôôÅÕ½ÐìÜÈÄÐØÅÕ½ÐìQ¡¸ Link to comment Share on other sites More sharing options...
ssubirias3 Posted August 5, 2007 Share Posted August 5, 2007 This is so cool, I psyched that I'm actually starting to get some of this stuff. Then to come back to this post and read MHz suggest something I thought would work... well that's just icing on the cake. Guess I was on the right track. Now that I got that out of my system, back to LukeJrs problem. LukeJrs, LukeJrs, LukeJrs... I saw your other post and I'm wondering why you ignored my earlier suggestion where I said .... do something like IF $feature <> $values Then MsgBox(0,"No Match", "Sorry Charlie no dice"). That may have saved you some frustration with your Elseif Not $feature[$a] == "68819" or code. Based on what MHz suggested ..... perhaps consider using a Switch...Case...EndSwitch to clean up the code or even put all the numbered conditions into a array to compare within a loop.here's what I came up with. Not sure if it does what you need, but it is a modification of the _ArraySearch example I mentioned to you earlier. I will admit looking at MHz's code, it seems to be cleaner than what I put together. But hey, MHz is an MVP -- I'm nothing, nada #include <IE.au3> #include <String.au3> #include <array.au3> ; $avCodes contains the strings you want to search for ; NOTE: last two values in the array are in the html code. Dim $avCodes[6] = ["68819", "73501", "73417", "72146", "68994", "48526"] ; Create an invisible browser $soIE1 = _IECreate("http://www.freewebs.com/lukejrs/testvar.html", 0, 0, 1) $sText1 = _IEDocReadHTML($soIE1) ;READ FROM HTML CODE ON WEBSITE $avFeature = _StringBetween($sText1, 'teleFeature.code = "', '";') ; FEATURE For $i = 0 To UBound($avCodes) - 1 $Input = $avCodes[$i] $Pos = _ArraySearch ($avFeature, $Input) Select Case $Pos = -1 MsgBox(0, "Not Found", '"' & $Input & '" was not found in the array.') Case Else MsgBox(0, "Found", '"' & $Input & '"' & " was found in the array.") EndSelect Next MsgBox(0,"Ta Dah", 'Script finished. Click "OK" to exit.')oÝ÷ Øýz-æ¥+.ì!Ë*.§máh¯Mú Link to comment Share on other sites More sharing options...
LukeJrs Posted August 6, 2007 Author Share Posted August 6, 2007 CODE#include <IE.au3> #include <String.au3> #include <array.au3> ; $avCodes contains the strings you want to search for ; NOTE: last two values in the array are in the html code. Dim $avCodes[6] = ["68819", "73501", "73417", "72146", "68994", "48526"] ; Create an invisible browser $soIE1 = _IECreate("http://www.freewebs.com/lukejrs/testvar.html", 0, 0, 1) $sText1 = _IEDocReadHTML($soIE1) ;READ FROM HTML CODE ON WEBSITE $avFeature = _StringBetween($sText1, 'teleFeature.code = "', '";') ; FEATURE For $i = 0 To UBound($avCodes) - 1 $Input = $avCodes[$i] $Pos = _ArraySearch ($avFeature, $Input) Select Case $Pos = -1 MsgBox(0, "Not Found", '"' & $Input & '" was not found in the array.') Case Else MsgBox(0, "Found", '"' & $Input & '"' & " was found in the array.") EndSelect Next MsgBox(0,"Ta Dah", 'Script finished. Click "OK" to exit.') Looking good But i never understand case and ubound For $i = 0 To UBound($avCodes) - 1 $Input = $avCodes[$i] $Pos = _ArraySearch ($avFeature, $Input) Select Case $Pos = -1 MsgBox(0, "Not Found", '"' & $Input & '" was not found in the array.') Case Else MsgBox(0, "Found", '"' & $Input & '"' & " was found in the array.") EndSelect Next Can you trasnlate that in idiot term lol i'm still learning :\ it work, There lots calculation needed to be done once the code was found, Each Number of feature is found have their own fraction needed to execute Can it be done? Example ElseIf $feature[$a] == "58791" Then MsgBox(0, "account is over by: ", "58791" & " - $" & 8*0.15) EndIf exitloop Link to comment Share on other sites More sharing options...
ssubirias3 Posted August 6, 2007 Share Posted August 6, 2007 Looking good But i never understand case and ubound Can you trasnlate that in idiot term lol i'm still learning :\ it work, There lots calculation needed to be done once the code was found, Each Number of feature is found have their own fraction needed to execute Can it be done?One thing I've noticed across my reading of the forums is the lack of simple "Thank you" and "You're Welcome" messages. I guess the lack of the first has a direct impact on the second, good ole cause and effect. @LukeJrs you're welcome and I'm glad the script worked for you. Especially considering that your original question was how to exit a loop. I didn't mind working on your script since it allowed me to practice some new found knowledge recently gained from big_daddy, PsaltyDS, MHz. Just remember to pay it forward and say a simple "thank you' . Look in the help file for the answers about your "case and ubound" questions. And actually its Switch...Case...EndSwitch, not "case". Here's how I would answer your question (not to excuse you from reading the help file). Switch...Case...EndSwitch and If...Then...EndIf are very similar. There are several ways to skin a cat and the same is true for conditionally running statements. As explained to me by big_daddy, Switch...Case...EndSwitch can make your code easier to read and smaller in size in some cases when compared to If...Then...EndIf. I personally haven't figured out nor received a good answer to the question "when is one conditional statement set better than another?" So I'm left with the idea it depends, on the person, situation, and probably the weather. Take your code for instance, MHz suggested Switch...Case...EndSwitch and I used Select...Case...EndSelect. I honestly don't know the difference between the two, but I'm sure there's a reason for each. Ubound, easier to understand in that it returns the size of an array. And that's straight from the help file, you still need to read it for more details. In your script I setup $avCodes[6] as an array that would hold 6 values. Later in the loop instead of saying For $i = 0 To 6 ;<= Loop would occur 0 - 6 times .... blah, blah, blah NextoÝ÷ Ø׶"½ì¨ºØ^~W±¸¥Ü¨}§]x(×¥zاØ^Ó~¼*zÌ"¶.¶¯x-¡©l¡ÈZ¨¯ +¯&¢ëf¡ØÊ)ජ½7ê Glad this worked out for you, and one thing I've learned by reading the forum is that many of the gurus aren't interested in writing a script for the asking, they want to see everyone put forth an effort and not be a lazy freeloader. Only makes sense, especially when the answers are in help or on another topic somewhere in this forum. Hope this helped you! Link to comment Share on other sites More sharing options...
LukeJrs Posted August 6, 2007 Author Share Posted August 6, 2007 I appreciate your time and everyone for helping me. I have read many topic and help files didn't understand it that well thank for pointing the right dirrection I'll try making my project easier to understand and not use if, endif ect thank you all again Link to comment Share on other sites More sharing options...
MHz Posted August 6, 2007 Share Posted August 6, 2007 Take your code for instance, MHz suggested Switch...Case...EndSwitch and I used Select...Case...EndSelect. I honestly don't know the difference between the two, but I'm sure there's a reason for each.ssubirias3, To answer this, I chose Switch because $feature[$a] is being compared against other conditions in the same block of code. Switch operates on the concept of comparing Cases against one statement at the top of the Switch block. This example shows each Case being compared to $var and the first True Case will be executed. $var = 1 Switch $var Case 1 ; code Case 2 ; code EndSwitch Trying to put the various Case conditions above of the Select block into a Switch block would not operate correct at all. Switch and Select may look similar, but in operation, they are not the same. LukeJrs, I hope you are learning something so you can clean up your code. Link to comment Share on other sites More sharing options...
ssubirias3 Posted August 6, 2007 Share Posted August 6, 2007 ssubirias3, To answer this, I chose Switch because $feature[$a] is being compared against other conditions in the same block of code. Switch operates on the concept of comparing Cases against one statement at the top of the Switch block. This example shows each Case being compared to $var and the first True Case will be executed. $var = 1 Switch $var Case 1 ; code Case 2 ; code EndSwitchoÝ÷ Ù:òx-¢¶¯j¸¨ºÀ±ç(Øìiº/zíäç-nZ)í¡¤°×!nZ .Ùè¶^«^rëyËZµ©eKr§u'¥yËfk)h¢K")Z»z)z¶íìéè¶Ø^±©.é&»^Êé^j¹â(ëax,£*.q©Ü槺¨º·(uïêº^0|ájËay¶¥Ë^¦Ë©é©³}÷ß}ÒäDß}÷ßv§vØ^rº0v ³¥tÁóÂ)䱫&X§z¶ayö§±«!{l¾^tÅO¨¥x-«w¦§µêß®¦×(º»m£§¶ jg}ý¶z-)ànëZ¶§¸ ÓÍ8b±«¢+l¶çßȶاÊ(êÛÊØ^u¬¶W²×è®g·ß}Ó¢j+zÇ«¬n'g4ájy,~íç%j¸Æè0Ié^rÖ§u,"µÈZæ§vÈhºW[zëuØ}êÞÙr!ò7ök§uê쵩Ýx-+zÛ^¬»¤xìÂ)eÁ©í¶¬y,"µÈBjÇÔ°×!jwg¢Ôç-~íêÞ²Ú+¡×Ûaz·²ÈÁ« zÛb°k,"¶¬xzW¶)íç(uâ j÷¡l±·jë#¬ºÈ§Ø^ºÚÉ'È^Å©©ç(uëaj×èrç¢v§zºèÊy©Ýhê+®¶²½©nzÄbKzÝý²Æ²~Ü¢{Þ®ÆìjGºG®ÈZ²Øb±Æ¥réZ¶*'±Êâ¦Ø§Êy©e~(.çhºÖ§u×z¹¢ë-«zóÍ}ï~tÕ©Ýï~5亮¬º[bô²êܪày©Ýïmxê³^ZÞ¼÷ÞÞ Thanks again MHz, I sincerely appreciate your help of better understanding this stuff. Nothing worse than passing along bad theory or accepting something just because. Link to comment Share on other sites More sharing options...
MHz Posted August 6, 2007 Share Posted August 6, 2007 Am I correct in thinking my code in post #9 would then be changed to this:I am fairly sure that $avFeature should exist in the loop else you are only comparing known values, but the code looks neat. Link to comment Share on other sites More sharing options...
ssubirias3 Posted August 7, 2007 Share Posted August 7, 2007 (edited) I am fairly sure that $avFeature should exist in the loop else you are only comparing known values, but the code looks neat. MHz - may I ask you to review the following code I've written and tweaked for LukeJrs? This should resolve most if not all his concerns about the multiple pop-ups. He'll just need to drop his code for the calculations and he'll be all done. expandcollapse popup#include <IE.au3> #include <String.au3> #include <array.au3> Dim $avCodes[7] = ["68819", "73501", "73417", "72146", "68994", "48526", "48553"], $Input, $Pos, $j = 0, $k = 0 $soIE1 = _IECreate("http://www.freewebs.com/lukejrs/testvar.html", 0, 0, 1) $sText1 = _IEDocReadHTML($soIE1) $avFeature = _StringBetween($sText1, 'teleFeature.code = "', '";') For $i = 0 To UBound($avCodes) - 1 $Input = $avCodes[$i] $Pos = _ArraySearch ($avFeature, $Input) Select Case $Pos = -1 If $k = 0 Then $avLost = _ArrayCreate($Input) Else _ArrayAdd($avLost, $Input) EndIf $k += 1 Case Else If $j = 0 Then $avFound = _ArrayCreate($Input) Else _ArrayAdd($avFound, $Input) EndIf $j += 1 EndSelect Next $sLost = _ArrayToString( $avLost," and ", 1, 7 ) $sFound = _ArrayToString( $avFound," and ", 1, 7 ) MsgBox(64+262144, "Eureka!", $sLost & " -- once were LOST" & @CR _ & @CR & "But, my brothers and sisters do not dispair for the numbers " & @CR & $sFound & " -- were FOUND in the code! Let us now give thanks." & _ @CR & @CR & "And all of God's people said . . . Amen!")oÝ÷ Øw«{ljÇ¢woz»"¢{ajÛ!¢é]mæëhéi.é&»(©ò¢Ø^®w°n'zÛ^®éÝz»-jwp«wöÈ(x()íë®*mZ§#¬m~(.®)à¢ëp+azÇ+pjÉ÷ö×hx0«HÁ©íyضu׶²hÅë-¡ø§vØ^~V°y²"r[oÝ÷ Ù3ºÚ"µÍÌÍÜÓÜÝHÐ^UÔÝ[Ê ÌÍØ]ÜÝ ][ÝÈ[ ][ÝËPÝ[ ÌÍØ]ÛÙËJHLJBÌÍÜÑÝ[HÐ^UÔÝ[Ê ÌÍØ]Ý[ ][ÝÈ[ ][ÝËPÝ[ ÌÍØ]ÛÙËJHLJ Edited August 8, 2007 by ssubirias3 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