AutoHotkey Community

It is currently May 27th, 2012, 10:36 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: December 8th, 2007, 7:18 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Source

Online Documentation

Download Offline Documentation
(includes source of script)

Documentation wrote:
There is not much to say. With readLine() you can get lines specified in ranges (getting more than one line with one call) from a variable, instead of accessing a file directly. That way, the file will not be re-opened and loaded into memory every time a line reading process is beeing to start.

Indexes as offset from end of file (upwards) can be used also, meaning ‘0’ is the last line.

Additional regular expression filter can be specified, letting only those lines to copy, which matches the expression.


Last changes: Version 0.2 (9 December 2007)
  • Now, the parameter Source accepts a valid file path also and opens the file temporary in that case.
  • Wrote and separated the detailed online documentation.


Last edited by Tuncay on March 23rd, 2008, 7:57 pm, edited 5 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2007, 7:23 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Cool function. Nice work :)

Edit: How about also accepting a valid file path for _File, and reading the file into a temporary variable for the rest of the function? Might be nice to have the option to use either method.

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 8th, 2007, 7:40 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Thx. :)
My first version was with a temp variable and only accepting a file path. But that has disadvantages. I wanted avoid temporary copy of big vars, because of performance.
Also, this implies, that a file would be open and read every time a readLine() process is done. If the user would manually open the file and read into a variable, then he can use the variable on every subsequent readLine() process.

Not that alone, I wanted a function operating on variables instead on files, because file like contents can be created on the fly.

But having both (accepting file path and accepting content) would be better to have, but I dont now how to deal if I use ByRef parameter.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Update v0.2
PostPosted: December 9th, 2007, 6:17 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Updated to version 0.2, still in beta. Now it is possible that source is a valid file path string. The only thing which does not work is to giving over a string only, it must be a variable containing the path.

Code:
readLine(f := "file.txt")

would work, but not

Code:
readLine("file.txt")

Also I wrote a nice like the original AutoHotkey looking Documentation.

I realized, that some links in documentation are broken. I`ll fix that soon, but have to rebuild the whole documentation and uplaod again. All files are at my home computer! :x
edit: corrected links now.


Last edited by Tuncay on March 30th, 2008, 3:24 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 10th, 2007, 5:19 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
Cool added functionality :) Thanks for the update

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2008, 6:40 am 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
Why this one doesn't work?
Code:
f = 1941`ndarius`nkof98`nmslug5`nsamurai`ntmnt`nzupapa

; I want to get the first line.
ret := readLine(f, 1)
MsgBox,, %ErrorLevel%, %ret%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2008, 4:25 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
I have copied this code and downloaded the source again (to be sure) and tested it. That works fine here. May be you have an outdated AutoHotkey version. And don`t forget to #include the readLine.ahk.

Do you receive any warning or error message from AutoHotkey?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 30th, 2008, 3:38 am 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
Yes, it says "A call to a non existing function... The program will exit"


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 30th, 2008, 3:40 am 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
My AHK version is 1.0.47.04 (August 28, 2007)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 30th, 2008, 3:43 am 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
Tuncay wrote:
And don't forget to #include the readLine.ahk.


I am sorry, but I don't understand what you mean by "to #include the readLine.ahk".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 30th, 2008, 10:10 am 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
Tuncay wrote:
...And don`t forget to #include the readLine.ahk.

Can you please explain how I should do it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 30th, 2008, 3:18 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Oh I see, you are new to AutoHotkey and programming in general. The special command #Include does merge the script with another script. That way you can use the function in another script, for example readLine().

From documentation, here is the:

Put the readLine.ahk in same folder of your script and add following line in your script:

Code:
#Include readLine.ahk


From now on, everything in readLine.ahk is copied in your script. There is also a standard library mechanism ... but that is not that important now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 30th, 2008, 3:55 pm 
Offline

Joined: February 29th, 2008, 12:11 pm
Posts: 943
Thank you very much!!!


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 8 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