kawliga751

Run different parts of script based on Weekday

7 posts in this topic

I'm new to Auotit but I have built a simple script that "runs" a different "batch" file based on certain days of the workweek. The script works now, but I was wanting to eliminate the need for a manual date entry. For example "First Batch' needs to run every Tuesday thru Thursday however "Second Batch" needs to run only on Friday and "Third Batch" needs to run only on Monday. In addition the 1st batch file runs on Tuesday, say 06/06 (the "FW" section) but then needs to actually report (the F4 date) the next weekday so this Batch actually needs 2 dates verified. 

What I'm trying to do is when the script is initiated it gets the date, verifies if and which weekday it is and in turn goes to and runs the appropriate "Batch' file.  

I've found ways to verify weekdays but can't find anything to do all of the above.

Any help is MUCH appreciated.

 

;P10
ShellExecute("C:\Program Files (x86)\Ericom Software\PowerTerm Enterprise\Sessions\mir00p10.PTS")


WinWait('(A) Soutwest P10 : PowerTerm Pro Enterprise Suite')
WinActivate('(A) Soutwest P10 : PowerTerm Pro Enterprise Suite')
Send('$Login)
Sleep(3000)
Send('{Enter}')
Sleep(3000)
Send($Password)
Send('{Enter}')
Sleep(3000)

; ****First Batch file run

Send('Batch')
Sleep(3000)
Send('{Enter}')
Send('FW')
Send('{Enter}')
Send('{DOWN}')
Send($Date)
Send('{Enter}')
Send('{Enter}')
Send($Date)
Send('{F9}')
Send('Y')
Sleep(3000)
Send('{Enter}')
Send('{F4}')
Send('Y')
Sleep(3000)
Send('{Enter}')
Send($Date)
Send('{Enter}')
Send('0620')
Send('{Enter}')
SEND('{!}SW0410PM.FWR')
Send('{Enter}')
Sleep(3000)
Send('Y')
Send('{Enter}')
Sleep(3000)
Send('{F9}')
Sleep(3000)

; ****Second Batch file run

Send('Batch')
Sleep(3000)
Send('{Enter}')
Send('FW')
Send('{Enter}')
Send('{DOWN}')
Send($Date)
Send('{Enter}')
Send('{Enter}')
Send($Date)
Send('{F9}')
Send('Y')
Sleep(3000)
Send('{Enter}')
Send('{F4}')
Send('Y')
Sleep(3000)
Send('{Enter}')
Send($Date)
Send('{Enter}')
Send('0620')
Send('{Enter}')
SEND('{!}SO0411AM.FWR')
Send('{Enter}')
Sleep(3000)
Send('Y')
Send('{Enter}')
Sleep(3000)
Send('{F9}')
Sleep(3000)

; ****Third Batch file run

Send('Batch')
Sleep(3000)
Send('{Enter}')
Send('FW')
Send('{Enter}')
Send('{DOWN}')
Send($Date)
Send('{Enter}')
Send('{Enter}')
Send($Date)
Send('{F9}')
Send('Y')
Sleep(3000)
Send('{Enter}')
Send('{F4}')
Send('Y')
Sleep(3000)
Send('{Enter}')
Send($Date)
Send('{Enter}')
Send('0620')
Send('{Enter}')
SEND('{!}SW0411AM.LOA')
Send('{Enter}')
Sleep(3000)
Send('Y')
Send('{Enter}')
Sleep(3000)
Send('{F9}')
Sleep(3000)
Send('EXIT')

 

 

Share this post


Link to post
Share on other sites

You could simply use the @WDAY macro in a switch, like so:

Switch @WDAY
    Case 2 To 4
        ;Call this Batch File
    Case 5
        ;Call This Batch File
    Case Else
        ;Do Something Else
EndSwitch

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can use @Wday macro to know the day of the week!

Switch @WDAY
    Case 1
        MsgBox(4096, "Day of the week", "Today is sunday", 3)
    Case 2
        MsgBox(4096, "Day of the week", "Today is Monday", 3)
    Case 3
        MsgBox(4096, "Day of the week", "Today is Tuesday", 3)
    Case 4
        MsgBox(4096, "Day of the week", "Today is Wednesday", 3)
    Case 5
        MsgBox(4096, "Day of the week", "Today is Thursday", 3)
    Case 6
        MsgBox(4096, "Day of the week", "Today is Friday", 3)
    Case 6
        MsgBox(4096, "Day of the week", "Today is Saturday", 3)
EndSwitch

EDITED: @JLogan3o13 we posted together!

Edited by Belini

Share this post


Link to post
Share on other sites

this looks very useful but, how would I make this call a specific "line" in the script?

As in how would :

Switch @WDAY
    Case 2 To 4

then go to 

; ****First Batch file run

$Date = InputBox("Date","Enter the Date To Run the Report","Date Here MMDDYYYY",'M8')

Send('Batch')
Sleep(3000)
Send('{Enter}')

 

Thanks again!

 

Share this post


Link to post
Share on other sites

Forget about GoTo and Just put the lines you want to perform under the Case statement and you're ready to go.
Another option is to put the code in separate Func statements and you run that Func from the Case statement.

Jos
 


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Thanks to all , this is perfect!

Share this post


Link to post
Share on other sites

one other suggestion - you may want to look at "ControlSend" instead of "send". The reason is Send only sends keystrokes to where ever the carrot is. If anything changes, your script breaks and all sorts of trouble can happen. ControlSend sends directly to the control in question so it makes things MUCH more stable.

Share this post


Link to post
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

  • Similar Content

    • Amixg
      By Amixg
      Hi! I have another problem with AutoIT.  You see, I'm still the one who's just starting out with this great programming language. I have a problem with AutoIT, it seems not to recognize the "StringReplace" function even when it is by default. The code was made half in KODA and half of my own. It is a software programmed for the Italian language (I am Italian) and translate the SMS language into Italian correct. Would you help me? Thanks in advance.
       
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $hull = "hello" StringReplace($hull, "hello", "hellx") $Form1 = GUICreate("Linguaggio SMS A Italiano", 507, 498, 192, 124) $Edit1 = GUICtrlCreateEdit("", 24, 40, 465, 177) GUICtrlSetData(-1, "") $Label1 = GUICtrlCreateLabel("Inserisci qui il testo che non riesci a capire:", 24, 8, 205, 17) $Label2 = GUICtrlCreateLabel("Ecco il testo tradotto(non toccare questo campo):", 27, 237, 237, 17) $Edit2 = GUICtrlCreateEdit("", 24, 264, 465, 137) GUICtrlSetData(-1, "") $Button1 = GUICtrlCreateButton("Traduci", 104, 424, 249, 49) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 StringReplace(GUICtrlGetData($Label1), "qlc", "qualcuno") StringReplace(GUICtrlGetData($Label1), "qls", "qualcosa") StringReplace(GUICtrlGetData($Label1), "ke", "che") StringReplace(GUICtrlGetData($Label1), "x", "per") StringReplace(GUICtrlGetData($Label1), "pls", "per favore") StringReplace(GUICtrlGetData($Label1), "tu6", "tu sei") StringReplace(GUICtrlGetData($Label1), "zzz", "mi fai dormire") StringReplace(GUICtrlGetData($Label1), "hagn", "Buonanotte") StringReplace(GUICtrlGetData($Label1), "tvtb", "Ti voglio tanto bene") StringReplace(GUICtrlGetData($Label1), "tat", "Ti amo tanto") StringReplace(GUICtrlGetData($Label1), "lafs", "Amore a prima vista") StringReplace(GUICtrlGetData($Label1), "fli?", "Flirtiamo?") StringReplace(GUICtrlGetData($Label1), "msidt", "Mi sono innamorato di te") StringReplace(GUICtrlGetData($Label1), "ba", "Bacio") StringReplace(GUICtrlGetData($Label1), "midi", "Mi dispiace.") StringReplace(GUICtrlGetData($Label1), "ntm", "Non ti merito") StringReplace(GUICtrlGetData($Label1), "tdp", "Togliti dai piedi.") StringReplace(GUICtrlGetData($Label1), "amò", "Amore") StringReplace(GUICtrlGetData($Label1), "ap", "A presto!") StringReplace(GUICtrlGetData($Label1), "cmq", "comunque") StringReplace(GUICtrlGetData($Label1), "cvd", "Ci vediamo dopo") StringReplace(GUICtrlGetData($Label1), "Tvb", "Ti voglio bene") StringReplace(GUICtrlGetData($Label1), "nn", "non") StringReplace(GUICtrlGetData($Label1), "risp", "rispondimi") StringReplace(GUICtrlGetData($Label1), "cel", "cellulare") StringReplace(GUICtrlGetData($Label1), "dom", "qualcosa") StringReplace(GUICtrlGetData($Label1), "nm", "numero") StringReplace(GUICtrlGetData($Label1), "fv", "favore") StringReplace(GUICtrlGetData($Label1), "-male", "meno male") StringReplace(GUICtrlGetData($Label1), "disc", "discoteca") StringReplace(GUICtrlGetData($Label1), "se#", "settimana") StringReplace(GUICtrlGetData($Label1), "+ o -", "più o meno") StringReplace(GUICtrlGetData($Label1), "ts", "torno subito") StringReplace(GUICtrlGetData($Label1), "tvtbcoa", "Ti voglio tanto bene come amica") EndSwitch WEnd  
    • Karnalsyn
      By Karnalsyn
      As with a lot of programming, the less manual repetition done to achieve the same outcome...the better.
      I package programs for network deployment at the organization I work for. Sometimes these applications require verbose messaging to the user, and sometimes by special request we have to turn that off and deploy silently.
      The way I currently handle these 2 scenarios is this.
      I have a function that builds the splashwin display screen to variable size depending on message length, and displays the desired message to the end user.
      Then at each point throughout my script as I need to make the user aware of what is currently happening, I inject a splashwin function call with the unique message pertaining to that specific event. ie. "Installing Microsoft Office, please wait..."
      In effort to build a more universal script to handle any type of request submitted. I've incorporated a switch command of '/silent'
      If cmdlineraw detects the usage of that switch when the script is triggered it sets a variable flag, ie. $silent = "on"
      Then at every splashwin call I make, I'm prefixing it with an IF statement that checks for the flag, and then does NOT display the message if that flag is "on". Or does display it if its not. Has worked for me just fine. But while I grow my programming skills and look for more streamlined ways of handling areas I find myself creating repetition. I'm curious if I can relocate that flag check. Taking it out of every single splashwin call, and injecting it into the function itself.
      Example of how I currently display or hide the splashwin based on command line...
      If StringInStr($cmdlineraw, "/silent", 0) Then
          $SilentSwitch = "ON"
      EndIf
      If $SilentSwitch = "OFF" Then SplashWin($Uninstalling & $ProductInfo[1][0])
      Some scripts have dozens of those splashwin calls littered throughout, so Is this the best approach I can take already? Or as stated earlier, can I pull the IF statement away from the splashwin call. And left the function as a whole either activate or deactivate as a result of the command line check.
    • wakillon
      By wakillon
      SciTE Hopper : Jump to Any line by one click and many other helpfull functions !


      As Ashalshaikh suggested me after leaving me the task to continue >SciTE Hopper, i open a new Topic about it.
      It will be more easy for futures updates.

      Many helpfull functions in contextual menu.
      SciTE Hopper is now multipurpose.
      • Color Catcher added
      • BinaryToAu3Kompressor added
      • TinyAu3Search replaced by StringFinder
      • RegJumper added
      • Edit With SciTE added (available in Options)
      • SpecialCharactersViewer added (available in Tray menu)
      New Contextual Menu :

      For a right Click on a function :

      • Copy function name
      • Insert a function header
      • Cut function
      • Copy function
      • Delete function
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments

      For entire script :

      • Create a functions List
      • Create a variables List
      • Remove usseless Blank lines
      • Remove Debug lines ( all lines starting with ConsoleWrite or _ArrayDisplay )
      • Set AutoIt Code Layout
      • Remove Comments
      • ( Open in SciTE a ) Duplicate of current Script in Temp Dir
      • ( Open in SciTE a ) Duplicate of current Script in Same Dir
      • Explore Parent Script Folder
      • Copy Script name
      • Copy Script path
      • Find Unused Functions
      • Find Unused Variables
      • Set all functions in alphabetic order.( func headers and regions ( in fact, all lines between functions ) are not supported.)

      SciTE Editor New Contextual Menu if SciTE Hopper is added ( in Options ) to SciTE Editor :
      when you made a selection in SciTE Editor you can :

      • Open a Reg Key in Regedit using RegJumper
      • Open a Url in your default Browser
      • Search on google in your default Browser
      • Search on AutoIt Website in your default Browser
      Now Can be added to windows start (minimized)
      Options are available by Tray Menu.
      A double click on tray icon will open clipboard content to SciTE Editor ( Handy when you have copied some code from your browser )

      How to proceed for add SciTE Hopper to SciTE Editor :
      Run Scite Editor, run Scite Hopper ( compiled! ) go to Options and select Add/Remove to SciTE Tab. then click on Add button and it's done !
      Right click on SciTE Editor and choose SciTE Hopper in Contextual Menu for run it when you need it !
      Update of 07 Dec 2017
      TinyAu3Search is replaced by StringFinder

      Previous downloads : 1287
      Script and compiled version are available in the download section
       
      Thanks to Ashalshaikh, Melba23, Th3 MMA, Alzri2, taitel, Manadar, taz742, Yashield, Authenticity, Xenobiologist for their help
      and asdf8 for his >Includes Helper and azjio for his >FileSearch.

      Hope it help you and happy Scripting !

       
    • Eli_jahbot
      By Eli_jahbot
      my esteemed autoits,
      i need your help once again. The bold and italics below are what i will be referring to. I need a message box to exit the script if Cancel is pressed and to continue the script if OK is pressed. I have tried multiple ways to do this to no avail. Can someone please breakdown how i go about this via Message box, and or Input box as I'm sure they will follow the same logic. I appreciate your time and assistance.
       
      Example:
      global $url, $username, $password, $sspassword
      $url = "https://securegateway.fairview.org"
      $username = "XXX"
      $password = "YYY"
      $sspassword = "ZZZ"
      #include <Constants.au3>
      #include <msgboxconstants.au3>
      ShellExecute ($url)
      WinWaitActive("window")
      send($username)
      send("{tab}")
      send($password)
      send("{enter}")
      msgbox($mb_okcancel, "Wait for the page to load then select OK to continue script", "Wait for the page to load then select OK to continue script")
      if($idok)
      send("+{tab 8}")
      send("{enter}")
      if ($idcancel) then Exit
      EndIf
    • mati
      By mati
      Hi,
      I wonder if
      AutoIt3Wrapper_run_debug_mode = Y can include run information about functions which are called within the main code. So far I noticed in the console that the function itself is called but no specific run information from  inside the function is provided. Is there a chance to show the entire debug log including functions in the console?
      I furthermore noticed a stop of information when a loop is entered. What could be the reason for that?
       
      Thanks for help.