martyh Posted December 12, 2011 Posted December 12, 2011 Hi Guys, I'm just newbie at Autoit ! However, I do have some general VBA programming exprience.... and now for my question... I have an Autoit script that I thought works --- at least the first time thru. The second and third time however it fails about half way. Amazingly the forth time thru it again works. Is there a buffer that I have to empty or what's going on?
guinness Posted December 12, 2011 Posted December 12, 2011 Is there a buffer that I have to empty or what's going on?Perhaps? Could you post what you created please. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
martyh Posted December 13, 2011 Author Posted December 13, 2011 expandcollapse popup [/i] [i]#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ----------------------------------------------------------------------------[/i] [i] AutoIt Version: 3.3.6.1 Author: MH Habicht Dste: 7 Dec 2011 Script Function: To capture the hyetograph in STORM and print it out in comparison with an IDF curve Requires batch file to work properly (third try) #ce ---------------------------------------------------------------------------- #include <GuiEdit.au3> #include <GuiConstantsEx.au3> #include <Clipboard.au3> Opt("SendKeyDelay", 10) ;5 milliseconds Opt("SendKeyDownDelay", 30) ;1 millisecond Opt("MouseClickDelay", 100) ;10 milliseconds Opt("MouseClickDownDelay", 100) ;10 milliseconds Opt("MouseClickDragDelay", 2500) ;250 milliseconds Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase ;NOTE: montreal PETrudeau is active ;Variables Global $MaxPpt = "100.00" ;$CmdLine[3] ; "80.00"; This one is found at Pluie du 2008-08-02 pour cellule 27,20 (x,y) HNE (Radar WVY) ;Actually equal to 100.5666 Global $STORMPath = $CmdLine[1] ;"C:Documents and SettingsUser2My DocumentsMHHJFSA Projects765STORMS PrintoutSTORMS Printoutstm" ;Actually changed in the BATCH Script ;$CmdLine[1] Global $STORMName = StringTrimRight($CmdLine[2], 4) ; & ".stm" ; "23j_17_70" ; ;"VR_25_20_10" ;StringTrimRight($CmdLine[2], 4) Global $STORMFullName = $STORMPath & $STORMName & ".stm" ;$STORMPrintDirPath = "Z:PROJ765-09Designfichiers stmstmpdf" ;$CmdLine[4] ; "Z:PROJ765-09Designfichiers stmstm" ; NETWORK Global $STORMPrintDirPath = "C:Documents and SettingsUser2My DocumentsMHHJFSA Projects765STORMS PrintoutSTORMS PrintoutstmpdfIDF" ; LOCAL $CmdLine[4] ; "Z:PROJ765-09Designfichiers stmstm" ; Global $STORMPrintDir = $STORMPrintDirPath & "IDF_" & $STORMName & "_STM.pdf" Global $DB_NameID = "7025250a" ; for Montreal PET msgbox(0, "Params", $MaxPpt & " " & $STORMFullName & " " & $STORMPrintDir) Run ( "C:Program FilesSTORMS 2010STORMS2010.exe") _WinWaitActivate("[CLASS:ThunderRT6FormDC]", "") $MainHandle = WinWaitActive("[CLASS:ThunderRT6FormDC]") ControlClick("[CLASS:ThunderRT6FormDC]", "", 2) ;2 ;[CLASS:ThunderRT6CommandButton; INSTANCE:1] ;&OK ;If WinExists("[CLASS:ThunderRT6FormDC]") Then ;waits to get storm file to be compared against IDF _WinWaitActivate("[CLASS:ThunderRT6MDIForm]", "") Send("{ALT}f") Send("os") Send($STORMFullName, 1) Send("{ENTER}") ;msgbox(0,"Err", "this is an error") _GetStorm[/i] [i];waits to get IDF file ;WinWaitActive("[CLASS:ThunderRT6MDIForm]") Send("{ALT}f") Send("{LEFT 4}") Send("{DOWN 2}") Send("{RIGHT 1}") Send("{DOWN 1}") Send("{ENTER}") Send($STORMPath & "JFSA_IDF_DATABASE_CRI.mdb", 1) Send("{ENTER}")[/i] [i];now get the correct data record from within the file <<--- this is approximately craps out Send("{ALT}b") Send("{DOWN}") Send("{RIGHT}") Send("{ENTER}") _WinWaitActivate("Recherche, données station ...","") ControlSetText("Recherche, données station ...", "", 1, $DB_NameID ) ControlClick("Recherche, données station ...", "", 4) sleep(1000) ;now wait for the correct window (and I'm not sure what the problem is!!!) ;So ... ;We will have to use the mouse --- the worst case scenerio MouseClick("left", 243, 34) MouseClick("left", 243, 57) MouseClick("left", 530, 74) MouseClick("left", 766, 435) ; load in hyetograph BEFORE showing statistics _WinWaitActivate("STORMS 2010 - Ver. 3.0.0","Base de données IDF") ;show IDF curve with ppt event -- the blue line ;the following send statements avoid more specific WinMenuSelectItem statements Send("{ALT}g") Send("{DOWN}") Send("{RIGHT}") Send("{ENTER}") _WinWaitActivate("STORMS 2010 - Ver. 3.0.0","Base de données IDF") ;show the statistics --- right side WinMenuSelectItem("STORMS 2010 - Ver. 3.0.0","Fichier de pluie","Graphique IDF","Voir statistiques de pluie") _WinWaitActivate("STORMS 2010 - Ver. 3.0.0","Base de données IDF") ;show the equations --- inset on the top WinMenuSelectItem("STORMS 2010 - Ver. 3.0.0","Fichier de pluie","Graphique IDF","Voir équations des courbes IDF") _PrintingStorm WinClose("[ACTIVE]")[/i] [i]Func _GetStorm() ConsoleWrite('@@ (95) :(' & @MIN & ':' & @SEC & ') _GetStorm()' & @CR) ;### Function Trace _WinWaitActivate("STORMS 2010 - Ver. 3.0.0", "") $EventHandle = WinWaitActive("STORMS 2010 - Ver. 3.0.0") Send("{ALT}w") Send("1") ;ACTIVE - 23j_17_70.stm etc ;checks replot hyetograph automatically ControlCommand("STORMS 2010 - Ver. 3.0.0", "", 45, "Check", "") ;checks Update Statistics Automatically ControlCommand("STORMS 2010 - Ver. 3.0.0", "", 44, "Check", "")[/i] [i] ; Selects the existing value ;ControlClick("STORMS 2010 - Ver. 3.0.0", "", 36, "", 2) ;Deletes the old amd Enters the NEW scale for ppt ;ControlCommand("STORMS 2010 - Ver. 3.0.0", "", 36, "EditPaste", $MaxPpt ) ;put in a more robust control ControlSetText("STORMS 2010 - Ver. 3.0.0", "", 36, $MaxPpt )[/i] [i] ;"EditPaste", 'string' Pastes the 'string' at the Edit's caret position ;Finish the command clicking the Plot Hyetograph ControlClick("STORMS 2010 - Ver. 3.0.0", "", 2) ;change the language Send("{ALT}f") Send("{DOWN}") Send("l") Send("f") ;wait for the active screen _WinWaitActivate("STORMS 2010 - Ver. 3.0.0", "") ;Time units to hours "SelectString", 'string' ; Sets selection according to string in a ListBox ControlCommand("STORMS 2010 - Ver. 3.0.0", "", 43, "SelectString", "h" ) ;to print the data Return EndFunc Func _PrintingStorm() ConsoleWrite('@@ (129) :(' & @MIN & ':' & @SEC & ') _PrintingStorm()' & @CR) ;### Function Trace ;----------------------------------------------- ;Printing and changing the Language to English ;----------------------------------------------- _WinWaitActivate("STORMS 2010 - Ver. 3.0.0", "") Send("^p") _WinWaitActivate("Options pour l' impression", "") ;upper left ;these lines had to be switched from ControlCommand lines to ControlSetText lines ;ControlSetText("Options pour l' impression", "", 36, "", 2) ControlSetText("Options pour l' impression", "", 36, "Pluie du 2 août 2008 sur l’est de Montréal") ;upper right ControlSetText("Options pour l' impression", "", 37, "8 décembre 2011" )[/i] [i] ;lower left ControlSetText("Options pour l' impression", "", 38, $STORMName & ".stm") ;lower right ControlSetText("Options pour l' impression", "", 39, "J.F. Sabourin et associés inc.") ;the printer button ControlClick("Options pour l' impression", "Imprimante", 14) ;go get it _PrintLandscape[/i] [i] ;send the $STORMPath & $STORMName to the path & file name _WinWaitActivate("Save PDF File As", "") ControlSetText("Save PDF File As", "", 1148, $STORMPrintDir) Send("{ENTER}") ;change the language back to english _WinWaitActivate("STORMS 2010 - Ver. 3.0.0","") Send("{ALT}f") Send("{LEFT 4}") Send("{DOWN}") Send("l") Send("e") EndFunc Func _WinWaitActivate($title,$text,$timeout=0) ConsoleWrite('@@ (165) :(' & @MIN & ':' & @SEC & ') _WinWaitActivate()' & @CR) ;### Function Trace WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc Func _PrintLandscape() ConsoleWrite('@@ (171) :(' & @MIN & ':' & @SEC & ') _PrintLandscape()' & @CR) ;### Function Trace _WinWaitActivate("Print", "Select Printer") ControlClick("Print", "Select Printer", "Button13") ;sleep(5000) _WinWaitActivate("Options pour l' impression", "Statistiques des quantités de ") ;msgbox(0,"Stop", "here") ControlClick("Options pour l' impression", "Statistiques des quantités de ", "ThunderRT6CommandButton2") EndFunc[/i] [i] OK a little expaination: this script is intended to go thru a program called STORM, openning two files that are read in to the system and then capturing the results by printing out a graph. One file is a cell of a storm and the other is the comparison storm at PE Trudeau Airport. Because there are a huge number of these 1 km square cells, I wrote a simple batch file to make it go from cell to cell, ( just the acquiring of the data for 1 cell is done by AutoIT). Therein lies the problem: the first time I run the whole script (Autoit and bat) everything is fine, but the next two iterations, the script stops working right before it goes to choose the airport file. (I've marked it) then by some miracle - the 4th iteration is OK !
water Posted December 13, 2011 Posted December 13, 2011 Might be a timing problem or another program stealing focus. My first AutoIt scripts had a lot of Send statements and hence were unreliable. I changed to ControlSend, ControlClick etc. functions and the scripts became much more reliable. I would suggest to put strings you use multiple times into a variable (or even put it into an ini file so you don't have to change thes cript when a new version of the program is installed). E.G._WinWaitActivate("STORMS 2010 - Ver. 3.0.0", "Base de données IDF")to$sWindowTitle = "STORMS 2010 - Ver. 3.0.0" _WinWaitActivate($sWindowTitle, "Base de données IDF") My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
martyh Posted December 13, 2011 Author Posted December 13, 2011 Might be a timing problem or another program stealing focus.If it is a timing problem then how would I go about solving it?How would another process "steal" focus?Thanks for the tip on "ControlSend, ControlClick" etc
water Posted December 13, 2011 Posted December 13, 2011 If you go with ControlSend, ControlClick etc. the timing will no longer be an issue. The Send command sends data to the active window. If another window pops up or gets activated by a message then the focus is on the wrong application. I would suggest to completely remove all Send statements and replace them with Control* functions. If you can't wait then I would insert Sleep statements after each Send that results in a new screen or submenu to open. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
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