breadhead Posted March 6, 2014 Share Posted March 6, 2014 (edited) One of the ways I use AutoIT is to cut down on repetitive key entry. I have created a simple script that preforms a 30+ step process that runs reports for our month end. Please see the example below. expandcollapse popup#include <file.au3> #include <Date.au3> ;calculate yesterdays date $ydate = _DateAdd('d','-1', _NowCalcDate()) $ymonth = StringMid($ydate, 6,2) $yyear = Stringmid($ydate, 3,2) $yday = Stringright($ydate, 2) ;MsgBox(0, "Yesterdays day is", $yday) ;MsgBox(0, "Yesterdays month is", $ymonth) ;MsgBox(0, "Yesterdays year is", $yyear) ;Variables and constants ;window name for the as400 session $windowname = "Session A - [24 x 80]" ; Get variables $mstart = InputBox("Month Start", "First Day of the Month Closed?", $ymonth & "01" & $yyear, "" ) $mend = InputBox("Month End", "Last Day of the Month Closed?", $ymonth & $yday & $yyear, "" ) $medstart = InputBox("Medicare Start", "First Medicare Cycle Date?", "100113", "" ) $medend = InputBox("Medicare End", "Last Day of the Medicare Cycle?", "093014", "" ) $prtqueue = InputBox("Print Queue", "Month End Report Queue?", "MERPTSQ", "" ) AutoItSetOption("SendKeyDelay", 150) sleep (10000) WinActivate($windowname) WinWaitActive($windowname) send("{F3 5}") sleep(1000) ; do monthly report processing send("1{enter}") send("11{enter}") send("4{enter}") send($prtqueue & "{NUMPADADD}{tab}Y{enter}") ;menu reset send("{F3 5}") ; Run several reports send("1{enter}") send("8{enter}") ; Admissions Register MsgBox (64, "Step 1", "Admissions Register 1" ) send("9{enter}") send($mstart & "{NUMPADADD}") send($mend & "{NUMPADADD}") send("2{enter}") send("{tab 2}" & $prtqueue & "{NUMPADADD}{tab}Y{enter}") SLEEP(1000) MsgBox (64, "Step 2", "Admissions Register 2" ) send("9{enter}") send($mstart & "{NUMPADADD}") send($mend & "{NUMPADADD}") send("3{enter}") send("{tab 2}" & $prtqueue & "{NUMPADADD}{tab}Y{enter}") ; Discharge Register MsgBox (64, "Step 3", "Discharge Register 1" ) send("10{enter}") send($mstart & "{NUMPADADD}") send($mend & "{NUMPADADD}") send("2{enter}") send("{tab 2}" & $prtqueue & "{NUMPADADD}{tab}Y{enter}") SLEEP(1000) What I would like to do, is have the ability to ask at the beginning of the script, which step you would like to start from. As sometimes, timing is not exactly perfect, and the script blows up. Is there a way to make each report a "function" (and I know I'm probably not using the right nomenclature) and then have a dialog box at the beginning of the script ask which "function" to start at? Edited March 6, 2014 by breadhead Link to comment Share on other sites More sharing options...
Starstar Posted March 6, 2014 Share Posted March 6, 2014 (edited) expandcollapse popup#include <file.au3> #include <Date.au3> #include <GUIConstantsEx.au3> ;calculate yesterdays date $ydate = _DateAdd('d','-1', _NowCalcDate()) $ymonth = StringMid($ydate, 6,2) $yyear = Stringmid($ydate, 3,2) $yday = Stringright($ydate, 2) ;MsgBox(0, "Yesterdays day is", $yday) ;MsgBox(0, "Yesterdays month is", $ymonth) ;MsgBox(0, "Yesterdays year is", $yyear) Local $PathSc = _PathFull(@ScriptFullPath) ;Variables and constants ;window name for the as400 session $frmInformation1 = GUICreate("Options", 325, 80, 190, 110) GUICtrlCreateIcon($PathSc, -1, 275, 10, 32, 32) GUISetBkColor(0xffe4b5) GUICtrlSetDefColor(0xff1493) GUICtrlSetDefBkColor(0xffffff) $btnOK1 = GUICtrlCreateButton("Month Start", 250, 48, 70, 25, 0x0001) $btnOK2 = GUICtrlCreateButton("Month End", 250, 8, 70, 25, 0x0001) $btnOK3 = GUICtrlCreateButton("Medicare Start", 165, 8, 80, 25, 0x0001) $btnOK4 = GUICtrlCreateButton("Medicare End", 165, 48, 80, 25, 0x0001) $btnOK5 = GUICtrlCreateButton("Print Queue", 90, 48, 70, 25, 0x0001) $btnOK6 = GUICtrlCreateButton("About Me", 10, 48, 70, 25, 0x0001) GUICtrlSetCursor($btnOK1, 0) GUICtrlSetCursor($btnOK2, 0) GUICtrlSetCursor($btnOK3, 0) GUICtrlSetCursor($btnOK4, 0) GUICtrlSetCursor($btnOK5, 0) GUICtrlSetCursor($btnOK6, 0) $lblInfo1 = GUICtrlCreateLabel("Starstar Starstar Starstar", 10, 10, 150, 20) $lblInfofont = GUICtrlSetFont($lblInfo1, 12, 800) GUICtrlSetCursor($lblInfo1, 7) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $btnOK1 $mstart = InputBox("Month Start", "First Day of the Month Closed?", $ymonth & "01" & $yyear, "" ) Case $GUI_EVENT_CLOSE Exit Case $btnOK2 $mend = InputBox("Month End", "Last Day of the Month Closed?", $ymonth & $yday & $yyear, "" ) Case $btnOK3 $medstart = InputBox("Medicare Start", "First Medicare Cycle Date?", "100113", "" ) Case $btnOK4 $medend = InputBox("Medicare End", "Last Day of the Medicare Cycle?", "093014", "" ) Case $btnOK5 $prtqueue = InputBox("Print Queue", "Month End Report Queue?", "MERPTSQ", "" ) Case $btnOK6 MsgBox(0,"Starstat Autoit","Autoit Forums") EndSwitch WEnd GUISetState(@SW_HIDE) Exit $windowname = "Session A - [24 x 80]" AutoItSetOption("SendKeyDelay", 150) sleep (10000) WinActivate($windowname) WinWaitActive($windowname) send("{F3 5}") sleep(1000) ; do monthly report processing send("1{enter}") send("11{enter}") send("4{enter}") send($prtqueue & "{NUMPADADD}{tab}Y{enter}") ;menu reset send("{F3 5}") ; Run several reports send("1{enter}") send("8{enter}") ; Admissions Register MsgBox (64, "Step 1", "Admissions Register 1" ) send("9{enter}") send($mstart & "{NUMPADADD}") send($mend & "{NUMPADADD}") send("2{enter}") send("{tab 2}" & $prtqueue & "{NUMPADADD}{tab}Y{enter}") SLEEP(1000) MsgBox (64, "Step 2", "Admissions Register 2" ) send("9{enter}") send($mstart & "{NUMPADADD}") send($mend & "{NUMPADADD}") send("3{enter}") send("{tab 2}" & $prtqueue & "{NUMPADADD}{tab}Y{enter}") ; Discharge Register MsgBox (64, "Step 3", "Discharge Register 1" ) send("10{enter}") send($mstart & "{NUMPADADD}") send($mend & "{NUMPADADD}") send("2{enter}") send("{tab 2}" & $prtqueue & "{NUMPADADD}{tab}Y{enter}") SLEEP(1000) Do you want something like this...?... Edited March 6, 2014 by Starstar Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once." Link to comment Share on other sites More sharing options...
Damein Posted March 6, 2014 Share Posted March 6, 2014 You will want to clean up the code a little to better achieve what you want. But this is what you are looking for. $ReportToRun = InputBox("Reports", "Which report do you want to run?") If $ReportToRun = "Monthly" Then _RunMonthlyReport() ElseIf $ReportToRun = "Daily" Then _RunDailyReport() EndIf Func _RunMonthlyReport() MsgBox(0, "test", "Monthly Report") EndFunc Func _RunDailyReport() MsgBox(0, "Test", "Daily Report") EndFunc First you need a way to track which report they want to run. Simplest way is to use an http://www.autoitscript.com/autoit3/docs/functions/InputBox.htm'>Inputbox. Attach a variable to that so you can check what the user has input. IE: $ReportToRun will equal whatever they type out. The _RunMonthlyReport() tell the script to "go to" that function. Let me know if anything doesn't make sense! Most recent sig. I made Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic Link to comment Share on other sites More sharing options...
Starstar Posted March 6, 2014 Share Posted March 6, 2014 Welcome to autoit.......... Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once." Link to comment Share on other sites More sharing options...
Starstar Posted March 6, 2014 Share Posted March 6, 2014 Damein I think Creating a window(Gui Create) is better then using "if" command here.Because windows gives choice to user. Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once." Link to comment Share on other sites More sharing options...
breadhead Posted March 6, 2014 Author Share Posted March 6, 2014 Thanks so much for the input. What you guys suggest will certainly work, but let me throw this out there. On a normal run of this script, it would step through functions 1-30. If the script blows up, I would like to be able to say, start at function 15 and then step through the remaining functions. Some sort of "loop" I would imagine? Link to comment Share on other sites More sharing options...
breadhead Posted March 6, 2014 Author Share Posted March 6, 2014 Well I have been thinking about this and need some more input. Lets say that at the beginning you say you want to start at step 1. An array could be built that contains functions 1-30 and then the script would run the array. If you chose to start at step 15, an array would be built that contains 15-30 and then the script would run that array. Now, if that is viable, how would one code it? Link to comment Share on other sites More sharing options...
breadhead Posted March 8, 2014 Author Share Posted March 8, 2014 Can anyone help me with this function loop? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now