AutoHotkey Community

It is currently May 27th, 2012, 5:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: LV_Add Help
PostPosted: January 25th, 2011, 8:21 pm 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
Hey, I'm trying to read a file and have it placed into a list view. I can do that just fine, but when I want it to have different columns (2 to be exact) I just can't grasp it.

File Contents
Code:
IN  08:00 AM Monday, January 24, 2011
OUT 09:30 AM Monday, January 24, 2011
IN  09:45 AM Monday, January 24, 2011
OUT 12:00 PM Monday, January 24, 2011
IN  01:00 PM Monday, January 24, 2011
OUT 02:30 PM Monday, January 24, 2011
IN  02:45 PM Monday, January 24, 2011
OUT 05:00 PM Monday, January 24, 2011


Code:
gui, add, ListView, w300 h500, Action|Date
Loop, Read, C:\punches.txt
LV_Add("",A_LoopReadLine)
gui, show, autosize center
return
guiclose:
 exitapp


Any help is appreciated! Thank you.

_________________
-Jeremiah


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2011, 8:34 pm 
Offline

Joined: May 15th, 2007, 8:59 pm
Posts: 169
You are going to have to split your line up.

Code:
gui, add, ListView, w300 h500, Action|Date
Loop, Read, C:\punches.txt
{
StringLeft, inout, A_LoopReadLine, 3 ; cut three characters off the left for "In" or "Out"
StringReplace, inout, inout, %a_space%,,All ;Remove extra spaces
StringTrimLeft, date, a_loopreadline, 4 ;Cut 4 characters off the left so you just have the date left
LV_Add("", inout, date) ;put the In or Out in column 1 and the date in column 2.
}
gui, show, autosize center
return
guiclose:
 exitapp


Last edited by icefreez on January 25th, 2011, 8:37 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2011, 8:36 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5482
Location: the tunnel(?=light)
To push data into columns beyond the first you just have to push data into additional parameter(s) of LV_Add():

Quote:
LV_Add([Options, Field1, Field2, ...]): Adds a new row to the bottom of the list. The parameters Field1 and beyond are the columns of the new row


Example using your data:

Code:
punches=
(
IN  08:00 AM Monday, January 24, 2011
OUT 09:30 AM Monday, January 24, 2011
IN  09:45 AM Monday, January 24, 2011
OUT 12:00 PM Monday, January 24, 2011
IN  01:00 PM Monday, January 24, 2011
OUT 02:30 PM Monday, January 24, 2011
IN  02:45 PM Monday, January 24, 2011
OUT 05:00 PM Monday, January 24, 2011
)

Gui, Add, ListView, w300 h500, Action|Time|Date
Loop, Parse, punches, `n, `r
   if   RegExMatch(A_LoopField,"s)(IN|OUT) (.*?(?:A|P)M) (.*)",_) ; used to sort the punch activity, time and date for their own columns
      LV_Add("",_1,_2,_3) ; pushes the subpatterns from RegExMatch to their own columns
Gui, Show, Autosize Center
return

GuiClose:
ExitApp

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2011, 9:12 pm 
Offline

Joined: April 20th, 2009, 1:10 pm
Posts: 817
Location: North Dakota, USA
@icefreez
You're example works perfect! Thank you very much.

@sinkfaze
Of course you're going to throw a RegEx at me. lol. Are you challenging me to learn this?

Well, here's a challenge for you... Let's get more columns in here.
Code:
Gui, Add, ListView, w300 h500, Action|Time|WeekDay|Month|Day|Year


There... try that Mr. RegEx master.

Also, while I try to figure out your RegEx, Are these matching quotes?
Code:
RegExMatch(A_LoopField,"s)(IN|OUT) (.*?(?:A|P)M) (.*)",_)

_________________
-Jeremiah


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2011, 9:29 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
Here's another example, for variety. It assumes a pattern of IN/OUT/IN/OUT...
Code:
punches =
(
IN  08:00 AM Monday, January 24, 2011
OUT 09:30 AM Monday, January 24, 2011
IN  09:45 AM Monday, January 24, 2011
OUT 12:00 PM Monday, January 24, 2011
IN  01:00 PM Monday, January 24, 2011
OUT 02:30 PM Monday, January 24, 2011
IN  02:45 PM Monday, January 24, 2011
OUT 05:00 PM Monday, January 24, 2011
)

Gui, Add, ListView, w500 r20 grid, IN|OUT

Loop, Parse, punches, `n, `r
 If InStr(A_LoopField,"IN")
  rowNum := LV_Add("",A_LoopField)
 Else LV_Modify(rowNum,"Col2",A_LoopField)
LV_ModifyCol()

Gui, Show
return
GuiClose:
 ExitApp


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: HotkeyStick, XstatyK and 81 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group