AutoHotkey Community

It is currently May 27th, 2012, 9:09 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Help with Loop File
PostPosted: November 15th, 2011, 8:59 pm 
Offline

Joined: May 22nd, 2006, 2:12 pm
Posts: 150
Hi!

I found this script in the forum, and I have been trying to change it so it sends one line from a text file, waits for a trigger key, and then sends the next line and so on.

I've tried modifying it by splittng off the line that increments it, but it still just copies everything from the first file and dumps it into the second. Does anyone know what I am doing wrong?


Code:
Start: ; label at the beginning of the script used for the "Goto" command later on.
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.


FileSelectFile, casenum, 1,,Please choose a text file to read from;, *.txt ; Opens file select dialog box for user to choose file to read from. Places chosen file details into variable named "casenum".

If ErrorLevel = 1 ; Check to see if dialog box was cancelled, rather than a file being chosen.
{   Msgbox, 5,You must choose a file to continue. ; If no file was chosen, show message box offering a retry or cancel option.
   IfMsgBox Retry
          Goto Start ; Restart at beginning of script if user clicked on "retry".
   else
          MsgBox,,This will stop the script! ; Show message if user clicked "cancel" and exit.
   ExitApp
}


;Opens Internet Explorer

WinMaximize, winword
sleep, 2000
f1::
;starts loop
Loop
{
   FileReadLine, line, %casenum%, %A_Index%
          if ErrorLevel
           break
   



;Sends the input from the text file selected earlier
SendInput %line%
Send,{enter}
}
return

f2::

lineno++ ; Increment the line number to read variable by 1, so the script reads the next line in the next pass of the loop.

return


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2011, 12:42 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
Here's how I would do it:
Code:
;! AutoHotkey_L
FileSelectFile File ; Yes I am that lazy.
f := FileOpen(File, "r `n")

F1::
Loop
   If (line := f.ReadLine()){
      If (text := RTrim(line, "`n")){
           Send % text . "{enter}"
           return
      }
      continue
   }
   else break
MsgBox "Done reading file!"
It sends one line of the file per press of F1. It omits blank lines.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2011, 9:06 pm 
Offline

Joined: May 22nd, 2006, 2:12 pm
Posts: 150
Thanks! That's exactly what I was looking for. I was wondering... I tried to enter a {home}{del 20} before the % text . "{enter}" (to clear the previous entry, but it errored out. Do I have to quotations around the send and del for it to work?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2011, 9:51 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
I prefer expression mode in general, which is how I posted:
Code:
Send % text . "{enter}"

You need either expression mode:
Code:
Send % "{home}{del 20}" . text . "{enter}"

or traditional mode (cleaner):
Code:
Send {home}{del 20}%text%{enter}

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2011, 9:53 pm 
Offline

Joined: May 22nd, 2006, 2:12 pm
Posts: 150
Oh! Now I see! Thanks!


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: Bing [Bot], BrandonHotkey, tomoe_uehara and 70 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