GlennRogers Posted October 1, 2013 Share Posted October 1, 2013 Hi everyone, im trying to get a loop working for Func Criteria() . It gets the variable from a string in the html. When I display the variable is a message box I only get numbers returned so i'm not sure why It isnt looping? Thanks in advance. expandcollapse popup#include <GuiConstantsEx.au3> #include <EditConstants.au3> #include <IE.au3> #include <Misc.au3> #include <Process.au3> #region ---Au3Recorder generated code Start (v3.3.7.0) --- #region --- Internal functions Au3Recorder Start --- Func Au3RecordSetup() Opt('WinWaitDelay', 100) Opt('WinDetectHiddenText', 1) Opt('MouseCoordMode', 0) EndFunc ;==>Au3RecordSetup Func _WinWaitActivate($title, $text, $timeout = 0) WinWait($title, $text, $timeout) If Not WinActive($title, $text) Then WinActivate($title, $text) WinWaitActive($title, $text, $timeout) EndFunc ;==>_WinWaitActivate Au3RecordSetup() HotKeySet("{ESC}", "Terminate") $oIE = _IECreate("http://hello.com", 1) _IELoadWait($oIE, 1000) $HWND = _IEPropertyGet($oIE, "hwnd") WinSetState($HWND, "", @SW_MAXIMIZE) _IELoadWait($oIE, 1000) Local $rbsca = "2007" ; Values for options in optionselect drop down Local $rbray = "2009" Local $rbgcc = "2008" Local $rbbcf = "5005" Global $RadioValue = '' Global $fraBottom = _IEFrameGetObjByName($oIE, "fraBottom") Global $fraRight = _IEFrameGetObjByName($fraBottom, "fraRight") Global $fraNavigator = _IEFrameGetObjByName($fraBottom, "fraNavigator") Global $Choose = GUICreate("SKU and product brand", 399, 314, 409, 311) Global $SCA = GUICtrlCreateRadio("SCA/V1", 200, 192, 65, 17) Global $RAY = GUICtrlCreateRadio("RAYS/V1", 296, 192, 65, 17) Global $GCC = GUICtrlCreateRadio("GCC/V1", 200, 232, 65, 17) Global $BCF = GUICtrlCreateRadio("BCF/V1", 296, 232, 65, 17) Global $OK = GUICtrlCreateButton("OK", 72, 272, 75, 25) Global $Cancel = GUICtrlCreateButton("Cancel", 216, 272, 75, 25) Global $Label1 = GUICtrlCreateLabel("Enter a SKU and choose which brand it belongs to.", 16, 96, 246, 33) Global $input = GUICtrlCreateInput("", 48, 160, 121, 21) Global $Label2 = GUICtrlCreateLabel("SKU:", 16, 160, 29, 17) Global $Label3 = GUICtrlCreateLabel("Brand:", 200, 160, 35, 17) Global $Label4 = GUICtrlCreateLabel("Note: Push ESC to stop", 24, 200, 116, 17) Global $Pic1 = GUICtrlCreatePic("C:\Documents and Settings\GlennR\Desktop\hello555.bmp", 176, 8, 217, 73) Global $RadioValue = '' GUISetState(@SW_SHOW) While 1 ; Switch GUIGetMsg() ; Switch is much easier to code than Select if all the checks are on the same variable Case $GUI_EVENT_CLOSE, $Cancel Exit Case $OK ; Read the input <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $sKey = GUICtrlRead($input) GUIDelete($Choose) ExitLoop Case $SCA $RadioValue = $rbsca ; If the $GCC radio button is selected then $RadioValue = "2008" Case $RAY $RadioValue = $rbray Case $GCC $RadioValue = $rbgcc Case $BCF $RadioValue = $rbbcf EndSwitch WEnd MsgBox(262144, "SKU", $sKey) Sleep(2000) Global $TextInput = _IEGetObjByName($fraNavigator, "txtMenuInpt") _IEAction($TextInput, "focus") Sleep(1000) _IEFormElementSetValue($TextInput, "Carton Maintenance") Sleep(500) Send("{DOWN}") Sleep(500) Send("{DOWN}") Sleep(500) Send("{ENTER}") _IELoadWait($oIE) Sleep(1000) _IELoadWait($oIE) Sleep(5000) Global $fraCriteria = _IEFrameGetObjByName($fraRight, "fraCriteria") Global $oForm = _IEFormGetObjByName($fraCriteria, "CRITERIA_FORM") Local $oWarehouse = _IEFormElementGetObjByName($oForm, "MANH_CO_DIV") Local $SCAwh = _IEFormElementOptionSelect($oWarehouse, "2007", 1, "byValue") _IEFormElementOptionSelect($oWarehouse, $RadioValue, 1, "byValue") ; Will select an option from the dropdown based on which radio button is selected Local $oFrom = _IEFormElementGetObjByName($oForm, "CR_FROM_STAT_CODE") _IEFormElementOptionSelect($oFrom, "10", 1, "byValue") Local $oTo = _IEFormElementGetObjByName($oForm, "CR_TO_STAT_CODE") _IEFormElementOptionSelect($oTo, "10", 1, "byValue") Local $SKU = _IEFormElementGetObjByName($oForm, "SKU_ID_STYLE") _IEAction($SKU, "focus") Sleep(250) Send($sKey) Sleep(500) Send("{ENTER}") Sleep(6000) Global $fraData = _IEFrameGetObjByName($fraRight, "fraData") $sNumloops = _IEBodyReadHTML($fraData) Global $record = StringInStr($sNumloops, 'record(s)') Global $oresult = StringMid($sNumloops, ($record - 5), 4) Replace() Func Replace() Global $sOutput = StringRegExpReplace($oresult,'[xt>]', "") EndFunc ;MsgBox(0, "hiya", $sOutput) Local $export = _IEGetObjById($fraData, "bExport") Local $iScreenX = _IEPropertyGet($export, "screenx") Local $iScreenY = _IEPropertyGet($export, "screeny") Local $iWidth = _IEPropertyGet($export, "width") Local $iHeight = _IEPropertyGet($export, "height") MouseClick("left", $iScreenX + $iWidth / 2, $iScreenY + $iHeight / 2, 1, 10) Sleep(500) _WinWaitActivate("Message from webpage", "") Sleep(1000) Send("{ENTER}") _WinWaitActivate("File Download", "") Sleep(500) Send("{LEFT}") Sleep(250) Send("{ENTER}") _WinWaitActivate("Save As", "") Sleep(250) Send("Cancelsku") Sleep(250) Send("{ENTER}") Sleep(1000) Send("{LEFT}") Sleep(250) Send("{ENTER}") _WinWaitActivate("Download complete", "") Send("{LEFT}") Sleep(250) Send("{LEFT}") Sleep(250) Send("{LEFT}") Sleep(250) Send("{ENTER}") Sleep(4000) _WinWaitActivate("Microsoft Excel","") sleep(250) _WinWaitActivate("Warehouse Management Web - Windows Internet Explorer", "") _WinWaitActivate("Microsoft Excel","") sleep(250) func criteria() $i = 0 While ($i < $sOutput) Send("{CTRLDOWN}c{CTRLUP}") Sleep(250) _WinWaitActivate("Warehouse Management Web - Windows Internet Explorer", "") _IEAction($TextInput, "focus") Sleep(1000) _IEFormElementSetValue($TextInput, "Carton Maintenance") Sleep(500) Send("{DOWN}") Sleep(500) Send("{DOWN}") Sleep(500) Send("{ENTER}") _IELoadWait($oIE) Sleep(3000) local $paste = ClipGet() $carton = _IEFormElementGetObjByName($oForm,"CARTON_HDR__CARTON_NBR") $cart = _IEFormElementSetValue($carton, $paste) $sPageContents = _IEBodyReadHTML($fraData) Local $iPosStart = StringInStr($sPageContents, $sKey) Local $iPosEnd = StringInStr($sPageContents, 'units', 0, 2, $iPosStart) Local $sLine = StringMid($sPageContents, $iPosStart, $iPosEnd - $iPosStart) Local $sResult = StringRight($sLine, StringLen($sLine) - StringInStr($sLine, '"', 0, -1)) $i = ($i + 1) WEnd EndFunc Func Terminate() Exit 0 EndFunc ;==>Terminate #endregion --- Internal functions Au3Recorder Start --- Link to comment Share on other sites More sharing options...
Astormooke Posted October 1, 2013 Share Posted October 1, 2013 (edited) Welcome to the forum! Have you tried: While ( $i < (int($sOutput))) I have had problems with integers that get confused as strings in the past. Hope that helps!  Reference: Function int() Edited October 1, 2013 by Astormooke Link to comment Share on other sites More sharing options...
TheSaint Posted October 1, 2013 Share Posted October 1, 2013 (edited) Have you temporarily tried using Msgboxes strategically placed throughout your script, to report on values being determined? Or if that interferes with processing, temporarily have the same values written to keys in an ini file for you to check afterward ... or line by line into a text file, maybe using _FileWriteLog to get times, etc. Outside of the Console, that's two of the best ways to help with troubleshooting. Edited October 1, 2013 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
GlennRogers Posted October 1, 2013 Author Share Posted October 1, 2013 Im definently getting a number when I display $sOutput in a msg box. Also tried adding int before it but its still not working.. Link to comment Share on other sites More sharing options...
Astormooke Posted October 1, 2013 Share Posted October 1, 2013 Honestly im not sure how you are getting a integer as the function StringRegExpReplace returns a string. Unless without those characters all that is left is numbers inwhich case it requires casting to an int... Global $sOutput = int(StringRegExpReplace($oresult,'[xt>]', "")) I know it seems to be the same as what I had before but Autoit is finicky with some nested functions. Also if that doesnt work I would suggest trying to replace white spaces as well just to be sure there isnt a space somewhere in there. Link to comment Share on other sites More sharing options...
GlennRogers Posted October 1, 2013 Author Share Posted October 1, 2013 Thanks mate I'll try it now and let you know. Link to comment Share on other sites More sharing options...
MHz Posted October 1, 2013 Share Posted October 1, 2013 Here is a test $sOutput = '1' criteria() func criteria() $i = 0 While ($i < $sOutput) Sleep(1000) ConsoleWrite('loop' & @CRLF) WEnd EndFunc Appears to loop OK. I notice the full posted code has only 1 instance of the word criteria in it. GlennRogers, how are you calling the function to do the loop? Link to comment Share on other sites More sharing options...
GlennRogers Posted October 1, 2013 Author Share Posted October 1, 2013 your a genius. It's always the tiniest thing that I overlook. Thanks for the help everyone I have it working. Link to comment Share on other sites More sharing options...
MHz Posted October 1, 2013 Share Posted October 1, 2013 Thanks, and I agree. Even though my tiny example does not reflect on what Astormooke suggests. Casting a string to a number is a good idea in a mathematical test to help ensure correct behavior. Link to comment Share on other sites More sharing options...
GlennRogers Posted October 1, 2013 Author Share Posted October 1, 2013 (edited) Quick question. As my script is navigating to different links within the URL, some frames become visible and non visible at different times. If I declare a frame as a variable then navigate away where its no longer visible, but come back to where it is visible again, do i need to re-declare these frames as new variables? i'm getting errors when I try to reference objects in these frames, even though they worked perfect the first time. I hope that makes sense. $fradData and $fraCriteria are the ones giving me problems. EDIT: I just tried making all my variable frames again with new names but still gave me errors Edited October 1, 2013 by GlennRogers Link to comment Share on other sites More sharing options...
GlennRogers Posted October 1, 2013 Author Share Posted October 1, 2013 (edited) I'll try explain it a little better. The $sNumloops variable works fine which is higher up in my code. $sNumloops = _IEBodyReadHTML($fraData) After this the script navigates through a few different links, $fraData is no longer present in the HTML. (URL always stays the same) Then It navigates to a link where $fraData is visible again. $sPageContents = _IEBodyReadHTML($fraData) But when It gets to the above code it crashes. I get the error "The requested action with this object has failed" It's got me stumped because it's basically doing the same thing just at a later stage. Edited October 1, 2013 by GlennRogers 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