Jump to content

Run different parts of script based on Weekday


Recommended Posts

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')

 

 

Link to post
Share on other sites
  • Moderators

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

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

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

 

Link to post
Share on other sites
  • Developers

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
 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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.

Link to post
Share on other sites
  • 5 years later...
  • Developers
18 minutes ago, ashraful089 said:

is the below way correct?

You could simply test that and find out yourself without asking ...  right? ;) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By UE_morf_boon
      Hi!
      I have a program that has a specific function that renames the computer.
      The entire program should be executed only on behalf of the current user, because some registry keys in the HKCU are being changed.
      The current user does not have administrator rights, so #Requireadmin is not suitable as a solution.
      The administrator accounts on the computers are different, so "RunAs" is not suitable.
      Is there a way to trigger a UAC, when running a function?
      The function code, if you need:
      Func _RenamePC($Input2) Local $Name = GUICtrlRead($Input2) $objWMIService = ObjGet("winmgmts:\root\cimv2") For $objComputer In $objWMIService.InstancesOf("Win32_ComputerSystem") $oReturn = $objComputer.rename($Name) Next EndFunc  
    • By ahha
      I seem to have lost my sense of how the Global scope works.  In this example $p is Global but I can't seem to set $p in function __One and then pass that version of $p to function __Two.  I thought you could set a Global to a new value from within a function and it would affect the Global value. 
      I've stared and played with this code for over an hour and I'm missing something really basic.  Help appreciated.
      #AutoIt3Wrapper_run_debug_mode=Y ; use this to debug in console window <--- LOOK Global $p = 999 MsgBox(0, "DEBUG", "MAIN - $p = '" & $p & "'") __One() Exit Func __One() ;Global $p ;this seems to make no difference - comment it out to see - how does one affect the Global in a function? MsgBox(0, "DEBUG", "Entering Func __One() - $p = '" & $p & "'") For $p = 1 to 3 MsgBox(0, "DEBUG", "IN Func __One() - $p = '" & $p & "'") __Two() Next EndFunc Func __Two() MsgBox(0, "DEBUG", "Entering __Two() $p = '" & $p & "'") EndFunc  
    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.26 contains 214 functions divided into these topics:
      window, desktop and monitor GUI, mouse and color GUI controls including graphical buttons (jpg, png) logics and mathematics include constants string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info Change log and files section  on the PAL website (SourceForge).
      A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By meety
      My au3 script program needs administrator privileges on win10 to be executed correctly, because it needs to be added to the boot---Script code:RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      I need to let the program automatically get administrator privileges, so I use a function of #RequireAdmin. Although the program can be added to the boot, but does not execute after system boot up? why is that?
      What should I do?
      --------------------------------------------------------------------
      Update:
      I found that after using the #RequireAdmin function, the program cannot be executed after system boot up.
      An example is given below. after it is compiled, it will not be executed after system boot up in the following two ways.
      1. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\
      2. RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", @ScriptName, "REG_SZ", @ScriptFullPath)
      why is that?
      example
      #include <MsgBoxConstants.au3>
      #RequireAdmin
      Func test()
          MsgBox(0, "", "this is test message")
      EndFunc   ;==>test
      test()
       
       
    • By roeselpi
      hello again,
      it has been a long time since i have been here and a long time since i last used autoit. ever so often when the time allows me to, then i follow up on an idea that i had a long time ago. i have done all the work on paper but now it is up to writing it in autoit and i keep stumbling over many little issues here and there. sometimes after a few days i will try again and get a step further but sometimes it just will not help no matter how long i try and think about a solution. for most of you it will be the basics but for me it is not all that easy, but at least i give it a try.
      right, down to business:
      here is my code:
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <Array.au3> #include <String.au3> ; ; PART 1: define replacements and check with msgbox ; Global $y, $z $y = "Yes" $z = "No" MsgBox(0,"replacements", $y & @CRLF & $z) ;the replacements in a message box ; ; PART 2: set the texts and check via console and msgbox ; Global $my1string = "abab" ;the first specified text MsgBox(0,"my1string", $my1string) ;the message box to output the first specified text Global $my2string = "icic" ;the second specified text MsgBox(0,"my2string", $my2string) ;the message box to output the second specified text ; ; PART 3: transform the strings to individual arrays ; $my1array = StringSplit($my1string, "") $my1array[0] = "" _ArrayDelete($my1array, 0) _ArrayDisplay($my1array, "my1array") ;the display of the first specified array $my2array = StringSplit($my2string, "") $my2array[0] = "" _ArrayDelete($my2array, 0) _ArrayDisplay($my2array, "my2array") ;the display of the first specified array ; ; PART 4: create an empty array for filling ; Global $OutputArray[4] $OutputArray[0] = "" _ArrayDisplay($OutputArray, "OutputArray") ;the display of the first specified array ; ; PART 5: compare & fill empty OutputArray with data after evaluation ; Global $i, $j, $k For $i = 0 to UBound($my1array) -1 For $j = 0 to UBound($my2array) -1 For $k = 0 to UBound($OutputArray) -1 If $my1array[$i] = "a" And $my2array[$j] = "i" Then $OutputArray[$k] = $y Else $OutputArray[$k] = $z EndIf Next Next Next _ArrayDisplay($OutputArray, "OutputArray") ;the display of the Newly filled Array In "Part 2" i make a string that is converted to an array in "Part 3" ... Now, I know that "a" and "i" are always in the exact same spot in both arrays and so i wanted to compare this and make a further array to document my findings by saying "yes" or "no" ... however my new array keeps saying just "no" allthough i can clearly see and know that it should say:
      yes no yes no my guess is that there is something wrong within my for-loops and that the counting is somehow "off" i guess that when the first for-loop is finished it reaches the second whilst the second for-loop is checking the first which would explain why it always says "no" instead of seeing the obvious.
      so my question would be: what is wrong with my for-loop? or where am i making an error that ultimately gives me the wrong results?
      help is much appreciated.
      kind regards
      roeselpi
       
       
      PS: sorry for my not so great english spelling ... stupid german sitting here trying out intermediate english skills.
×
×
  • Create New...