KingYoshi Posted July 4, 2011 Posted July 4, 2011 Is there a way that I can either save text from an external text file to a variable within Autoit. Or insert text from a specific line of a text file, and have Autoit write it out? I understand how this would be done if I just wrote the text in the text file. The Goal: #1 A person edits a text file in any way they want. #2 Autoit reads the text on a specific line in the textfile and sets this to a variable #3 Autoit then sends the text held in the variable through Send("{Enter} $Variable {Enter}") I want someone to be able to edit an external text file, and change what that specific line of text says, therefore changing what text Autoit outputs. Thank you for any and all help/suggestions.
Moderators Melba23 Posted July 4, 2011 Moderators Posted July 4, 2011 KingYoshi,FileReadLine sounds like the function you need. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
KingYoshi Posted July 4, 2011 Author Posted July 4, 2011 Was looking at that function, however it seems to read the entire file. Is there a way to pinpoint a specific line of text within the file? Or could I have t look for a specific symbol such as ~ and then read all text inbetweeen two ~ ~?
somdcomputerguy Posted July 4, 2011 Posted July 4, 2011 Do you have a Help file anywhere? Read about that function, in particular how to use it, and then read about the _StringBetween function, for the 'all the text between the two ~~' thing. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
Moderators Melba23 Posted July 4, 2011 Moderators Posted July 4, 2011 KingYoshi, it seems to read the entire fileWhich bit of: FileReadLine Read in a line of text from a previously opened text file. FileReadLine ( "filehandle/filename" [, line] ) Parameters line [optional] The line number to read. gave you the idea it read the entire file? Are you sure you read the correct page in the Help file. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
KingYoshi Posted July 4, 2011 Author Posted July 4, 2011 Woops. I feel stupid. I completely missed the parameter!!! Thank you for your help.
Moderators Melba23 Posted July 4, 2011 Moderators Posted July 4, 2011 KingYoshi, It happens! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
KingYoshi Posted July 4, 2011 Author Posted July 4, 2011 I used the function and it works great. However the variable is not being outputted through Send("{Enter}/1" & $Msg1 & "{Enter}",1) Only Enter /1 Enter is being outputted. Source Code: expandcollapse popup; Press Esc to terminate script ; Press Pause to pause the script ; Random Sendkeydelay FileReadLine FileOpen Global $UnPaused, $Keypause, $Delay, $file, $Msg1 HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") $file = FileOpen("message.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $Msg1 = FileReadLine($file) If @error = -1 Then ExitLoop Wend FileClose($file) While 1 Sleep(100) ToolTip("Paused",0,0) WEnd Func TogglePause() $UnPaused = NOT $UnPaused While $UnPaused ToolTip("Sending...",0,0) $Keypause = Random(1, 5, 1) AutoItSetOption("SendKeyDelay", $Keypause) $Keypause = Random(1, 5, 1) AutoItSetOption("SendKeyDownDelay", $Keypause) Send("{Enter}/1" & $Msg1 & "{Enter}",1) $Delay = Random(5000, 6000, 1) Sleep($Delay) ;Insert copies HERE of above 5 lines for more messages WEnd EndFunc Func Terminate() Exit 0 EndFunc
KingYoshi Posted July 4, 2011 Author Posted July 4, 2011 I really find this weird, since I am getting no syntax errors when running it.. There has to be some sort of mistake in my code...
Moderators Melba23 Posted July 4, 2011 Moderators Posted July 4, 2011 KingYoshi, There has to be some sort of mistake in my code...Sure is! You are reading all the lines in one go until the end of the file - so at the end $Msg1 is empty as there are no lines left. You need to read and Send each line in turn. Try this - look for the <<<<<<<<< line: expandcollapse popup; Press Esc to terminate script ; Press Pause to pause the script ; Random Sendkeydelay FileReadLine FileOpen Global $UnPaused, $Keypause, $Delay, $file, $Msg1 HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") $file = FileOpen("message.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 Sleep(100) ToolTip("Paused",0,0) WEnd Func TogglePause() $UnPaused = NOT $UnPaused While $UnPaused ToolTip("Sending...",0,0) $Keypause = Random(1, 5, 1) AutoItSetOption("SendKeyDelay", $Keypause) $Keypause = Random(1, 5, 1) AutoItSetOption("SendKeyDownDelay", $Keypause) ; Read the next line of text ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $Msg1 = FileReadLine($file) If @error Then ; EOF so close the file and exit FileClose($file) ExitLoop EndIf Send("{Enter}/1" & $Msg1 & "{Enter}",1) $Delay = Random(5000, 6000, 1) Sleep($Delay) ;Insert copies HERE of above 5 lines for more messages WEnd EndFunc Func Terminate() Exit EndFunc Better? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
KingYoshi Posted July 4, 2011 Author Posted July 4, 2011 Thank you for the help with that and the notes. Am a bit rusty at this, so I have to get used to programming again. Also thank you for the notes they really helped!
Moderators Melba23 Posted July 4, 2011 Moderators Posted July 4, 2011 KingYoshi, My pleasure. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
KingYoshi Posted July 4, 2011 Author Posted July 4, 2011 (edited) Thank you for the help with that and the notes. Am a bit rusty at this, so I have to get used to programming again.Also thank you for the notes they really helped!Just tried your full version of the code, and it didn't work at all.After reading through it I thought it would, but when I added the corrections, it now doesn't output anything.It now can't seem to find the file!? Nothing had changed besides the code, so I am not sure why this is happening.Disregard the above.. It seems that somehow another file with the same name had been created, and was causing problems.. I am not sure how this is, as 2 files with the same name should not be able to exist within the same folder... (It was probably a different file type) Edited July 4, 2011 by KingYoshi
Moderators Melba23 Posted July 4, 2011 Moderators Posted July 4, 2011 KingYoshi,It worked for me when I tested it. when I added the correctionsSo what does it look like now? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now