Sign in to follow this  
Followers 0
wisem2540

Putting a macro into a variable?

18 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


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

Share this post


Link to post
Share on other sites

For instance.

If I wanted the line to read

Do-Until @hour = 10 AND (@WDAY = 1 OR @WDAY = 2)

that would seem almost impossible via an INI

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I understand, but I still cannot specify multiple weekdays with this example. Is that possible?

Share this post


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

Share this post


Link to post
Share on other sites

Could I build this out to 7 Days, but then only specify 2 days in the INI? I assume it would be fine, since the rest of the array would come back as "" or null right?

Share this post


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

Share this post


Link to post
Share on other sites

I think I may have it. What im wanting to do is exaclty what you have descrived. Except that I want the array to be able to grow and shrink based on the INI. Let me do some testing

thanks

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

If you want to keep your original method - you could try the execute command

$value="@hour"
MsgBox(0,"Hour",Execute($value))

$value="@sec=10"
do
Sleep(0)
until Execute($value)
Edited by BryanFisk
1 person likes this

Share this post


Link to post
Share on other sites

If you want to keep your original method - you could try the execute command

$value="@hour"
MsgBox(0,"Hour",Execute($value))

$value="@sec=10"
do
Sleep(0)
until Execute($value)

Thanks but that does not work.

Share this post


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

Share this post


Link to post
Share on other sites

Thanks but that does not work.

Actually I think it does work! I was just typing it wrong. I will continue to test this.

Thanks so much!

Share this post


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

Share this post


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

Share this post


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

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
Sign in to follow this  
Followers 0