 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
WhiteNight
Joined: 23 Feb 2005 Posts: 1
|
Posted: Wed Feb 23, 2005 4:40 pm Post subject: Nested Loops |
|
|
I am new to this and need some help with a little problem. I have a list which looks like this:
Off at 12:55:24
Off at 13:10:27
Off at 13:25:24
On at 13:33:48
On at 13:40:24
On at 13:55:24
Off at 14:03:48
Off at 14:10:24
Off at 14:25:25
On at 14:38:01
On at 14:40:25
Off at 14:53:01
Off at 14:55:25
Off at 15:10:27
On at 15:16:45
Off at 15:17:48
Off at 15:25:25
What i want to do is take the first occurrence of “on” and match it with the next occurrence of “off”, then post that to a new file. So for every occurrence of “on” I want the corresponding “off” to be logged. The new file will look like this:
On at 13:33:48
Off at 14:03:48
On at 14:38:01
Off at 14:53:01
On at 15:16:45
Off at 15:17:48
I have played with it many different ways, like ifinstring and loop, parse, but I can’t seem to get it to work right. Any help would be appreciated. Thanks in advance. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3842 Location: Bremen, Germany
|
Posted: Wed Feb 23, 2005 4:53 pm Post subject: |
|
|
Hi,
By the look of your examples the result will be also ordered in time, right? So that there is nothing like this:
On 10:13
Off 11:15
On 11:01
Off 11:25
Or like this
On 10:13
Off 11:15
On 11:01
Off 11:10
If this is true, it is pretty simple. Make a loop over the timely ordered times. Check with if if it a "on" is the first parameter, put that line to a file and remeber that you now have a ON. In the next rounds you look for a "off". If you find one, put it to the file and start to look for on again
So it is kind of
| Code: | Status = ON
loop,read,...,...
{
stringleft, FirstChar,...
If (Status = "ON")
{
if (FirstChar = "On")
{
FileAppend,...
Status = OFF
}
}
else
{
if (FirstChar = "Off")
{
FileAppend,...
Status = ON
}
}
} |
untested
Edit: Corrected the {} _________________ Ciao
toralf  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|