AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Nested Loops

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
WhiteNight



Joined: 23 Feb 2005
Posts: 1

PostPosted: Wed Feb 23, 2005 4:40 pm    Post subject: Nested Loops Reply with quote

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
View user's profile Send private message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Wed Feb 23, 2005 4:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group