Edun

Send string to specific row

6 posts in this topic

Alright I have done some simple things using AutoIT but now I have a little and most likely stupid problem.

I already have a working script where I use ControlSend to send strings in different textboxes in a program I use at work. Now I would like to know if there is a simple way to send something to specific row. For example if there would be a notepad file with 3 rows:

  1. Test1
  2. Test2
  3. Test3

Now I would like to send something to row 2 after the Test2 text. Should I just use something like @CRLF or arrow keys to get focus to correct place as I was planning or any smarter way to work this out?

Sorry for the stupid question. I usually find the answer reading forums and help files but for some reason not this one.

Share this post


Link to post
Share on other sites



43 minutes ago, l3ill said:

Instead of Send use FileWriteLine to write to your text file and use the line parameter.

Not sure if I can use that. Well maybe I could but then I'd need to rewrite the whole thing but my goal is to just add text to the end of specific line. Notepad was maybe a bad example since I'm not actually using it.

Right now I already got a handle of the program where I want to send strings. Like these:

   ControlSend($examplehandle, "", "[NAME:ToTextBox]", $sometext) ;Receiver of the email
   ControlSend($examplehandle, "", "[NAME:SubjectTextBox]", "Hello") ;Subject of the email

Those are single line text boxes so no problem sending strings there. Third text box where I want to send text is the email message itself which already contains some text. Let's say:

Hello!

My name is [mynamehere]

Best Regards,

Any way to use ControlSend or some other method using $handle to send my name there?

 

 

Share this post


Link to post
Share on other sites

Here is an example using Notepad that appends text to a specified line number.

#include <String.au3>

; -------- Create Notepad example ------------
If ProcessExists("notepad.exe") = 0 Then
    Run("notepad.exe")
    Local $hWnd = WinWait("[CLASS:Notepad]", "")
    ControlSetText($hWnd, "", "Edit1", "Hello!" & @CRLF & "My name is " & @CRLF & "Best Regards," & @CRLF)
EndIf
; ------ End of Create Notepad example ----------

Local $hWnd = WinWait("[CLASS:Notepad]", "")

Local $sText = ControlGetText($hWnd, "", "Edit1")
Local $appendage = "[mynamehere]"
Local $iLineNum = 2 ; <<<<<<< Enter line number to append text to here.

ControlSetText($hWnd, "", "Edit1", _AppendText2Line($sText, $appendage, $iLineNum))


Func _AppendText2Line($sText, $appendage, $iLineNum)
    Local $iPos = StringInStr($sText, @CRLF, 0, $iLineNum)
    Return _StringInsert($sText, $appendage, ($iPos = 0) ? StringLen($sText) : $iPos - 1) ; If @CRLF is not in $sText, then $appendage is appended to end of $sText.
EndFunc   ;==>_AppendText2Line

 

Share this post


Link to post
Share on other sites
4 hours ago, Malkey said:

Here is an example using Notepad that appends text to a specified line number.

#include <String.au3>

; -------- Create Notepad example ------------
If ProcessExists("notepad.exe") = 0 Then
    Run("notepad.exe")
    Local $hWnd = WinWait("[CLASS:Notepad]", "")
    ControlSetText($hWnd, "", "Edit1", "Hello!" & @CRLF & "My name is " & @CRLF & "Best Regards," & @CRLF)
EndIf
; ------ End of Create Notepad example ----------

Local $hWnd = WinWait("[CLASS:Notepad]", "")

Local $sText = ControlGetText($hWnd, "", "Edit1")
Local $appendage = "[mynamehere]"
Local $iLineNum = 2 ; <<<<<<< Enter line number to append text to here.

ControlSetText($hWnd, "", "Edit1", _AppendText2Line($sText, $appendage, $iLineNum))


Func _AppendText2Line($sText, $appendage, $iLineNum)
    Local $iPos = StringInStr($sText, @CRLF, 0, $iLineNum)
    Return _StringInsert($sText, $appendage, ($iPos = 0) ? StringLen($sText) : $iPos - 1) ; If @CRLF is not in $sText, then $appendage is appended to end of $sText.
EndFunc   ;==>_AppendText2Line

 

 

I think this will just do the trick. Wow, surprisingly hard, thought there would've been easier way to do this. Thanx a lot! Gonna try this one on my script :)

Share this post


Link to post
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