Jump to content

Sleep variables and IE Error event help


Recommended Posts

Hi All,

I've been using Autoit for a few weeks now and have been reading this forum quite alot to find the information I need. But now I'm stuck and I'm hoping some of you could help me out.

The purpose of my program is to launch 5 seperate programs depending on whether a radio button is selected. I'm able to determine which radio button is selected and when I click "go" it runs the script. Program #1 takes information from a cell in excel, then in an Internet Explorer window , enters the data from the excel sheet into a box and clicks okay. The webpage i'm viewing will check to see if that data has been entered before, if it is it opens up a message saying that the data is already there. Before running the script I ask the user how many times the script should loop because there could be quite a few things in the excel sheet that need entered.

I've also created a slider bar on the main window which I'm trying use to control teh delay times as some of the people have slower connections/computers than user and may need toa djust the speed of the script to avoid errors.

I have a few problems that I can't seem to find the answer to.

1) Can I use variables in Sleep() ? Right now I specify the the sleep times manually, but I'm trying to increase or decrease these times using the value from the slider by entering Sleep($Sleepvar) but when I run it it doesn't seem to recognize it. Any ideas?

2) In Program #1 there are two places where my script may run into a snag. If the data being entered into my website I'll get a response back. I figured out how to identify when that occurs and pass the line. The only problem is when there are two lines in my spreadsheet that already exists things break :s Is there a way I can restart the script or Go to the start when this error occurs? Is there a better way to do what I'm trying to do?

3) Using the winwait/winactive commands can I insert a variable for Autoit to search the screen for?

For example: in one of my error loops the response that I get back from IE is a standard msg box that contains "What I copied from by excel sheet Site Already exists please try again."

I can't seem to get the right syntax but this is what I'm trying to do

WinActive("Microsoft Internet Explorer", ""$variablefromclipboard" Site already exists please try again.")

Has anyone tried this?

I apologize for the length of my code, If you would like me to shorten it I can try.

Thanks in advance!

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Release
; Version: 2.0001 (Alpha)
;
; Script Function:
;   Creates NPSi Sites, NPSi Summaries and orders materials in SAP for the BBB program.
;
; CTRL + ALT + X to close the program at any time.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



#include <Misc.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <SliderConstants.au3>
#include <TabConstants.au3>
#include <ButtonConstants.au3>
#include <GuiSlider.au3>

; Check to see if the script is running and close it after notifying the user.

If _Singleton("MyScriptName", 1) = 0 Then
    MsgBox(0, "Script Name", "This program is already running. Having more than one copy open is not allowed.")
    Exit
EndIf

; Set CTRL + ALT + X hotkey to close program.

HotKeySet("^!x", "MyExit")

Func MyExit()
    Exit
EndFunc;==>MyExit





$DAPP = GUICreate("DAPP Machine 2.0", 653, 513, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_GROUP, $WS_BORDER, $WS_CLIPSIBLINGS))
GUISetCursor(2)
;Drop-down menu items
$MenuItem1 = GUICtrlCreateMenu("&File")
$MenuItem2 = GUICtrlCreateMenuItem("&Options", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenuItem("E&xit", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenu("&-")
$MenuItem6 = GUICtrlCreateMenuItem("&Hotkeys", $MenuItem5)
$MenuItem7 = GUICtrlCreateMenuItem("", $MenuItem5)
$MenuItem8 = GUICtrlCreateMenuItem("About", $MenuItem5)

;Instructions table
;Use this to be able to edit text boxes in the table:     GUICtrlSetState(-1, @SW_SHOW )
$InstructionsLabel = GUICtrlCreateLabel("Instructions:", 16, 16, 74, 17)
GUICtrlSetFont(-1, 8, 800, 4, "MS Sans Serif")
$Tab = GUICtrlCreateTab(16, 40, 332, 305)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$Order = GUICtrlCreateTabItem("Program #1")
GUICtrlCreateEdit("", 23, 73, 321, 265, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
GUICtrlSetData(-1, StringFormat("This is where i'll write instructions for Program #1."))
GUICtrlSetState(-1, $GUI_SHOW)
$Sites = GUICtrlCreateTabItem("Program #2")
GUICtrlCreateEdit("", 23, 73, 321, 265, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
GUICtrlSetData(-1, StringFormat("This is where i'll write instructions for Program #2."))
GUICtrlSetState(-1, $GUI_SHOW)
$Single = GUICtrlCreateTabItem("Program #3")
GUICtrlCreateEdit("", 23, 73, 321, 265, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
GUICtrlSetData(-1, StringFormat("This is where i'll write instructions for Program #3."))
GUICtrlSetState(-1, $GUI_SHOW)
$Double = GUICtrlCreateTabItem("Program #4")
GUICtrlCreateEdit("", 23, 73, 321, 265, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL))
GUICtrlSetData(-1, StringFormat("This is where i'll write instructions for Program #4."))
GUICtrlSetState(-1, $GUI_SHOW)
GUICtrlCreateTabItem("")

;Radio Buttons to select which program.
$RadioGroup = GUICtrlCreateGroup("What do you want to Do?", 392, 32, 217, 201)
$Radio1 = GUICtrlCreateRadio("Run Program #1", 417, 62, 169, 17)
$Radio2 = GUICtrlCreateRadio("Run Program #2", 417, 89, 177, 17)
$Go = GUICtrlCreateButton("Go!", 459, 196, 75, 25, 0)

;Speedvar slider
GUICtrlCreateGroup("", -99, -99, 1, 1)
$SpeedLabel = GUICtrlCreateLabel("Speed Settings", 432, 352, 128, 24)
GUICtrlSetFont(-1, 12, 800, 4, "MS Sans Serif")
$Slider = GUICtrlCreateSlider(409, 385, 174, 45, BitOR($TBS_BOTTOM, $WS_TABSTOP), BitOR($GUI_SS_DEFAULT_SLIDER, $WS_EX_CLIENTEDGE))
GUICtrlSetData($Slider, 2)
GUICtrlSetLimit(-1, 4, 0)
GUICtrlSetTip(-1, "Adjust the speed in which the program runs.")

$Fasticon = GUICtrlCreateIcon(@ScriptDir & "\rabbit.ico", 0, 357, 389, 36, 28)
$Slowicon = GUICtrlCreateIcon(@ScriptDir & "\turtle.ico", 0, 605, 389, 36, 36)
;Company Logo & About link.
;$Logo = GUICtrlCreatePic(@ScriptDir & "\about.jpg", 16, 375, 284, 100, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
;GUICtrlSetTip(-1, "Click for About")
;GUICtrlSetCursor(-1, 4)
;GUICtrlSetFont(-1, 8, 800, 4, "MS Sans Serif")

;Display Exit Hotkey on the main GUI window.
$Exitlabel = GUICtrlCreateLabel("Press CTRL + ALT + X at anytime to stop this program.", 376, 260, 261, 17)
GUISetState(@SW_SHOW)


;Find out whether or not the user clicked on the File-Exit button, if they did kill the main window.
GUISetState()
Do
    $msg1 = GUIGetMsg()
    If $msg1 = $MenuItem4 Then
        Exit


    ElseIf $msg1 = $Go Then

; After the user clicked Go read the value from the slider and enter the sleep times associated with each option.

        $Speedvar = ''

        Switch GUIGetMsg()
            Case $Slider
                $Speedvar = GUICtrlRead($Slider)
                Switch GUICtrlRead($Slider)
                    Case "0"
                        If $Speedvar = "0" Then $Speedvar = 10000
                    Case "1"
                        If $Speedvar = "1" Then $Speedvar = 15000
                    Case "2"
                        If $Speedvar = "2" Then $Speedvar = 20000
                    Case "3"
                        If $Speedvar = "3" Then $Speedvar = 40000
                    Case "4"
                        If $Speedvar = "4" Then $Speedvar = 50000
                    Case Else
                EndSwitch
            Case Else
        EndSwitch


;----------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------
; Check to see if the Radio button for Program #1 is selected and the go button was pushed.
;----------------------------------------------------------------------------------------------
        Select
            Case GUICtrlRead($Radio1) = $gui_checked

    ; Prompt the user to run the script - With a Yes/No prompt

                $answer = MsgBox(4, "Program #1", "This Program will.")


    ; Check the user's answer to the prompt
    ; If "No" was clicked then exit the script
                If $answer = 7 Then
                    MsgBox(4096, "Program #1", "OK.  Bye!")
                    Exit
                EndIf

    ; Present user with a textbox to enter how many consecutive times to run the script.

                $Program1endvariable = InputBox("Program #1", "How Many times doy ou want to run this program? Exit key sequence for script halt CTRL + ALT + x", "Enter Number Here.", " M3")
                If @error = 1 Then
                    MsgBox(4096, "Error", "You really want to Cancel? Okay!")
                    Exit
                EndIf

                If @error = 0 Then
                    Do

                        $loopA = 0;Start count variable.
                        $loopEnd = $Program1endvariable;Specify variable to define when loop is to be completed. (user driven).



            ; Start Executing NPSi Command Functions.

                        Sleep(2000)
                        Opt("WinWaitDelay", 100)
                        Opt("WinTitleMatchMode", 4)
                        Opt("WinDetectHiddenText", 1)
                        Opt("MouseCoordMode", 0)
                        WinWait("Microsoft Excel", "")
                        If Not WinActive("Microsoft Excel", "") Then WinActivate("Microsoft Excel", "")
                        WinWaitActive("Microsoft Excel", "")
                        Sleep(400)
                        Send("^c")
                        Sleep(1000)
                        WinWait("MySite - Microsoft Internet Explorer", "")
                        If Not WinActive("MySite - Microsoft Internet Explorer", "") Then WinActivate("MySite - Microsoft Internet Explorer", "")
                        WinWaitActive("MySite - Microsoft Internet Explorer", "")
                        Sleep(1000)
                        MouseMove(142, 63)
                        Sleep(1000)
                        MouseClick("left")
                        MouseMove(139, 121)
                        Sleep(1000)
                        MouseClick("left")
                        Sleep(1000)
                        Send("^v")
                        Sleep(2000)
                        Send("{ENTER}")
                        Sleep(2000)


            ;Error sequence #1 - Check to see If Delay time wasn't set long enough and something went wrong.


                        If WinActive("Microsoft Internet Explorer", "Please add site first") Then
                            Sleep(1000)
                            WinWait("Microsoft Internet Explorer", "Please add site first")
                            If Not WinActive("Microsoft Internet Explorer", "Please add site first") Then WinActivate("Microsoft Internet Explorer", "Please add site first")
                            WinWaitActive("Microsoft Internet Explorer", "Please add site first")

                ;Close the error message box and run the script again hoping that the cache speeds things up a second time.

                            Sleep(1000)
                            Send("{ENTER}")
                            Sleep(2000)
                            WinWait("MySite - Microsoft Internet Explorer", "")
                            If Not WinActive("MySite - Microsoft Internet Explorer", "") Then WinActivate("MySite - Conversion Profile - Microsoft Internet Explorer", "")
                            WinWaitActive("MySite - Conversion Profile - Microsoft Internet Explorer", "")
                            Sleep(1000)
                            MouseMove(142, 63)
                            Sleep(1000)
                            MouseClick("left")
                            Sleep(200)
                            MouseMove(139, 121)
                            MouseClick("left")
                            Sleep(1000)
                            Send("^v")
                            Sleep(2000)
                            Send("{ENTER}")
                            Sleep(200)



                ;Error Sequence #2 - If site already exists in the system close the error box and go to the next site on the spreadsheet.


                        ElseIf WinActive("Microsoft Internet Explorer", " Site already exists please try again.") Then
                            Sleep(1000)
                            Send("{ENTER}")
                            Sleep(1000)
                            WinWait("Microsoft Excel.XLS", "")
                            If Not WinActive("Microsoft Excel.XLS", "") Then WinActivate("Microsoft Excel.XLS", "")
                            WinWaitActive("Microsoft Excel.XLS", "")
                            Sleep(400)
                            Send("{DOWN}")
                            Sleep(100)
                            Send("^c")
                            Sleep(1000)
                            WinWait("MySite - Microsoft Internet Explorer", "")
                            If Not WinActive("MySite - Microsoft Internet Explorer", "") Then WinActivate("MySite - Microsoft Internet Explorer", "")
                            WinWaitActive("MySite - Microsoft Internet Explorer", "")
                            Sleep(1000)
                            MouseMove(142, 63)
                            Sleep(1000)
                            MouseClick("left")
                            MouseMove(139, 121)
                            MouseClick("left")
                            Sleep(1000)
                            Send("^v")
                            Sleep(2000)
                            Send("{ENTER}")
                            Sleep(3000)
                            Send("{TAB}5{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}p{TAB}r{TAB}4{TAB}{TAB}{TAB}{TAB}{ENTER}")
                            Sleep(1000)
                            WinWait("Microsoft Internet Explorer", "New site added for ")
                            If Not WinActive("Microsoft Internet Explorer", "New site added for ") Then WinActivate("Microsoft Internet Explorer", "New site added for ")
                            WinWaitActive("Microsoft Internet Explorer", "New site added for ")
                            Sleep(1000)
                            Send("{ENTER}")
                            Sleep(1000)
                            WinWait("MySite - Microsoft Internet Explorer", "")
                            If Not WinActive("MySite - Microsoft Internet Explorer", "") Then WinActivate("MySite - Microsoft Internet Explorer", "")
                            WinWaitActive("MySite - Microsoft Internet Explorer", "")
                            MouseMove(206, 68)
                            MouseDown("left")
                            MouseUp("left")
                            Sleep(100)
                            MouseMove(145, 123)
                            MouseDown("left")
                            MouseUp("left")
                            Sleep(1000)
                            Send("cab{TAB}{TAB}{TAB}{ENTER}")
                            Sleep(1000)

                ;Wait for IE prompt to say the floor was added successfully, close the acknowledge window and go back to the spreadsheet and continue.
                            WinWait("Microsoft Internet Explorer", "Floor CAB added to ")
                            If Not WinActive("Microsoft Internet Explorer", "Floor CAB added to ") Then WinActivate("Microsoft Internet Explorer", "Floor CAB added to ")
                            WinWaitActive("Microsoft Internet Explorer", "Floor CAB added to ")
                            Send("{Enter}")
                            Sleep(1000)
                            WinWait("Microsoft Excel", "Worksheet Menu Bar")
                            If Not WinActive("Microsoft Excel", "Worksheet Menu Bar") Then WinActivate("Microsoft Excel", "Worksheet Menu Bar")
                            WinWaitActive("Microsoft Excel", "Worksheet Menu Bar")
                            Sleep(1000)
                            Send("{DOWN}")
                            Sleep(200)

                ;If there the previous site didn't already exist and the latency wasn't an issue then continue creating the site.
                        Else
                            WinWait("MySite - Microsoft Internet Explorer", "")
                            If Not WinActive("MySite - Microsoft Internet Explorer", "") Then WinActivate("MySite - Microsoft Internet Explorer", "")
                            WinWaitActive("MySite - Microsoft Internet Explorer", "")
                            Sleep(2000)
                            Send("{TAB}5{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}p{TAB}r{TAB}4{TAB}{TAB}{TAB}{TAB}{ENTER}")
                            Sleep(1000)
                ;Wait for successful acknowledgment message, close it and proceed.
                            WinWait("Microsoft Internet Explorer", "New site added for ")
                            If Not WinActive("Microsoft Internet Explorer", "New site added for ") Then WinActivate("Microsoft Internet Explorer", "New site added for B")
                            WinWaitActive("Microsoft Internet Explorer", "New site added for ")
                            Sleep(1000)
                            Send("{ENTER}")
                            Sleep(1000)
                            WinWait("MySite - Microsoft Internet Explorer", "")
                            If Not WinActive("MySite - Microsoft Internet Explorer", "") Then WinActivate("MySite - Microsoft Internet Explorer", "")
                            WinWaitActive("MySite - Microsoft Internet Explorer", "")
                            MouseMove(206, 68)
                            MouseDown("left")
                            MouseUp("left")
                            Sleep(100)
                            MouseMove(145, 123)
                            MouseDown("left")
                            MouseUp("left")
                            Sleep(1000)
                            WinWait("MySite - Microsoft Internet Explorer", "")
                            If Not WinActive("MySite - Microsoft Internet Explorer", "") Then WinActivate("MySite - Microsoft Internet Explorer", "")
                            WinWaitActive("MySite - Microsoft Internet Explorer", "")
                            Send("cab{TAB}{TAB}{TAB}{ENTER}")
                            Sleep(1000)
                ;Wait for successful message from IE that the floor was added successfully, acknowledge it and move to the next line in the spreadsheet.
                            WinWait("Microsoft Internet Explorer", "Floor CAB added to ")
                            If Not WinActive("Microsoft Internet Explorer", "Floor CAB added to ") Then WinActivate("Microsoft Internet Explorer", "Floor CAB added to ")
                            WinWaitActive("Microsoft Internet Explorer", "Floor CAB added to ")
                            Send("{Enter}")
                            Sleep(1000)
                            WinWait("Microsoft Excel", "Worksheet Menu Bar")
                            If Not WinActive("Microsoft Excel", "Worksheet Menu Bar") Then WinActivate("Microsoft Excel", "Worksheet Menu Bar")
                            WinWaitActive("Microsoft Excel", "Worksheet Menu Bar")
                            Sleep(1000)
                            Send("{DOWN}")
                            Sleep(200)
                        EndIf
            ; Site was created Successfully increase the loopcount and repeat.
                        $loopA = $loopA + 1
                        Sleep(200)

            ;Stop Looping until the User Value is met.
                    Until $loopA = $loopEnd
                EndIf





    ; Display Message to user that program is finished and refocus on main Program window.
                MsgBox(0, "Program#1", "Finished!")
                WinActivate("DAPP Machine 2.0")
    ;----------------------------------------------------------------------------------------------
    ;------------------------------Finished Program #1 Script----------------------------------
    ;----------------------------------------------------------------------------------------------

    ;----------------------------------------------------------------------------------------------
    ;----------------------------------------------------------------------------------------------
    ;----------------------------------------------------------------------------------------------
    ; Check to see if the Radio button for Program #2 is selected and the go button was pushed.
    ;----------------------------------------------------------------------------------------------

            Case GUICtrlRead($Radio2) = $gui_checked

    ; Prompt the user to run the script - With a Yes/No prompt

                $answer2 = MsgBox(4, "Program #2", "This Program will.")


    ; Check the user's answer to the prompt
    ; If "No" was clicked then exit the script
                If $answer2 = 7 Then
                    MsgBox(4096, "Program #2", "OK.  Bye!")
                    Exit
                EndIf

    ; Present user with a textbox to enter how many consecutive times to run the script.

                $Program2endvariable = InputBox("Program #2", "How Many times doy ou want to run this program? Exit key sequence for script halt CTRL + ALT + x", "Enter Number Here.", " M3")
                If @error = 1 Then
                    MsgBox(4096, "Error", "You really want to Cancel? Okay!")
                    Exit


                ElseIf @error = 0 Then
                    $loopA2 = 0;Start count variable.
                    $loopEnd2 = $Program2endvariable;Specify end variable that is user defined.

                    Do; Start Executing Program #2 functions.


                        Opt("WinTextMatchMode", 2)
                        Opt("WinWaitDelay", 100)
                        Opt("WinTitleMatchMode", 4)
                        Opt("WinDetectHiddenText", 1)
                        Opt("MouseCoordMode", 0)
                        WinWait("Untitled - Notepad", "")
                        If Not WinActive("Untitled - Notepad", "") Then WinActivate("Untitled - Notepad", "")
                        WinWaitActive("Untitled - Notepad", "")
                        Sleep($Speedvar)
                        Send("asdf")
                        Sleep($Speedvar)

            ; Program #2 ran successfully.
                        $loopA2 = $loopA2 + 1
                        Sleep(200)

            ;Stop Looping until User Value is met.
                    Until $loopA2 = $loopEnd2
                EndIf


    ; Display Message to user that program is finished and refocus on main Program window.
                MsgBox(0, "Program#2", "Finished!")
                WinActivate("DAPP Machine 2.0")
    ;----------------------------------------------------------------------------------------------
    ;------------------------------Finished Program #2 Script--------------------------------------
    ;----------------------------------------------------------------------------------------------

    ;----------------------------------------------------------------------------------------------
    ;----------------------------------------------------------------------------------------------
    ;----------------------------------------------------------------------------------------------
    ; Check to see if no radio buttons are selected and Go! button is pushed.
    ;----------------------------------------------------------------------------------------------
            Case GUICtrlRead($Radio1) = $gui_unchecked And GUICtrlRead($Radio2) = $gui_unchecked                MsgBox(0, "None Selected", "Please select a program before clicking Go.")

        EndSelect


    ElseIf $msg1 = $MenuItem8 Then
;   ElseIf $msg1 = $MenuItem8 Or $msg1 = $Logo Then

; About GUI Window dimensions and components.
;-------------------------------------------------------------------------------------------------
        $Aboutwindow = GUICreate("DAPP Machine 2.0 - About", 324, 232, 314, 231, BitOR($WS_CAPTION, $WS_POPUP, $WS_BORDER, $WS_CLIPSIBLINGS))
;$Pic1 = GUICtrlCreatePic(@ScriptDir & "\me.jpg", 16, 24, 132, 156, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
        $GroupBox1 = GUICtrlCreateGroup("", 8, 8, 305, 185)
        $label1 = GUICtrlCreateLabel("DAPP Machine", 160, 24, 77, 17, $WS_GROUP)
        $Label2 = GUICtrlCreateLabel("Version 2.0", 160, 48, 57, 17, $WS_GROUP)
        $Label3 = GUICtrlCreateLabel("Created By: Me", 160, 72, 143, 17, $WS_GROUP)
        $Label4 = GUICtrlCreateLabel("(xxx) xxx-xxxx", 160, 96, 100, 17, $WS_GROUP)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $Aboutok = GUICtrlCreateButton("&OK", 112, 200, 75, 25)
        GUISetState(@SW_SHOW)
;-------------------------------------------------------------------------------------------------

        Do
            $msg = GUIGetMsg()
            If $msg = $Aboutok Then
                ExitLoop
            EndIf
        Until $msg = $GUI_EVENT_CLOSE
        GUIDelete($Aboutwindow)

; Hotkey's GUI Window dimensions and components.
;-------------------------------------------------------------------------------------------------

    ElseIf $msg1 = $MenuItem6 Then
        #Region ### START Koda GUI section ### Form=
        $Hotkeywindow = GUICreate("Keyboard Shortcuts", 368, 203, 321, 254)
        GUISetIcon("D:\004.ico")
        $HotkeyGroupBox1 = GUICtrlCreateGroup("", 8, 1, 265, 193)
        $Label5 = GUICtrlCreateLabel("Exit Program", 22, 16, 63, 17)
        GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
        $Label6 = GUICtrlCreateLabel("CTRL + ALT + X", 22, 38, 83, 17)
        $Label7 = GUICtrlCreateLabel("Release the job automatically.", 22, 59, 215, 17)
        GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
        $Label8 = GUICtrlCreateLabel("CTRL + ALT + F7", 22, 81, 88, 17)
        $Label9 = GUICtrlCreateLabel("Future", 22, 103, 34, 17)
        GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
        $Label10 = GUICtrlCreateLabel("Future", 22, 125, 34, 17)
        $Label11 = GUICtrlCreateLabel("Future", 22, 146, 34, 17)
        GUICtrlSetFont(-1, 8, 400, 4, "MS Sans Serif")
        $Label12 = GUICtrlCreateLabel("Future", 22, 168, 34, 17)
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $Hotkeyok = GUICtrlCreateButton("&OK", 286, 11, 75, 25, 0)
        GUISetState(@SW_SHOW)

        Do
            $msg = GUIGetMsg()
            If $msg = $Hotkeyok Then
                ExitLoop
            EndIf

        Until $msg = $GUI_EVENT_CLOSE
        GUIDelete($Hotkeywindow)

; Options Gui Window dimensions and components.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ElseIf $msg1 = $MenuItem2 Then


        $Optionswindow = GUICreate("Optionswindow", 356, 240, 318, 315)
        $GroupBox1 = GUICtrlCreateGroup("", 8, 1, 337, 193)
;       $Slider1 = GUICtrlCreateSlider(89, 143, 174, 45, BitOR($TBS_AUTOTICKS, $TBS_ENABLESELRANGE, $TBS_FIXEDLENGTH, $WS_GROUP, $WS_TABSTOP), BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
;       GUICtrlSetLimit(-1, 5, 0)
;       GUICtrlSetTip(-1, "Adjust Speed..")
;       $Icon1 = GUICtrlCreateIcon(@ScriptDir & "\turtle.ico", 0, 37, 147, 36, 28)
;       $Icon2 = GUICtrlCreateIcon(@ScriptDir & "\rabbit.ico", 0, 285, 147, 36, 36)
        $Optiontext = GUICtrlCreateEdit("", 16, 16, 321, 113, $ES_READONLY, BitOR($WS_EX_CLIENTEDGE, $WS_EX_STATICEDGE))
        GUICtrlSetData(-1, StringFormat("Adjust the slider bar left or right to speed up or slow down the \r\nscript. The default setting is in the middle and should only be \r\nchanged if you are having difficulty with the programs stalling.  If \r\nyou have tried adjusting the slider bar to the lowest setting and are \r\nstill getting stuck in a certain spot E-Mail me and I will adjust the \r\nwait times in the Script to make it more reliable."))
        GUICtrlCreateGroup("", -99, -99, 1, 1)
        $Optionok = GUICtrlCreateButton("OK", 89, 203, 75, 25)
        $Optioncancel = GUICtrlCreateButton("Cancel", 191, 203, 75, 25)
        GUISetState(@SW_SHOW)

; Create ToolTips for slider bar.
;       $hWndTT = _GUICtrlSlider_GetToolTips($Slider1)
;       _GUICtrlSlider_SetToolTips($Slider1, $hWndTT)

        Do
            $msg = GUIGetMsg()
            If $msg = $Optionok Then
                ExitLoop
            ElseIf $msg = $Optioncancel Then
                ExitLoop
            EndIf

        Until $msg = $GUI_EVENT_CLOSE
        GUIDelete($Optionswindow)


    EndIf

Until $msg1 = $GUI_EVENT_CLOSE
GUIDelete()
Edited by Teltech
Link to comment
Share on other sites

Hi All,

I've been using Autoit for a few weeks now and have been reading this forum quite alot to find the information I need. But now I'm stuck and I'm hoping some of you could help me out.

The purpose of my program is to launch 5 seperate programs depending on whether a radio button is selected. I'm able to determine which radio button is selected and when I click "go" it runs the script. Program #1 takes information from a cell in excel, then in an Internet Explorer window , enters the data from the excel sheet into a box and clicks okay. The webpage i'm viewing will check to see if that data has been entered before, if it is it opens up a message saying that the data is already there. Before running the script I ask the user how many times the script should loop because there could be quite a few things in the excel sheet that need entered.

I've also created a slider bar on the main window which I'm trying use to control teh delay times as some of the people have slower connections/computers than user and may need toa djust the speed of the script to avoid errors.

I have a few problems that I can't seem to find the answer to.

1) Can I use variables in Sleep() ? Right now I specify the the sleep times manually, but I'm trying to increase or decrease these times using the value from the slider by entering Sleep($Sleepvar) but when I run it it doesn't seem to recognize it. Any ideas?

Yes, a variable should work fine, providing the variable contains an integer. You have a logic problem where you have the test for GuiGetMsg() = $slider is inside an ElseIf clause checking GUIGetMsg() = $go. There is no need to check GUIGetMsg() again at that point, so it should look more like this:
ElseIf $msg1 = $Go Then

    ; After the user clicked Go read the value from the slider and enter the sleep times associated with each option.

        $Speedvar = GUICtrlRead($Slider)
        Switch $Speedvar
            Case "0"
                If $Speedvar = "0" Then $Speedvar = 10000
            Case "1"
                If $Speedvar = "1" Then $Speedvar = 15000
            Case "2"
                If $Speedvar = "2" Then $Speedvar = 20000
            Case "3"
                If $Speedvar = "3" Then $Speedvar = 40000
            Case "4"
                If $Speedvar = "4" Then $Speedvar = 50000
        EndSwitch

    ; ...<snip>
        
    EndIf

2) In Program #1 there are two places where my script may run into a snag. If the data being entered into my website I'll get a response back. I figured out how to identify when that occurs and pass the line. The only problem is when there are two lines in my spreadsheet that already exists things break :s Is there a way I can restart the script or Go to the start when this error occurs? Is there a better way to do what I'm trying to do?

First, this would be much easier and more reliable if you learn to use the IE.au3 UDF functions to manipulate the web page.

As for the pop-up responses, you could kick off an AdLibEnable() function that checks for all those pop-ups every 100ms or so and handles them as they occur.

3) Using the winwait/winactive commands can I insert a variable for Autoit to search the screen for?

For example: in one of my error loops the response that I get back from IE is a standard msg box that contains "What I copied from by excel sheet Site Already exists please try again."

I can't seem to get the right syntax but this is what I'm trying to do

WinActive("Microsoft Internet Explorer", ""$variablefromclipboard" Site already exists please try again.")

Has anyone tried this?

You need the "&" concatenate operator to put the string together with the contents of the variable:
WinActive("Microsoft Internet Explorer", $variablefromclipboard & " Site already exists please try again.")
This will still only work if that's the literal string. If the variable data and the other string part are on separate lines or something, it still won't match. You could just drop the variable and only test for the string "Site already exists please try again", because you only apply the sites one at a time and already know which one it's talking about.

I apologize for the length of my code, If you would like me to shorten it I can try.

Thanks in advance!

No problem. Just use "codebox", vice "code" for posting long stuff.

And welcome to AutoIt1

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks PsaltyDS !!!

I knew there was something right infront of me that I was overlooking. My Speed slider works great :D

I checked out the helpfile on the AdlibEnable() function and did some playing around with it.

I was having troubles, because when the error message pop-up occured I wanted the script to stop processing and go back to the start. But I was thinking about it all wrong. I didn't want to go back to the start, I wanted to skip the end! So the function checks to see if a certain window is open, then sets changes a variable to 1. In my script I added a while event so if the window isn't open execute the last part. If it is open then only do the first part.

It works great!, here's a snippet of what I've done. It's not applied to the full program but in theory it checks to see of I have communicator open. If it's not open then write asdf fdsa. If it is open only write asdf.

CODE
AdlibEnable("myadlib", 100)

Func myadlib()

If WinExists("Microsoft Office Communicator") Then

$Communicatorcheck = 1

EndIf

EndFunc ;==>myadlib

ElseIf @error = 0 Then

$loopA2 = 0;Start count variable.

$loopEnd2 = $Program2endvariable;Specify end variable that is user defined.

Do; Start Executing Program #2 functions.

$Communicatorcheck = 0

Opt("WinTextMatchMode", 2)

Opt("WinWaitDelay", 100)

Opt("WinTitleMatchMode", 4)

Opt("WinDetectHiddenText", 1)

Opt("MouseCoordMode", 0)

WinWait("Untitled - Notepad", "")

If Not WinActive("Untitled - Notepad", "") Then WinActivate("Untitled - Notepad", "")

WinWaitActive("Untitled - Notepad", "")

Sleep($Speedvar)

Send("asdf")

Sleep($Speedvar)

While $Communicatorcheck = 0

Sleep(1000)

Send("fdsa")

Sleep(1000)

$Communicatorcheck = 1

WEnd

; Program #2 ran successfully.

$loopA2 = $loopA2 + 1

Sleep(200)

;Stop Looping until User Value is met.

Until $loopA2 = $loopEnd2

EndIf

I'm pretty new to Autoit and have been avoiding the IE UDF because I fear it :o Once I get the basics down I'll venture into that world until my next project which is much more complex but from what I've read it looks very promising.

Now to figure out how to force numbers to be entered into the inputbox so my loop doesn't run forever :D

Thank you so much! :) ... Autoit is great

Yes, a variable should work fine, providing the variable contains an integer. You have a logic problem where you have the test for GuiGetMsg() = $slider is inside an ElseIf clause checking GUIGetMsg() = $go. There is no need to check GUIGetMsg() again at that point, so it should look more like this:

ElseIf $msg1 = $Go Then

; After the user clicked Go read the value from the slider and enter the sleep times associated with each option.

        $Speedvar = GUICtrlRead($Slider)
        Switch $Speedvar
            Case "0"
                If $Speedvar = "0" Then $Speedvar = 10000
            Case "1"
                If $Speedvar = "1" Then $Speedvar = 15000
            Case "2"
                If $Speedvar = "2" Then $Speedvar = 20000
            Case "3"
                If $Speedvar = "3" Then $Speedvar = 40000
            Case "4"
                If $Speedvar = "4" Then $Speedvar = 50000
        EndSwitch

; ...<snip>
        
    EndIf

First, this would be much easier and more reliable if you learn to use the IE.au3 UDF functions to manipulate the web page.

As for the pop-up responses, you could kick off an AdLibEnable() function that checks for all those pop-ups every 100ms or so and handles them as they occur.

You need the "&" concatenate operator to put the string together with the contents of the variable:

WinActive("Microsoft Internet Explorer", $variablefromclipboard & " Site already exists please try again.")
This will still only work if that's the literal string. If the variable data and the other string part are on separate lines or something, it still won't match. You could just drop the variable and only test for the string "Site already exists please try again", because you only apply the sites one at a time and already know which one it's talking about.

No problem. Just use "codebox", vice "code" for posting long stuff.

And welcome to AutoIt1

:D

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