Jump to content

Looking for best practice advice


MaxG
 Share

Recommended Posts

Hello All,
 
Intro:
I'm working on an automation project for work and this is my first AutoIt program (I usually code in VBA or AcroJS).  My code is not complete - my intention is to get a rough working program together, then modify to accommodate batch processing, then cycle between writing error handling code and testing on copies of live jobs.

I'm working with mail processing software that is server-based so there are times where my client software goes unresponsive while it communicates with the server.  I have to assume this will be an ongoing issue that I must script-around.  Also, it uses plenty of non-standard controls.  (using SysExporter and MouseClick for those...)
 
Why I'm posting:
I'm just looking for general feedback / enlightenment from the community on AutoIt best practices
(general coding best practices are welcome as well....  I ought to make better use of hungarian notation in my variables)

Specifically:

  • Sleep statements vs. WinWaitActive and such.
    I've added a lot of delays because it seems like my script runs too fast for the software and it appears to add stability.
     
  • Window identification: hWnd vs Title
    I expect to be encouraged to make better use of hWnds, but I what I'm doing is working for me so far.  Since I'm dealing with a lot
    of different windows, I'm not sure what the best method of managing hWnds would be so title has made more sense thus far.
     
  • Combinations of WinWait, WinActivate, and WinWaitActive
    Since this code is essentially a rough draft / outline I've been "making it work" and I feel like there is a lot of room for me to improve
    when using these statements.
     
  • General Tips for Stability
    I've had some instances where windows do not always become active as expected, or acrobat not closing, and this happens when the same code is run multiple times.  It only happens occasionally so I can't reproduce it reliably.

 

Anyway, If anybody feels like reading code and making constructive comments, please, have at it!

#include <File.au3>
#include <Array.au3>
#include <GuiTab.au3>
#include <_ArrayRemoveBlanks.au3>

;BlockInput(1)

;Directory Constants
Const $dirCustomerDirectory = "C:\Users\Me\Desktop\Script Test Files\TEST_ENVIRONMENT\Customer"
Const $dirJobTickets = "C:\Users\Me\Desktop\AutoIT Scripts\_JobTickets"

; Delay variables for pauses during script execution
Local $microDelay = 250             ; Tiny pauses between commands
Local $shortDelay = 1000            ; Small pauses between commands
Local $mediumDelay = 5000           ; Medium pauses
Local $longDelay = 10000            ; Long pauses
Local $timeout = 60000              ; Command timeout set for 1 minute

Local $listName = "Max_Test"        ; - Obviously, this is hard coded for testing purposes.
Local $JobNum = ""
Local $PizzaPlace = ""
Local $CustomerID = ""
Local $GID_Check = ""
Local $WaitingFlag = False

;$arrZipCodes is an array that will hold the zip codes extracted from the distribution report.
Local $arrZipCodes

Local $arrRegExFound

Local $fullJobPath = ""
Local $JobFolder = ""
Local $CustFolder = ""
Local $listFile = ""

Local $hFileOpen = ""
Local $sFileOpen = ""

Local $hWnd = ""
Local $sHWnd = ""

;BEGIN PERMIT TABLE INITIALIZATION SECTION - SAVES IT TO SCRIPT DIR
;Activates the BCC Windows
WinActivate("Main Program - ADMIN")
Sleep($microDelay)
;Clicks the "Postal" menu option.
MouseClick("left", 235, 38, 1, 0 )
Sleep($microDelay)
MouseClick("left", 235, 266, 1, 0 )
Sleep($microDelay)
MouseClick("left", 533, 266, 1, 0 )

WinWait("PS Form 3602-R", "Change Permit")

Do
    
    WinActivate("PS Form 3602-R", "Change Permit")
    ControlClick("PS Form 3602-R", "Change Permit", "[CLASS:TButton; INSTANCE:5]")
    Sleep($shortDelay)
    
    If WinActive("Main Program FS", "Borland Database Engine error") <> 0 Then
        $WaitingFlag = True
        
        WinActivate("Main Program FS", "Borland Database Engine error")
        Sleep($shortDelay)
        Send("{enter}")
        
        Sleep($longDelay)   ;Pauses for 10 seconds, then re-attempts to access the permit
    EndIf
    
Until $WaitingFlag = False

WinWait("Select a Permit", "&Modify")
WinActivate("Select a Permit", "&Modify")
ControlClick("Select a Permit", "&Modify", "[CLASS:TBitBtn; TEXT:&Modify]")

WinWaitActive("Permit Information", "PreparedPanel")

Run("C:\Program Files (x86)\NirSoft\SysExporter\sysexp.exe")
WinWaitActive("SysExporter", "item(s)")
WinMove("SysExporter", "item(s)",1270, 410, 400, 600)
WinActivate("SysExporter", "item(s)")

Opt("MouseCoordMode", 0)
MouseClickDrag("left", 27, 60, -445, 113, 5)
Opt("MouseCoordMode", 1)

WinActivate("SysExporter")
Send("^e")
WinWaitActive("Select a filename to save", "")
ControlSend("Select a filename to save", "", "[CLASS:Edit; INSTANCE:1]", @ScriptDir & "\PermitTableExport{enter}")

Sleep($shortDelay)
If WinActive("Confirm Save As", "&Yes") <> 0 Then
    
    WinWaitActive("Confirm Save As", "&Yes")
    ControlClick("Confirm Save As", "&Yes", "[CLASS:Button; TEXT:&Yes]", "left", "1")
    
EndIf

;Cancel out of the windows I opened in BCC to get at the permit table.
WinActivate("Permit Information", "PreparedPanel")
Send("!c")
Sleep($microDelay)
Send("!c")
Sleep($microDelay)
Send("!c")
Sleep($microDelay)
WinClose("SysExporter")
;END PERMIT TABLE INTIALIZATION SECTION


;BEGIN BATCH INITIALIZATION
;Tests job ticket folder to ensure there are tickets to process.
Local $jobTicketArray = _FileListToArray($dirJobTickets,"*.pdf")
If ($jobTicketArray[0] = 0) Then
    MsgBox(0,"ERROR","Could not locate job ticket PDFs in the folder; exiting script!")
    Exit
EndIf

;Loops through each job ticket PDF and converts it to plain text.
For $Counter = 1 To $jobTicketArray[0] 

    ShellExecute($dirJobTickets & "\" & $jobTicketArray[$Counter],"","","open")
    Sleep($mediumDelay)
    Send("!f")          ;Accesses the file menu
    Sleep($microDelay)
    Send("h")           ;Navigates the menu system to the export as plain text option.
    Sleep($microDelay)
    Send("m")
    Sleep($microDelay)
    Send("t")
    WinWaitActive("Save As", "&Save")
    ControlClick("Save As", "&Save", "[CLASS:Button; TEXT:&Save]")

    Sleep($shortDelay)
    If WinActive("Save As", "The file already exists") <> 0 Then
        
        WinWaitActive("Save As", "The file already exists")
        ControlClick("Save As", "The file already exists", "[CLASS:Button; TEXT:&Yes]", "left", "1")
        
    EndIf

    WinActivate("Adobe Acrobat", "AVUICommandWidget")
    Send("^w")

Next

Sleep($shortDelay)
WinActivate("Adobe Acrobat", "AVUICommandWidget")
Sleep($shortDelay)
Send("^q")
;END BATCH INITIALIZATION


;BEGIN INTIALIZATION OF CURRENT JOB
;First - read the job ticket text output to gather data.
Local $jobTicketTextArray = _FileListToArray($dirJobTickets,"*.txt")
If ($jobTicketTextArray[0] = 0) Then
    MsgBox(0,"ERROR","Could not locate job ticket TXTs in the folder; exiting script!")
    Exit
EndIf

;000000000000000000000   MAIN PROCESSING LOOP WILL LIKELY BEGIN HERE!
;When this is the start of the loop, change the array reference to be the counter variable.

$hFileOpen = FileOpen($dirJobTickets & "\" & $jobTicketTextArray[1])
$sFileRead = FileRead($hFileOpen)

FileClose($hFileOpen)

;Finds and stores the job number from the job ticket.
$arrRegExFound = StringRegExp($sFileRead, "Job\s(\d{4}\d?)", 1)
$JobNum = $arrRegExFound[0]

;Finds and stores the Grande ID from the job ticket.
$arrRegExFound = StringRegExp($sFileRead, "ID#\s?(\w{9})", 1)
$CustomerID = $arrRegExFound[0]

;This block finds and stores the customer folder path (and folder name) based on CustomerID
Local $folderArray = _FileListToArray($dirCustomerDirectory, "*" & $CustomerID & "*", 2)
If ($folderArray[0] = 0) Or ($folderArray[0] > 1) Then
    MsgBox(0,"ERROR","Could not locate an exact match on CustomerID " & $CustomerID & "; exiting script!")
    Exit
Else
    $CustFolder = $folderArray[1]
    $arrRegExFound = StringRegExp($folderArray[1], "(.*)\s+?\w\d\w\d{6}", 1)
    ;Store customer name based on folder name in the customer directory folders.
    ;The flag '7' at the end is three flags in one:  trim leading space, trim trailing, trim double spaces between words to a single space)
    $PizzaPlace = StringStripWS(StringReplace(String($arrRegExFound[0]), "-", ""), 7)
EndIf

;This block finds and stores the job folder path (and name) based on Job#
$folderArray = _FileListToArray($dirCustomerDirectory & "\" & $CustFolder, "*" & $JobNum & "*", 2)
If ($folderArray[0] = 0) Or ($folderArray[0] > 1) Then
    MsgBox(0,"ERROR","Could not locate an exact match on Job# " & $JobNum & "; exiting script!")
    Exit
Else
    $JobFolder = $folderArray[1]
EndIf

;Constructs the full path to the job folder for ease of reference
$fullJobPath = $dirCustomerDirectory & "\" & $CustFolder & "\" & $JobFolder

;This block finds and stores the list file name based on regular expression:   [Q]\d{6}\.[t][x][t]
;This RegExp defines the pattern format of the valassis-purchased lists.
$folderArray = _FileListToArray($fullJobPath, "*.txt", 1)

If @error Then
    MsgBox(0,"ERROR","Could not locate list file; exiting script!")
    Exit
Else
    For $vElement In $folderArray
        If StringRegExp($vElement, "[Q]\d{6}\.[t][x][t]") Then $listFile = $vElement
    Next
EndIf
;END INITIALIZATION OF CURRENT JOB

;BEGIN PROCESSING JOB IN BCC
;Activates the BCC Windows
WinActivate("Main Program - ADMIN")
Sleep($shortDelay)
;Clicks the "New List" button.
ControlClick("Main Program", "", "[CLASS:TToolBar; INSTANCE:3]", "left" , 1, 10, 15)

;Clicks the "Use Template..." option and finds the Grande Non-Auto template.
send("{down}{down}{enter}")
send("Grande Non-Auto{enter}")

;NOW:  This section will need variable input for the job# and customer name
;      BUT for now I'm having it overwrite a test DB
WinWaitActive("Save New List As")
ControlClick("Save New List As", "", "[CLASS:Edit; INSTANCE:1]")
Sleep($shortDelay)
Send($listName & "{enter}")


;TEMPORARY OVERWRITE SECTION FOR LIST DBF CREATION REPORT CREATION
WinWaitActive("Confirm Save As")
ControlClick("Confirm Save As", "", "[CLASS:Button; INSTANCE:1]")
;END OVERWRITE SECTION

;Handles the saved BATCH index screen
WinWaitActive("[CLASS:#32770]", "The following index is saved")
ControlClick("[CLASS:#32770]", "The following index is saved", "[CLASS:Button; INSTANCE:1]")

;Clicks the save button on the layout screen just prior to DBF creation
WinWaitActive("Main Program - ADMIN", "")
WinWait($listName, "")
Sleep($mediumDelay)
WinActivate($listName, "")
;MsgBox(0,"Test","Before Click")
ControlClick($listName, "No Records", "[CLASS:TPanel; INSTANCE:2]", "left", 1, 45, 10)

;Fills list name and initials
WinWaitActive($listName, "&Help")
Sleep($shortDelay)
Send("{TAB}MG{ENTER}")

;handles list import
WinWaitActive("[CLASS:TMailList_Form]", "")
ControlClick("Main Program", "", "[CLASS:TToolBar; INSTANCE:3]", "left" , 1, 115, 15)

WinWaitActive("Import Wizard", "Select Transfer Format")
ControlClick("Import Wizard", "", "[CLASS:TBitBtn; TEXT:&Modify]")

WinWaitActive("Import Wizard", "Source and Destination Files")
ControlClick("Import Wizard","Source and Destination Files", "[CLASS:TBitBtn; TEXT:Browse]")

WinWaitActive("Open Delimited file", "Look &in:")

;Moves to the directory where I need to start searching.
Sleep($shortDelay)
Send($fullJobPath & "\" & $listFile & "{enter}")
Sleep($shortDelay)

WinWaitActive("Import Wizard", "&Next")
ControlClick("Import Wizard", "", "[CLASS:TBitBtn; TEXT:&Next]")

WinWaitActive("Import Delimited File", "&Import")
ControlClick("Import Delimited File", "", "[CLASS:TBitBtn; TEXT:&Import]")

WinWaitActive("Save Procedure Information", "&Don't Save")
ControlClick("Save Procedure Information", "", "[CLASS:TButton; TEXT:&Don't Save]")

WinWaitActive("Import Status", "&OK")
ControlClick("Import Status", "", "[CLASS:TBitBtn; TEXT:&OK]")

Sleep($mediumDelay)
WinActivate("Main Program - ADMIN", "")
Sleep($mediumDelay)
Send("^d")

;This section creates a distribution report after changing some of the settings and setting the job folder path
WinWaitActive("Distribution Report", "")
ControlClick("Distribution Report", "Options", "[CLASS:TButton; TEXT:Options]")

Sleep($shortDelay)
WinWaitActive("Distribution Report Options", "")
ControlClick("Distribution Report Options", "", "[CLASS:TCheckBox; TEXT:Omit Header && Pagination]")
ControlClick("Distribution Report Options", "", "[CLASS:TCheckBox; TEXT:Don't Print Total Records at end of report]")
ControlClick("Distribution Report Options", "", "[CLASS:TBitBtn; TEXT:&OK]")

sleep($shortDelay)
WinWaitActive("Distribution Report", "")
$hWnd = ControlGetHandle("Distribution Report", "", "[CLASS:TPageControl; INSTANCE:1]")
_GUICtrlTab_ClickTab($hWnd, _GUICtrlTab_FindTab($hWnd, "Print Setup"))


ControlClick("Distribution Report", "", "[CLASS:TRadioButton; TEXT:Print to file]")
ControlClick("Distribution Report", "", "[CLASS:TRadioButton; TEXT:Text File]")
Sleep($shortDelay)
ControlSetText("Distribution Report", "", "[CLASS:TEdit; INSTANCE:4]", $fullJobPath & "\DistRep.txt")
Sleep($shortDelay)
ControlClick("Distribution Report", "", "[CLASS:TBitBtn; TEXT:&Begin]")

WinWaitActive("Save Procedure Information", "")
ControlClick("Save Procedure Information", "", "[CLASS:TButton; TEXT:&Don't Save]")

;TEMPORARY OVERWRITE SECTION FOR DISTRIBUTION REPORT CREATION
;WinWaitActive("Main Program FS", "&Overwrite")
;ControlClick("Main Program FS", "&Overwrite", "[CLASS:Button; TEXT:&Overwrite]")

Sleep($shortDelay)
If WinActive("Main Program FS", "&Overwrite") <> 0 Then
    
    WinWaitActive("Main Program FS", "&Overwrite")
    ControlClick("Main Program FS", "&Overwrite", "[CLASS:Button; TEXT:&Overwrite]")
    
EndIf
;END OVERWRITE SECTION

Sleep($mediumDelay)
;Read the Distribution Report file and place the values found into an array
If _FileReadToArray($fullJobPath & "\DistRep.txt", $arrZipCodes) Then

    _ArrayRemoveBlanks($arrZipCodes)
    
    ;This For Loop cleans the data (removes piece count for each unique zip code leaving just the zip codes)
    For $iCount = 1 to $arrZipCodes[0] - 1
        $arrZipCodes[$iCount] = StringLeft($arrZipCodes[$iCount], 5)
    Next

Else
    MsgBox(0,"Error","The distribution report does not contain any zip codes; exiting script!")
    Exit
EndIf

Sleep($mediumDelay)
WinActivate("Main Program - ADMIN")
Sleep($shortDelay)
;Clicks the "Presort" button.
ControlClick("Main Program", "", "[CLASS:TToolBar; INSTANCE:3]", "left" , 1, 390, 15)


Sleep($shortDelay)
WinWaitActive("Mailing Presort Information", "Load")
ControlClick("Mailing Presort Information", "Load", "[CLASS:TButton; TEXT:Load]")

Sleep($shortDelay)
WinWaitActive("List of Saved Presort Settings", "")
ControlClick("List of Saved Presort Settings", "", "[CLASS:SysHeader32; INSTANCE:1]", "left", 1, 50, 8)
Sleep($shortDelay)
Send("Grande - 1 Non-Auto{enter}")

Sleep($shortDelay)
WinWaitActive("Mailing Presort Information", "Permit...")
ControlClick("Mailing Presort Information", "Permit...", "[CLASS:TButton; TEXT:Permit...]")
Sleep($shortDelay)

WinWaitActive("Select a Permit", "&Modify")
Sleep($shortDelay)
Send("{down}")
Sleep($microDelay)
Send("{down}")
Sleep($microDelay)
Send("{down}")
Sleep($microDelay)
Send("{down}")
Sleep($microDelay)
ControlClick("Select a Permit", "&Modify", "[CLASS:TBitBtn; TEXT:&Modify]")

Sleep($mediumDelay) 
WinActivate("Permit Information", "&Modfy")
Sleep($shortDelay)

Opt("MouseCoordMode", 0)
MouseClick("left", 50, 240)
Opt("MouseCoordMode", 1)

Sleep($shortDelay)
Send($PizzaPlace)
Sleep($microDelay)
Send("{enter}")

Sleep($shortDelay)
WinWaitActive("Select a Permit", "&Use")
Sleep($shortDelay)
ControlClick("Select a Permit", "&Use", "[CLASS:TBitBtn; TEXT:&Use]")

WinWaitActive("Mailing Presort Information", "")
Sleep($microDelay)
 
ControlClick("Mailing Presort Information", "", "[CLASS:TDateTimePicker; INSTANCE:2]", "left", 1, 10, 10)
Sleep($shortDelay)
Send(@MON)
Sleep($shortDelay)
Send("{right}")
Sleep($shortDelay)
Send(@MDAY)
Sleep($shortDelay)
Send("{right}")
Sleep($shortDelay)
Send(@YEAR)
Sleep($shortDelay)
Send("{tab}")
Sleep($shortDelay)
Send(@MON)
Sleep($shortDelay)
Send("{right}")
Sleep($shortDelay)
Send(@MDAY)
Sleep($shortDelay)
Send("{right}")
Sleep($shortDelay)
Send(@YEAR)

Sleep($shortDelay)
WinActivate("Mailing Presort Information", "")
ControlClick("Mailing Presort Information", "&OK", "[CLASS:TBitBtn; TEXT:&OK]")
WinWaitActive("Warning", "&Yes")
ControlClick("Warning", "&Yes", "[CLASS:TButton; TEXT:&Yes]")

Sleep($microDelay)
WinWaitActive("Possible Destination Sites", "&OK")
Sleep($microDelay)

_GUICtrlTab_ClickTab(ControlGetHandle("Possible Destination Sites", "", "[CLASS:TPageControl; INSTANCE:1]"), _GUICtrlTab_FindTab(ControlGetHandle("Possible Destination Sites", "", "[CLASS:TPageControl; INSTANCE:1]"), "DDU Destinations"))
Sleep($microDelay)

For $delDDUzips = 1 To 10
    ControlClick("Possible Destination Sites", "Delete", "[CLASS:TListBox; INSTANCE:1]", "left", 1, 15, 8)
    Sleep($microDelay)
    ControlClick("Possible Destination Sites", "Delete", "[CLASS:TBitBtn; TEXT:Delete]")
    Sleep($microDelay)
Next

For $populateZips = 1 To $arrZipCodes[0] - 1
    ControlSend("Possible Destination Sites", "Delete", "[CLASS:TOvcSimpleField; INSTANCE:1]", $arrZipCodes[$populateZips])
    Sleep($microDelay)
Next

ControlClick("Possible Destination Sites", "&OK", "[CLASS:TBitBtn; TEXT:&OK]")

WinWait($listName & " - Presort Summary",  "Select All")
Sleep($shortDelay)
WinActivate($listName & " - Presort Summary",  "Select All")
Sleep($microDelay)

;ControlClick($listName & " - Presort Summary",  "Select All", "[CLASS:TBitBtn; TEXT:Select All]")
Sleep($microDelay)
ControlClick($listName & " - Presort Summary",  "Select All", "[CLASS:TToolBar; INSTANCE:1]", "left", 1, 245, 15)

WinWait("Mail.dat", "Load saved Mail.dat")
Sleep($shortDelay)
WinActivate("Mail.dat", "Load saved Mail.dat")

MsgBox(0, "Test", "Woohoo!")

;BlockInput(0)
Link to comment
Share on other sites

I would always prefer WinWait etc. When using Sleep you might miss a window or spend too much time waiting.

Send always goes to the window having focus. If you can't replace it with ControlSend etc. then make sure the user does not interfere with your script by locking keyboard and mouse (if possible).

MouseClick is dangerous too because the x/y coordinates you need to click to depend on screen resolution and window position. Try to replace them with ControlSend or Send.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@water:

Thank you for your input.  I try to use MouseClick relative to the active window (rather than absolute coords) to avoid some of the issues you mentioned.  I prefer ControlSend as well, but this program uses a lot of non-standard controls that don't respond to direct control commands.

Given your thoughts, I'll probably seek to remove the sleep statements when I'm focusing on optimizing the code.

One situation where the sleep statements seem to be helping is when a window exists, becomes active, but does not handle the sending of text properly if it is done immediately. (ie: the beginning portion of the text string does not appear in the control some of the time without adding a manual pause)

 

@kylomas

Good point of consideration; not a stupid question at all.

The answer is sort of yes and no.  There is an actions recorder of sorts, but it does not offer the flexibility I need.  In truth, I'll probably use the built in recorder for a few specific tasks and incorporate that into the main script.  There is also a UDF interface but, again, it is application specific.  The language is a proprietary blend of VB and java as far as I can tell, and only appears to interact with the application's internal data rather than providing a bridge to the rest of the system.  Being proprietary in nature, there is very little information available, making it even less attractive to me.

To expand on my project focus, this script "reads" pdf copies of job tickets our customer service reps produce and operates the main program as a user would.  The processes involved are so repetitive and predictable that I don't see a need for a human employee to read these job tickets and enter the data into the software if a script can do it the same way using the same information.

Edited by MaxG
Link to comment
Share on other sites

Has anyone encountered this before:

"One situation where the sleep statements seem to be helping is when a window exists, becomes active, but does not handle the sending of text properly if it is done immediately. (ie: the beginning portion of the text string does not appear in the control some of the time without adding a manual pause)"

If anyone has any additional comments/suggestions on my code or the scripting concepts discussed here, they are all welcome and appreciated.

Link to comment
Share on other sites

Do you cite the help file or where is this sentence being taken from?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Actually, I'm quoting my own sentence in the response I made to your initial remarks.    :)

(To be fair, I think I added that after the original post)

@water:

Thank you for your input.  I try to use MouseClick relative to the active window (rather than absolute coords) to avoid some of the issues you mentioned.  I prefer ControlSend as well, but this program uses a lot of non-standard controls that don't respond to direct control commands.

Given your thoughts, I'll probably seek to remove the sleep statements when I'm focusing on optimizing the code.

One situation where the sleep statements seem to be helping is when a window exists, becomes active, but does not handle the sending of text properly if it is done immediately. (ie: the beginning portion of the text string does not appear in the control some of the time without adding a manual pause)

Edited by MaxG
Link to comment
Share on other sites

yes ive encountered having to sleep the script instead of a proper trigger, mostly due to time constraints on the project, but also legitimate lag between the window being "active" and actually accepting inupt; and have also needed opt("sendkeydelay" , 10) though i think that was a terminal issue.

They are especially useful when writing something that will be deployed on machines of varying skill level.  I did try to move all error checking to the location of the sleep and do that while waiting, at least then it is useful loitering.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Thank you for sharing that boththose, its good to know that my sleep statements are not necessarily bad practice.   But, if I understand correctly, you replaced some sleep statements with error handling for the sake of efficiency.  That's interesting to me...  I may have to borrow that idea once I finish the rough script and start optimizing.

I think my average sleep timer is 5 seconds, which seems a bit long to me but produces a more predictable script run for my implementation (or so I've observed).  Still, error handling would certainly be better use of that 5 seconds.  ^_^

Link to comment
Share on other sites

replaced / augmented - whatever it took, we had many internal products that i had to wrap and deploy. In general we would try to dump a log at the end that listed the [old version / current version / date modified] of the things we were deploying, so that our Tier2 and Tier3 helpdesks had a resource to troubleshoot things that were blamed on the patch disc.

I also would tend to give them something to look at if there were extended periods of what might be perceived as inactivity, oracle patches and installs in particular love to just sit around offering no feedback. I used this for many years:

but UEZ has since unloaded a cornucopia of loading animations that make my circle look square.  

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Woah, sounds like you had your hands full!  :)

I checked out your circle - I liked it, thank you for posting the link.  I also looked at UEZ's work - also great examples.  I think I can learn a lot from studying both of your code.

The examples on this site have shown me how truly powerful AutoIt is and your post strengthens that notion!  I've never done any graphics programming - at a glance it looks complicated...  any suggested resources for starting out?  (books, web sites, etc.)

Link to comment
Share on other sites

've never done any graphics programming - at a glance it looks complicated...  any suggested resources for starting out?  (books, web sites, etc.)

 

 

Stalk UEZ and Eukalyptus, read all of their stuff, then place offerings of Jager-Schnitzel and Mezzo mix to the german gods of GDI+ and hope your stuff works.  

And use F1, liberally.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Haha, well said!

In all seriousness, yes, I will definitely study their scripts.... and perhaps invest in some Jager-Schnitzel and Mezzo mix.   :D

I do use F1 liberally....  that help file is one of the most comprehensive and easiest to use I've ever seen!  I can totally see why people are annoyed when people don't utilize it, though as new user, sometimes the difficult part is simply not knowing what your looking for (function name, UDF, etc.).

Link to comment
Share on other sites

Stalk UEZ and Eukalyptus, read all of their stuff, then place offerings of Jager-Schnitzel and Mezzo mix to the german gods of GDI+ and hope your stuff works.  

And use F1, liberally.

 

Well, I thought Germany is the land of the beer junkies.  ;) 

Btw, Eukalyptus is from Austria...

 

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

I'm from Wisconsin, USA - another land of the beer junkies.  :)

After typing that it occurs to me...  there are many Wisconsinites with German heritage!

@UEZ

I'm curious, how did you get your start in graphics programming?

Link to comment
Share on other sites

I'm very interested in this "useless" part of programming. Everything I learnt regarding GDI+ is from this forum!

Prerequisite are a basic mathematical understanding how graphical stuff seems to work and the will to learn it. ;)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Btw, Eukalyptus is from Austria...

 

 

I spit (then snowbladed) from Germany into Austria once, and I have been meaning to revisit all the many places I almost died on the Zugspitze.  When that day comes, I certainly owe you both many rounds of lukewarm Hefe.

Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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