Jump to content

Putting a macro into a variable?


Recommended Posts

I have a script that is based on time.

Something like this.

$time = INIREAD ("File", "Section", "Crap")

Do

Sleep (600000); 10mins

until $time

In this case the INI reads @HOUR = 10

so it should resolve to

Do

Sleep(600000)

Until @hour = 10

If I do a msgbox(0, "test", $time), I get a box that says @hour = 10

If I remove the variable, it works. So my question is, can I not store a macro into a variable?

Edited by wisem2540
Link to comment
Share on other sites

Macros can't be set by you (except @error and @extended). Read the content of the INI file into a variable and compare it like this:

Until @hour = $time

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

My original plan was to be able to set the INI to read the entire string

like this

[section]

time= @hour = 10 AND @WDAY = 1

So that anyone who wants to modify when this script runs, can just change that line in the INI.

I could specify a line for Hour, Min, Day, and everything else, but what if we dont want it that fine? Does this make sense?

Link to comment
Share on other sites

I would set weekday, hour and minute in your ini file like this. Then read the whole section using InIReadSection and the variables are set in your script.

[section]

hour=10

minute=0

weekday=1

In your script use something like
If @WDay = $weekday And @Hour = $hour and @Minute = $minute Then ...

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

The way I would do it is like this.

$sTime = IniRead("test.ini", "section", "time", "10,1,2")
$aTime = StringSplit($sTime, ",")
Do
    ; something gets done here 

Until @hour = $aTime[1] And (@WDAY = $aTime[2] or @WDAY = $aTime[3])

This is the ini file

[section]

time = 10,1,2

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I'm not sure what it is you're asking. Can you clarify that a bit?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

This is an example of a method I use to run a process on multiple days and times, controlled by an ini file. You can also change the times in the ini file without having to stop the AutoIt script

ini file example

[RUNAT]
;Format is wday:hour:min<sparator>
time=1:10:35|1:15:00|2:10:30|4:00:30|6:20:00
endtime=2013-04-28_12:00

$sTime = IniRead("test.ini", "section", "time", "")
$sEndTime = IniRead("test.ini", "section", "endtime", "")
$timer=TimerInit()
Do
    sleep(30000)
    if TimerDiff($timer) > 900000 Then
        ; Reread ini file every 15 min so you can change the times without having to restart the script
        $sTime = IniRead("test.ini", "section", "time", "")
        $sEndTime = IniRead("test.ini", "section", "endtime", "")
        $timer=TimerInit()
    EndIf
   
    if StringInStr($sTime,@wday&":"&@HOUR&":"&@MIN) Then
        ; if its one of the time to run
        ; run some process or function
    endif
    ;check if it is time to stop the script
Until @YEAR&"-"&@MON&"-"&@MDAY&"_"@HOUR&":"&@MIN > $sEndTime
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

I'm not sure what it is you're asking. Can you clarify that a bit?

Alright, so my idea failed. Perhaps I am just frustrated with it....

So lets just talk about one line in an INI. Day of the week

I want to be able to specity as many days (up to 7) that the script would run

Example...

[section]

Hour = 06

Day = 1,2,3

Should translate to If @Hour = 6 AND (@WDAY= 1 OR @WDAY=2 OR @WDAY=3)

But I need it to be flexible enough so that if someone puts in more values, such as 1,2,3,4,7 that it will still know to continue adding @WDAY

If this more clear Brewman?

Link to comment
Share on other sites

Here's a method I came up with that uses a "binary" representation of the days of the week in the ini file

Global $Mask[8] = [7, 0x1000000, 0x0100000, 0x0010000, 0x0001000, 0x0000100, 0x0000010, 0x0000001]
$sTime = IniRead("test.ini", "section", "Hour", "10")
$Days = IniRead("test.ini", "section", "day", 0x0101000)
Do
    Sleep(100)
    ; something gets done here
Until @hour = $sTime And $Mask[@WDAY] = BitAND($Mask[@WDAY], $Days)
ConsoleWrite("We're out of the loop" & @CRLF)

Here's the ini file.

[section]
Hour = 22
Day = 0x0001000

Each day of the week is represented by either a 1 or a 0, where you'd use a 1 to signify that you want it to exit the loop on that day of the week, Sunday is the left most digit after the 0x, and Saturday is the rightmost digit. You'll notice there are only 7 digits to the right of the 0x, that's not a problem as any bit not set is going to be a zero anyways. The Day in the ini file is set to Wednesday and all the rest are set to zero.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@wisem2540

Did you try my example in post #11 that gives you all the flexability and more that you are looking for.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Yes I did. While it does work, I prefered my original method. Mostly since I came up with it. While it may be not quite as neat as your example, It works for this purpose. Using the Execute command, outline in post 12 allowed me to use my own original idea.

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