Jump to content

Mid-Macro copy from 1st .txt line and paste into app, then 2nd, etc.


brand00m
 Share

Recommended Posts

Hi all, I have a relatively simple script I have been trying to write... my apologies for not referencing how I began but I have a script that I am trying to implement keyclicks and mouseclicks... I would like to be able to copy the line of a text file, from start to finish, but command when the paste is happening. It is not once per whole macro loop (it is twice). I have attached the code I am trying to improve upon.

Local Const $File = "C:\Users\Brandoom\Desktop\practice.txt"
WinActivate("Creo Parametric")
Global $Handle = FileOpen($File, 0)
If $Handle = -1 Then
MsgBox(0x10, 'Error', 'Could not open the file:' & @LF & $File)
Exit
EndIf

HotkeySet('^{RIGHT}', 'NextLine')
HotkeySet('{ESC}', 'Done')

NextLine()

While 1
Sleep(0x7FFFFFFF)
WEnd

Func NextLine()
Local $NextLine = FileReadLine($Handle)
If @Error Then
MsgBox(0x40, 'End of File', 'The end of the file has been reached.')
Done()
EndIf
ClipPut($NextLine)
TrayTip('Copied to Clipboard', $NextLine & @LF & @LF & 'Ctrl+Right: Next line' & @LF & 'Esc: Quit', 5, 1)
EndFunc

Func Done()
FileClose($Handle)
Exit
EndFunc

Again, I would like to be able to copy and paste from a text file line by line, and have a hotkey that increments the FileReadLine or something to that effect to process through an entire .txt file. I cannot seem to get it to do my mouseclicks and send commands without restarting from the beginning of the script after I press the paste hotkey ctrl+right. Thank you all for your help!

B

Edited by brand00m
Link to comment
Share on other sites

I have SOLVED my problem. I added the following notation to run my macro, and when I wanted to step through, added another read line midway through my code, I have sampled what i did in case anyone else stumbles onto a similar problem.

$iTotalLines = StringSplit($hFileRead, Chr(10))
For $i = 1 To $iTotalLines[0]
$sLineRead = FileReadLine($hFileOpen, $i)
$i=$i+1 ;next 3 lines read into next line without breaking loop
$sLineRead = FileReadLine($hFileOpen, $i)
clipput($sLineRead)
Next

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...