Jump to content

reading a line from notepad


trumpet
 Share

Recommended Posts

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

#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

...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

  • 1 year later...
  • Developers

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

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 by CoDEmanX
Link to comment
Share on other sites

...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

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...