trumpet Posted December 12, 2006 Share Posted December 12, 2006 Hi, I am fairly new to using the autoit program. My question is probably very basic but I haven't yet figured out a way to this in autoit....Is there a way to read a line of text from NotePad in autoit and then enter that in a variable in an autoit script? Any help is appreciated. Link to comment Share on other sites More sharing options...
Glyph Posted December 12, 2006 Share Posted December 12, 2006 (edited) try this in an ini file, $0=(IniRead( @ScriptDir & '\Settings.ini', 'Test', '0', 'Message Here' )) Msgbox(0,"Test","Read: " &$0) oÝ÷ Øâ~)^ÄÞ²Ý Make a file called test.txt with this program, and itll read line "1"! Edited December 12, 2006 by backstabbed tolle indicium Link to comment Share on other sites More sharing options...
GaryFrost Posted December 12, 2006 Share Posted December 12, 2006 #include <Misc.au3> Run("Notepad") WinWaitActive("Untitled - Notepad") $h_Edit = ControlGetHandle("Untitled - Notepad", "", "Edit1") $text = "this is line 1" & @CRLF & "Line 2" & @CRLF & "Line 3" _WM_SETTEXT($h_Edit, $text) ConsoleWrite(_GetLine($h_Edit, 2) & @LF) Func _WM_SETTEXT($h_Edit, $s_Text) Local Const $WM_SETTEXT = 0xC Local $struct_string = DllStructCreate("char[" & StringLen($s_Text) + 1 & "]") DllStructSetData($struct_string, 1, $s_Text) _SendMessage($h_Edit, $WM_SETTEXT, 0, DllStructGetPtr($struct_string)) EndFunc ;==>_WM_SETTEXT Func _GetLine($h_Edit, $i_line) Local Const $WM_GETTEXT = 0xD Local $struct_string = DllStructCreate("char[4096]") If @error Then Return SetError(-1, -1, "") _SendMessage($h_Edit, $WM_GETTEXT, 4096, DllStructGetPtr($struct_string)) If @error Then Return SetError(-1, -1, "") Local $a_text = StringSplit(DllStructGetData($struct_string, 1), @CRLF, 1) If $i_line <= $a_text[0] Then Return $a_text[$i_line] Return SetError(-1, -1, "") EndFunc ;==>_GetLine SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
herewasplato Posted December 12, 2006 Share Posted December 12, 2006 ...read a line of text from NotePad in autoit and then enter that in a variable in an autoit script?...Welcome to the forum. You might want to close the file that is open in Notepad and use FileReadLine. See the sample code in the help file. If you still want to just get a line from Notepad into an Autoit variable, then consider the code/methods in the previous posts or run this little sample script:;start Notepad for a test script Run("Notepad") WinWait("Untitled - Notepad") WinActivate("Untitled - Notepad") WinWaitActive("Untitled - Notepad") ;put in some sample text ControlSetText("Untitled - Notepad", "", "Edit1", "test line 1" & @CRLF & _ "test line 2" & @CRLF & _ "test line 3" & @CRLF & _ "test line 4") ;read a line of text from Notepad Send("{HOME}") Send("{DOWN 2}") ;send shift end Send("+{END}") ;"read" line into the Windows clipboard Send("^c") Sleep(50) ;and then enter that in a variable in an autoit script ;get line from the Windows clipboard $variable = ClipGet() MsgBox(0, "", $variable) WinClose("Untitled - Notepad")...or you could use ControlSend instead of Send. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
trumpet Posted December 16, 2006 Author Share Posted December 16, 2006 try this in an ini file, $0=(IniRead( @ScriptDir & '\Settings.ini', 'Test', '0', 'Message Here' )) Msgbox(0,"Test","Read: " &$0) oÝ÷ Øâ~)^ÄÞ²Ý Make a file called test.txt with this program, and itll read line "1"! Link to comment Share on other sites More sharing options...
trumpet Posted December 16, 2006 Author Share Posted December 16, 2006 Thank-you for everyone's help. It is very much appreciated. Link to comment Share on other sites More sharing options...
CoDEmanX Posted February 16, 2008 Share Posted February 16, 2008 @gafrost: your code example doesn't work for me. i want to read out the content of several controls. ControlGetText didn't work on those ThunderRT6-Controls. So i'm searching a working WM_SETTEXT example for AutoIt3. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 16, 2008 Developers Share Posted February 16, 2008 No need to ask te same question multiple times. Show the code you have that isn't working but you say you want to read the text ? if so I guess you want to use WM_GETTEXT. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
CoDEmanX Posted February 17, 2008 Share Posted February 17, 2008 (edited) i want to use WM_GETTEXT and WM_SETTEXT. i got gafrost's code working, missed the second "Untitled - Notepad" --> "Unbenannt - Editor" (german xp) once WM_* is fully working, i will let a person try the same on ThunderRT6 controls. I can't test locally, 'cause i don't own OnQ (hotel software). These ThunderRT controls seem to be ActiveX controls or something similar. For the case WM_* isn't working, is there a workaround? successfully tested (notepad): Func _WM_GETTEXT($h_Edit) Local Const $WM_GETTEXT = 0xD Local $struct_string = DllStructCreate("char[4096]") If @error Then Return SetError(-1, -1, "") _SendMessage($h_Edit, $WM_GETTEXT, 4096, DllStructGetPtr($struct_string)) If @error Then Return SetError(-1, -1, "") Local $a_text = DllStructGetData($struct_string, 1) Return $a_text EndFunc ;==>_WM_GETTEXT Edited February 17, 2008 by CoDEmanX Link to comment Share on other sites More sharing options...
herewasplato Posted February 18, 2008 Share Posted February 18, 2008 ...These ThunderRT controls seem to be ActiveX controls or something similar...See here...http://www.autoitscript.com/forum/index.ph...st&p=169411... and read to the end of that thread.A search of the forum for "+Thunder +control" may turn up other info of use to you... or maybe not :-) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
CoDEmanX Posted February 19, 2008 Share Posted February 19, 2008 thxis this about controlling VB controls too? http://www.autoitscript.com/forum/index.ph...mp;#entry460392this is VBScript only right? http://www.autoitscript.com/forum/index.php?showtopic=38671 Link to comment Share on other sites More sharing options...
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