Jump to content

Why wont this loop work?


Recommended Posts

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.

#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

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 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)

userbar.png

Link to comment
Share on other sites

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

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 by GlennRogers
Link to comment
Share on other sites

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 by GlennRogers
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...