Sign in to follow this  
Followers 0
litlmike

Read and ReplaceString in a Control

14 posts in this topic

#1 ·  Posted (edited)

Is there a way to Replace a String of Text in a Control?

At work, we use Eudora as our email client. I wrote a script that inputs certain fields for me. However, I would like to replace 2 strings in the email body, the ConrtolID/ClassNameNN is "EudoraEdit1". The first string is 'NNNNN', and the second is 'XXXXX'.

I tried the code below, which worked, but caused formatting problems, and confirmed my initial thoughts that this isn't the best approach. If there is a ControlReplaceString command, that would work perfect. Or, maybe a ControlReadText would work. But, to my knowledge there isn't.

How do you propose that I accomplish the result? Thanks in advance.

Send("{CTRLDOWN}a{CTRLUP}{CTRLDOWN}c{CTRLUP}"); Selects ALL the text in the email body, and puts to the clipboard
$email_showing = ClipGet ( ); Put email body to clipboard

$AddNotes_New = StringReplace ( $email_showing, "NNNNN", $contact); Replaces 1st string 
$AddNotes_NewB = StringReplace ( $AddNotes_New, "XXXXX", $company); Replaces 2nd string 

ClipPut ( $AddNotes_NewB );puts to clipboard
Send("{CTRLDOWN}v{CTRLUP}"); pastes in email body, but with formatting loss

***EDIT*** Added Pic

Edited by litlmike

Share this post


Link to post
Share on other sites



Is there a way to Replace a String of Text in a Control?

At work, we use Eudora as our email client. I wrote a script that inputs certain fields for me. However, I would like to replace 2 strings in the email body, the ConrtolID/ClassNameNN is "EudoraEdit1". The first string is 'NNNNN', and the second is 'XXXXX'.

I tried the code below, which worked, but caused formatting problems, and confirmed my initial thoughts that this isn't the best approach. If there is a ControlReplaceString command, that would work perfect. Or, maybe a ControlReadText would work. But, to my knowledge there isn't.

How do you propose that I accomplish the result? Thanks in advance.

Send("{CTRLDOWN}a{CTRLUP}{CTRLDOWN}c{CTRLUP}"); Selects ALL the text in the email body, and puts to the clipboard
$email_showing = ClipGet ( ); Put email body to clipboard

$AddNotes_New = StringReplace ( $email_showing, "NNNNN", $contact); Replaces 1st string 
$AddNotes_NewB = StringReplace ( $AddNotes_New, "XXXXX", $company); Replaces 2nd string 

ClipPut ( $AddNotes_NewB );puts to clipboard
Send("{CTRLDOWN}v{CTRLUP}"); pastes in email body, but with formatting loss
check out ControlGetText() and ControlSetText()

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

check out ControlGetText() and ControlSetText()

Thanks for the input, but I am running across the same formatting problems. I tried both of the following methods below. Both provide me with an equally dissatisfactory result. The issue is that both methods are similar to a paste method. When something is pasted into the body of the email, it erases/destroys the signature at the bottom of the email. I will post a pic so you can get a visual (in the original post above).

If there was someway to just Replace a String in the Control, that would be perfect. Any ideas how to do this another way?

$email_body = ControlGetText ( "Eudora", "","EudoraEdit1" )
$AddNotes_New = StringReplace ( $email_body, "NNNNN", $contact)
$AddNotes_NewB = StringReplace ( $AddNotes_New, "XXXXX", $company)
ControlSetText ( "Eudora", "", "EudoraEdit1", $AddNotes_NewB )

$email_body = ControlGetText ( "Eudora", "","EudoraEdit1" )
ControlSetText ( "Eudora", "NNNNN", "EudoraEdit1", $contact ); I was hoping this would replace just the string of the control of the text.
ControlSetText ( "Eudora", "XXXXX", "EudoraEdit1", $company )

Share this post


Link to post
Share on other sites

Thanks for the input, but I am running across the same formatting problems. I tried both of the following methods below. Both provide me with an equally dissatisfactory result. The issue is that both methods are similar to a paste method. When something is pasted into the body of the email, it erases/destroys the signature at the bottom of the email. I will post a pic so you can get a visual (in the original post above).

If there was someway to just Replace a String in the Control, that would be perfect. Any ideas how to do this another way?

$email_body = ControlGetText ( "Eudora", "","EudoraEdit1" )
$AddNotes_New = StringReplace ( $email_body, "NNNNN", $contact)
$AddNotes_NewB = StringReplace ( $AddNotes_New, "XXXXX", $company)
ControlSetText ( "Eudora", "", "EudoraEdit1", $AddNotes_NewB )

$email_body = ControlGetText ( "Eudora", "","EudoraEdit1" )
ControlSetText ( "Eudora", "NNNNN", "EudoraEdit1", $contact ); I was hoping this would replace just the string of the control of the text.
ControlSetText ( "Eudora", "XXXXX", "EudoraEdit1", $company )
in that case, i suggest going with ControlSend() to enter the text, it's a little slower, but the way that the keystrokes are sent to the control will not affect the formatting.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

in that case, i suggest going with ControlSend() to enter the text, it's a little slower, but the way that the keystrokes are sent to the control will not affect the formatting.

This may be a step in the right direction, but it hasn't quite solved the riddle. It did send the text in a better way. Here is the new code I tried. You can help me first by understanding how "text" and "string" are used in reference to the different Control() commands. For instance, what part do they play in :

ControlSend ( "title", "text", controlID, "string")

In that, should I expect that the "string" to replace the "text" automatically? If so, that didn't happen for me. However, it is supposed to, then I need to take a new direction, maybe the text was hidden, etc.

$email_body = ControlGetText ( "Eudora", "","EudoraEdit1" )
ControlSend ( "Eudora", "NNNNN", "EudoraEdit1", $contact)
ControlSend ( "Eudora", "XXXXX", "EudoraEdit1", $company)

Share this post


Link to post
Share on other sites

This may be a step in the right direction, but it hasn't quite solved the riddle. It did send the text in a better way. Here is the new code I tried. You can help me first by understanding how "text" and "string" are used in reference to the different Control() commands. For instance, what part do they play in :

ControlSend ( "title", "text", controlID, "string")

In that, should I expect that the "string" to replace the "text" automatically? If so, that didn't happen for me. However, it is supposed to, then I need to take a new direction, maybe the text was hidden, etc.

$email_body = ControlGetText ( "Eudora", "","EudoraEdit1" )
ControlSend ( "Eudora", "NNNNN", "EudoraEdit1", $contact)
ControlSend ( "Eudora", "XXXXX", "EudoraEdit1", $company)
with controlsend() the string passed is actually sent as keystrokes into the control, it is typically only supposed to work for standard MS controls (although i've seen it work with many other types), which may be your issue if the text isn't appearing. another thing you can do, is to actually go back to Send() which isn't as nice as Control send, because it will require the window receiving the keystrokes to be activated, and the control to receive the keystrokes to have focus. that means that while it's sending the keystrokes, the message will be up, and the letters will appear one at a time, about a half a second after each other (250MS for the keydown delay and 250ms for sendkeydelay) if you don't edit the options in the script to speed them up. but you won't be able to use other windows etc as they're being sent, so the only benefit to automating this way would be that the script may type faster than you, but there would be several draw backs.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

with controlsend() the string passed is actually sent as keystrokes into the control, it is typically only supposed to work for standard MS controls (although i've seen it work with many other types), which may be your issue if the text isn't appearing. another thing you can do, is to actually go back to Send() which isn't as nice as Control send, because it will require the window receiving the keystrokes to be activated, and the control to receive the keystrokes to have focus. that means that while it's sending the keystrokes, the message will be up, and the letters will appear one at a time, about a half a second after each other (250MS for the keydown delay and 250ms for sendkeydelay) if you don't edit the options in the script to speed them up. but you won't be able to use other windows etc as they're being sent, so the only benefit to automating this way would be that the script may type faster than you, but there would be several draw backs.

Thanks for the feedback. Let me ask from another angle. What are the different ways to highlight the string 'NNNNN' on the email body? If I can do that, then I can just use Send($name).

Share this post


Link to post
Share on other sites

Thanks for the feedback. Let me ask from another angle. What are the different ways to highlight the string 'NNNNN' on the email body? If I can do that, then I can just use Send($name).

you can try ControlCommand(), but again i'm not sure how much success you're going to have since it's not a standard MS control...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

you can try ControlCommand(), but again i'm not sure how much success you're going to have since it's not a standard MS control...

ControlCommand? How does that work to highlight the string? I don't see any parameters that point me in that direction.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

So you basically want to do a mail merge?

No, not at all. I am trying to make a script for 10 employees that have the same Applications, like ACT!, and Eudora. But every employee will have different contacts in their ACT! database, and send different emails to their contacts. However, they have to take the info from ACT! and populate the info into their emails 20-60 times a day.

We could get the employees to name the fields they would like to auto-populate as strings like ,"NNNNN", "XXXXX", "NAME", etc. Now if only, I can find the best method to replace those strings. We are about 90% of the way in solving this issue. Just a few steps left.

*** Let me make a point of clarification. There is NO way to do this within the programs. It is stupid! We have looked into this extensively, and was our first course of action. ****

Edited by litlmike

Share this post


Link to post
Share on other sites

This worked with notepad:

Opt("SendKeyDelay", 1)
$name = "Test Name"
WinActivate("Untitled")
ControlFocus("Untitled", "", "Edit1")
ControlSend("Untitled", "", "Edit1", "{UP 50}{HOME}");Resets the cursor
$sel = ""
ClipPut("")
While StringInStr(ClipGet(), "NNNNN") == 0
    ControlSend("Untitled", "", "Edit1", "+{RIGHT}^c")
WEnd
ControlSend("Untitled", "", "Edit1", "{LEFT 5}+{RIGHT 5}" & $name)

Using this test text in an unsaved notepad window:

This is a test, i am waiting for the string:

NNNNN

Now it should replace and read "Test Name"

So this should work for Eudora *Untested*

Opt("SendKeyDelay", 1)
$name = "Test Name"
WinActivate("Eudora")
ControlFocus("Eudora", "", "EudoraEdit1")
ControlSend("Eudora", "", "EudoraEdit1", "{UP 50}{HOME}");Resets the cursor
$sel = ""
ClipPut("")
While StringInStr(ClipGet(), "NNNNN") == 0
    ControlSend("Eudora", "", "EudoraEdit1", "+{RIGHT}^c")
WEnd
ControlSend("Eudora", "", "EudoraEdit1", "{LEFT 5}+{RIGHT 5}" & $name)

Hope that helps.


[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

This worked with notepad:

Opt("SendKeyDelay", 1)
$name = "Test Name"
WinActivate("Untitled")
ControlFocus("Untitled", "", "Edit1")
ControlSend("Untitled", "", "Edit1", "{UP 50}{HOME}");Resets the cursor
$sel = ""
ClipPut("")
While StringInStr(ClipGet(), "NNNNN") == 0
    ControlSend("Untitled", "", "Edit1", "+{RIGHT}^c")
WEnd
ControlSend("Untitled", "", "Edit1", "{LEFT 5}+{RIGHT 5}" & $name)

Using this test text in an unsaved notepad window:

This is a test, i am waiting for the string:

NNNNN

Now it should replace and read "Test Name"

So this should work for Eudora *Untested*

Opt("SendKeyDelay", 1)
$name = "Test Name"
WinActivate("Eudora")
ControlFocus("Eudora", "", "EudoraEdit1")
ControlSend("Eudora", "", "EudoraEdit1", "{UP 50}{HOME}");Resets the cursor
$sel = ""
ClipPut("")
While StringInStr(ClipGet(), "NNNNN") == 0
    ControlSend("Eudora", "", "EudoraEdit1", "+{RIGHT}^c")
WEnd
ControlSend("Eudora", "", "EudoraEdit1", "{LEFT 5}+{RIGHT 5}" & $name)

Hope that helps.

Thanks for the input. This may be a viable option. I am very new to this, however. Do you mind giving me a play by play to what the commands are accomplishing? I was able to 'see' the program work, but it didn't quite do the job, and in order for me to modify it, I need to know what is going on. Thanks.

Share this post


Link to post
Share on other sites

...I was able to 'see' the program work, but it didn't quite do the job...

If you could be a bit more specific, I could help you more... As to the "play by play", I guess easiest would be line by line:

Opt("SendKeyDelay", 1)

This just sets the delay to 1ms (default= 5ms) so the script operates faster.

WinActivate("Eudora")
ControlFocus("Eudora", "", "EudoraEdit1")
ControlSend("Eudora", "", "EudoraEdit1", "^{HOME}");A more reliable method of putting the cursor at the beginning

WinActivate("Eudora") makes a window whose title contains "Eudora" become the topmost window. The next line makes the "EudoraEdit1" control have focus, and the next line ensures the cursor is at the beginning of the edit control. I modified that bit so that it's more reliable("^{HOME}" stands for "Ctrl+Home key", which in an edit control, puts the cursor at the beginning; the reverse happens when you hit Ctrl+End key)

$sel = ""
ClipPut("")
While StringInStr(ClipGet(), "NNNNN") == 0
    ControlSend("Eudora", "", "EudoraEdit1", "+{RIGHT}^c")
WEnd
ControlSend("Eudora", "", "EudoraEdit1", "{RIGHT}+{LEFT 5}" & $name);Added "RIGHT" key in case EudoraEdit1 doesn't work the same as Edit1 control

ClipPut("") just clears the clipboard by replacing whatever's there with "". Here's the bit that might get confusing. I've created a While loop that tests what's in the clipboard ("ClipGet()" returns a string containing what the clipboard contains) to see if it contains the string "NNNNN". The way I increment the loop is by selecting one more character each time ("+{RIGHT}" equals "Shift+Right arrow key", "^c" equals "Ctrl+c", copying the new selection to the clipboard). As soon as the clipboard contains "NNNNN", we know the selection ends just past the string, so the final line presses the right key once to place the cursor at the end of the selection, then "+{LEFT 5}" selects the 5 characters just to the left of the cursor (hopefully "NNNNN") and then sends the $name variable (in my case "Test Name") which replaces "NNNNN". I made a couple changes to the script to make it more reliable, so here it is:

Opt("SendKeyDelay", 1)
$name = "Test Name"
WinActivate("Eudora")
ControlFocus("Eudora", "", "EudoraEdit1")
ControlSend("Eudora", "", "EudoraEdit1", "^{HOME}");Resets the cursor
$sel = ""
ClipPut("")
While StringInStr(ClipGet(), "NNNNN") == 0
    ControlSend("Eudora", "", "EudoraEdit1", "+{RIGHT}^c")
WEnd
ControlSend("Eudora", "", "EudoraEdit1", "{RIGHT}+{LEFT 5}" & $name)

Hope that works better for you.


[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

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
Sign in to follow this  
Followers 0