TKO Posted June 27 Report Share Posted June 27 Hello there, hopefully you can help me out. I'm trying to put together a macro but I'm having a hard time with the logic, I'm autistic. The idea is to run the IF just once, the condition is date/time (T1 is current time and T2 is the goal time); - How do I stop it after the first time? The way it is, it keeps repeating during the whole minute because the condition is HH:MM I tried to do with hh:mm:ss but the macro misses the timing more often than not. Attached the macro in this topic.. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Cory Posted June 28 Report Share Posted June 28 I'm happy to help out but I can't figure out your intended logic from the script. Could you explain just the condition logic in plain English? And/or what you're wanting to do in general. Like do you want this to continue running until a certain time or a period of time? I'm most confused about you setting T1 and T99, presumably text variables, inside the loop. Aren't they always going to be the same then? First off you should be using time variables, and not text. Normally I would think that if you wanted to set a time before entering the loop. Maybe set by a user. Then check to see if it's past that time in the loop. I attached a crude demo. Time loop demo.mex Quote Link to comment Share on other sites More sharing options...
TKO Posted June 28 Author Report Share Posted June 28 9 hours ago, Cory said: I'm happy to help out but I can't figure out your intended logic from the script. Could you explain just the condition logic in plain English? And/or what you're wanting to do in general. Like do you want this to continue running until a certain time or a period of time? I'm most confused about you setting T1 and T99, presumably text variables, inside the loop. Aren't they always going to be the same then? First off you should be using time variables, and not text. Normally I would think that if you wanted to set a time before entering the loop. Maybe set by a user. Then check to see if it's past that time in the loop. I attached a crude demo. Time loop demo.mex 2.57 kB · 0 downloads Hey there, thanks for trying. I will try to explain it better. The macro would be running during the day no stop, when T1 (current time) met T2 (a time set manually in the variable), the text will be pasted in a different screen/field. T2 is just the first, the idea is to have others IF like T3, T4 etc with others times. Each time the timing is met (T1), the text will be added. The T99 would be the ending of the macro, also a time in the day. Crude example: T1 = current time T2 = 8am T3 = 10am T4 = 2pm T99 = 5pm Check T1, is it 8am? Do T2 Is it 10am? Do T3 and so on Is it 5pm? Stop the macro because it's over. That's what I came up with, I'm no programmer. I used to use Macro Express back in the day in online games 🙂 Quote Link to comment Share on other sites More sharing options...
acantor Posted June 28 Report Share Posted June 28 It looks like the value of %T1% will be the same as the value of %T99% the first time the script executes the second line. Neither variable was previously assigned, so I'm guessing both values will be zero. This means the condition in the "Repeat Until" statement is met, and execution will jump to the "Repeat End" line. It's hard to tell because I don't understand what the macro is supposed to do. But whatever it does, I believe that at least one of the "Date/Time save" instructions must appear before the "Repeat Until" instruction. It may help to begin with a simplified version of the macro, or a macro that displays only seconds... Repeat Start (Repeat 20 times) Date/Time: Set %CurrentTime% to the current date/time using "hh:mm:ss" as the format Date/Time: Set %CurrentSecond% to the current date/time using "ss" as the format MessageBox: Seconds at time = %CurrentTime% End Repeat <REPEAT START Start="1" Step="1" Count="20" Save="FALSE"/> <DATE/TIME Format="hh:mm:ss" Flags="\xB0" Date="27-Jun-2024 11:48:14 p.m." Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%CurrentTime%" IsDateVar="FALSE"/> <DATE/TIME Format="ss" Flags="\xB0" Date="30-Dec-1899" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%CurrentSecond%" IsDateVar="FALSE"/> <MESSAGEBOX Caption="Seconds at time = %CurrentTime%" Message="Current seconds: %CurrentSecond%" Icon="0"/> <END REPEAT/> Quote Link to comment Share on other sites More sharing options...
TKO Posted June 28 Author Report Share Posted June 28 7 hours ago, acantor said: It looks like the value of %T1% will be the same as the value of %T99% the first time the script executes the second line. Neither variable was previously assigned, so I'm guessing both values will be zero. This means the condition in the "Repeat Until" statement is met, and execution will jump to the "Repeat End" line. It's hard to tell because I don't understand what the macro is supposed to do. But whatever it does, I believe that at least one of the "Date/Time save" instructions must appear before the "Repeat Until" instruction. It may help to begin with a simplified version of the macro, or a macro that displays only seconds... Repeat Start (Repeat 20 times) Date/Time: Set %CurrentTime% to the current date/time using "hh:mm:ss" as the format Date/Time: Set %CurrentSecond% to the current date/time using "ss" as the format MessageBox: Seconds at time = %CurrentTime% End Repeat <REPEAT START Start="1" Step="1" Count="20" Save="FALSE"/> <DATE/TIME Format="hh:mm:ss" Flags="\xB0" Date="27-Jun-2024 11:48:14 p.m." Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%CurrentTime%" IsDateVar="FALSE"/> <DATE/TIME Format="ss" Flags="\xB0" Date="30-Dec-1899" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%CurrentSecond%" IsDateVar="FALSE"/> <MESSAGEBOX Caption="Seconds at time = %CurrentTime%" Message="Current seconds: %CurrentSecond%" Icon="0"/> <END REPEAT/> Hello, thanks for your input. I'm probably overcomplicating things, and failing to communicate. What I want to know/need is how to make the condition (IF T1 = T2) run just one time. As I'm using HH:MM, right now it is running during the whole minute, because the condition is met multiple times, instead of just once. Quote Link to comment Share on other sites More sharing options...
rberq Posted June 28 Report Share Posted June 28 12 hours ago, TKO said: I tried to do with hh:mm:ss but the macro misses the timing more often than not. You have greater than 1000 milliseconds in total delays, so hh:mm:ss should never "miss the timing" as it goes through the Repeat loop subsequent times. Look to the overall logic of the macro, which others have commented on. Quote Link to comment Share on other sites More sharing options...
Samrae Posted June 28 Report Share Posted June 28 17 hours ago, TKO said: - How do I stop it after the first time? It looks like you are using Macro Express 3. That may confuse some of us trying to help since many macro features are not available in that old version. To directly answer your question, without trying to figure out your logic, use the Break command to stop a repeat loop. Like this: Repeat Until %T1% = %T99% // <Set variables to hh:mm> If Variable %T1% = variable %T2% Mouse Move Screen 193, 270 Delay 99 Milliseconds Mouse Left Button Down Mouse Left Button Up Delay 640 Milliseconds Text Type: TEST EXAMPLE Delay 185 Milliseconds Mouse Move Screen 343, 653 Delay 185 Milliseconds Mouse Left Button Down Mouse Left Button Up Break End If Repeat End By the way, I cannot think of a reason you would need to use this command: Macro Playback Speed: Normal Speed That is the default behavior - the macro will play back at normal speed without this command. Quote Link to comment Share on other sites More sharing options...
acantor Posted June 29 Report Share Posted June 29 I'm not sure the following is what you have in mind. This macro begins by prompting you to enter the time the macro should stop. It prompts you twice: first for the hour, and then for the minute. It assumes a 24-hour clock. So if the desired stop time is 5 minutes to midnight, specify "23" for the hour, and "55" for the minutes. Then the macro displays the current time and the stop time, updating once a second. This continues until the current time = the stop time. Variable Restore: Restore All Variables // Prompt for stop hour (0 - 23) :GetStopHour Variable Set Integer %StopHour%: Prompt If Variable %StopHour% Is Less Than "0" OR If Variable %StopHour% Is Greater Than "23" MessageBox: Invalid stop hour Goto:GetStopHour End If // Prompt for stop minute (0 - 59) :GetStopMinute Variable Set Integer %StopMinute%: Prompt If Variable %StopMinute% Is Less Than "0" OR If Variable %StopMinute% Is Greater Than "59" MessageBox: Invalid stop minute Goto:GetStopMinute End If // Convert stop hour to a string. Prepend a zero if less than 10. Variable Modify Integer %StopHour%: Convert to Text String (%StopHourString%) If Variable %StopHour% Is Less Than "10" Variable Set String %StopHourString% to "0%StopHourString%" End If // Convert stop minute to a string. Prepend a zero if less than 10. Variable Modify Integer %StopMinute%: Convert to Text String (%StopMinuteString%) If Variable %StopMinute% Is Less Than "10" Variable Set String %StopMinuteString% to "0%StopMinuteString%" End If // Set stop time to "00" seconds Variable Set String %StopTimeString% to "%StopHourString%:%StopMinuteString%:00" // Get the current time in "hh:mm:ss" format Date/Time: Set %CurrentTimeString% to the current date/time using "hh:nn:ss" as the format // Loop until the stop time equals the current time. Update the current time every second Text Box Display: Progress... Repeat Until %StopTimeString% Equals "%CurrentTimeString%" Date/Time: Set %CurrentTimeString% to the current date/time using "hh:nn:ss" as the format Text Box Update: Progress... Delay: 1000 milliseconds End Repeat // We're done! Text Box Close: Progress... MessageBox: Done! // Save variables so we don't need to type stop hour and stop minute the next time the macro is run Variable Save: Save All Variables <VARIABLE RESTORE Option="\x00"/> <COMMENT/> <COMMENT Value="Prompt for stop hour (0 - 23)"/> <LABEL Name="GetStopHour"/> <VARIABLE SET INTEGER Option="\x01" Destination="%StopHour%" Prompt="Specify the hour the macro will stop (0 - 23)" Mask="FALSE" OnTop="TRUE" Left="Center" Top="Center" Monitor="0" Lines="\x00"/> <IF VARIABLE Variable="%StopHour%" Condition="\x02" Value="0" IgnoreCase="FALSE"/> <OR/> <IF VARIABLE Variable="%StopHour%" Condition="\x03" Value="23" IgnoreCase="FALSE"/> <MESSAGEBOX Caption="Invalid stop hour" Message="Specify a stop hour between 0 and 23." Icon="4"/> <GOTO Name="GetStopHour"/> <END IF/> <COMMENT/> <COMMENT Value="Prompt for stop minute (0 - 59)"/> <LABEL Name="GetStopMinute"/> <VARIABLE SET INTEGER Option="\x01" Destination="%StopMinute%" Prompt="Specify the minute the macro must stop (0 - 59)" Mask="FALSE" OnTop="TRUE" Left="Center" Top="Center" Monitor="0" Lines="\x00"/> <IF VARIABLE Variable="%StopMinute%" Condition="\x02" Value="0" IgnoreCase="FALSE"/> <OR/> <IF VARIABLE Variable="%StopMinute%" Condition="\x03" Value="59" IgnoreCase="FALSE"/> <MESSAGEBOX Caption="Invalid stop minute" Message="Specify a stop minute between 0 and 59." Icon="4"/> <GOTO Name="GetStopMinute"/> <END IF/> <COMMENT/> <COMMENT Value="Convert stop hour to a string. Prepend a zero if less than 10."/> <VARIABLE MODIFY INTEGER Option="\x04" Destination="%StopHour%" Variable="%StopHourString%"/> <IF VARIABLE Variable="%StopHour%" Condition="\x02" Value="10" IgnoreCase="FALSE"/> <VARIABLE SET STRING Option="\x00" Destination="%StopHourString%" Value="0%StopHourString%" NoEmbeddedVars="FALSE"/> <END IF/> <COMMENT/> <COMMENT Value="Convert stop minute to a string. Prepend a zero if less than 10."/> <VARIABLE MODIFY INTEGER Option="\x04" Destination="%StopMinute%" Variable="%StopMinuteString%"/> <IF VARIABLE Variable="%StopMinute%" Condition="\x02" Value="10" IgnoreCase="FALSE"/> <VARIABLE SET STRING Option="\x00" Destination="%StopMinuteString%" Value="0%StopMinuteString%" NoEmbeddedVars="FALSE"/> <END IF/> <COMMENT/> <COMMENT Value="Set stop time to \"00\" seconds"/> <VARIABLE SET STRING Option="\x00" Destination="%StopTimeString%" Value="%StopHourString%:%StopMinuteString%:00" NoEmbeddedVars="FALSE"/> <COMMENT/> <COMMENT Value="Get the current time in \"hh:mm:ss\" format"/> <DATE/TIME Format="hh:nn:ss" Flags="\xB0" Date="28-Jun-2024 10:46:10 p.m." Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%CurrentTimeString%" IsDateVar="FALSE"/> <COMMENT/> <COMMENT Value="Loop until the stop time equals the current time. Update the current time every second"/> <TEXT BOX DISPLAY Title="Progress..." Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Courier New;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs28 StopTimeString = \\lang1033 [%StopTimeString%]\r\n\\par \\lang4105 CurrentTimeString = \\lang1033 [%\\lang4105 Current\\lang1033 TimeString%]\\f1\\fs14 \r\n\\par }\r\n" Left="821" Top="Center" Width="795" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x02" Delay="0"/> <REPEAT UNTIL Variable="%StopTimeString%" Condition="\x00" Value="%CurrentTimeString%"/> <DATE/TIME Format="hh:nn:ss" Flags="\xB0" Date="30-Dec-1899" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%CurrentTimeString%" IsDateVar="FALSE"/> <TEXT BOX UPDATE Header="Progress..." Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Courier New;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs28 StopTimeString = \\lang1033 [%StopTimeString%]\r\n\\par \\lang4105 CurrentTimeString = \\lang1033 [%\\lang4105 Current\\lang1033 TimeString%]\\f1\\fs14 \r\n\\par }\r\n"/> <DELAY Flags="\x02" Time="1000"/> <END REPEAT/> <COMMENT/> <COMMENT Value="We're done!"/> <TEXT BOX CLOSE Header="Progress..."/> <MESSAGEBOX Caption="Done!" Message="The time %StopTimeString% has arrived!" Icon="2"/> <COMMENT/> <COMMENT Value="Save variables so we don't need to type stop hour and stop minute the next time the macro is run"/> <VARIABLE SAVE Option="\x00"/> Quote Link to comment Share on other sites More sharing options...
TKO Posted June 29 Author Report Share Posted June 29 16 hours ago, Samrae said: It looks like you are using Macro Express 3. That may confuse some of us trying to help since many macro features are not available in that old version. To directly answer your question, without trying to figure out your logic, use the Break command to stop a repeat loop. Like this: Repeat Until %T1% = %T99% // <Set variables to hh:mm> If Variable %T1% = variable %T2% Mouse Move Screen 193, 270 Delay 99 Milliseconds Mouse Left Button Down Mouse Left Button Up Delay 640 Milliseconds Text Type: TEST EXAMPLE Delay 185 Milliseconds Mouse Move Screen 343, 653 Delay 185 Milliseconds Mouse Left Button Down Mouse Left Button Up Break End If Repeat End By the way, I cannot think of a reason you would need to use this command: Macro Playback Speed: Normal Speed That is the default behavior - the macro will play back at normal speed without this command. Yes it's Macro Express 3.11, my bad, I should have said it earlier. Feel free to move this topic to the right forum section. Thanks everyone, I will give it a try in all your suggestions 🙏 Quote Link to comment Share on other sites More sharing options...
acantor Posted June 29 Report Share Posted June 29 These days, there is Macro Express 5 and Macro Express 6. The latter is referred to as Macro Express Pro. If you want to continue working on this macro, upgrade to the Pro edition. It supports date variables. Version 5 does not. Quote Link to comment Share on other sites More sharing options...
rberq Posted June 29 Report Share Posted June 29 3 hours ago, TKO said: Yes it's Macro Express 3.11, my bad, I should have said it earlier. Feel free to move this topic to the right forum section. At this point, there is little reason to move your question to another forum section. Your macro is technically "clean" and it runs, but apparently doesn't do quite what you want. I don't recall just how "DATE/TIME" works in version 3 of Macro Express; but I suspect the screen shot of the script that you provided is not showing us the details of what is being stored in T1 and T2 and T99. The format being stored is HH:mm, but is that current time, or a time you specify, or what? Quote Link to comment Share on other sites More sharing options...
TKO Posted June 30 Author Report Share Posted June 30 12 hours ago, rberq said: At this point, there is little reason to move your question to another forum section. Your macro is technically "clean" and it runs, but apparently doesn't do quite what you want. I don't recall just how "DATE/TIME" works in version 3 of Macro Express; but I suspect the screen shot of the script that you provided is not showing us the details of what is being stored in T1 and T2 and T99. The format being stored is HH:mm, but is that current time, or a time you specify, or what? Yeah T1 is current time, T2 a time I will set and T99 the ending time, also set by hand. I applied a few suggestions from the replies and it is now working 🙏 Thanks everyone Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.