Sign in to follow this  
Followers 0
starczar

Controlsend Random Problem

20 posts in this topic

Greetings;

I recently wrote a new script that seems to be having random problems with the CONTROLSEND function. The line of code in question is:

controlsend ("Select Import File","","Edit1","c:\~Projects\Convention2006\full-in-1.csv{ENTER}")

Sometimes it works correctly but sometimes it sends the wrong characters to the window. For instance today it sent c;\~Projects\Convention2006\full-in-1.csv{ENTER} (the 2nd character was wrong and it added an extra 3rd character from out of nowhere).

Any ideas?

Share this post


Link to post
Share on other sites



Did you try doing it like this:

ControlSend('Select Import File', '', 'Edit1', 'c:\~Projects\Convention2006\full-in-1.csv', 1)
ControlSend('Select Import File', '', 'Edit1', '{ENTER}')


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Any specific program you send to?

dim $i
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
for $i = 0 to 50
ControlSend('Untitled - Notepad', '', 'Edit1', 'c:\~Projects\Convention2006\full-in-1.csv{ENTER}',0)
next

Did not faile once, on three tries.

EDIT: Added test code.

Edited by Uten

Share this post


Link to post
Share on other sites

Any specific program you send to?

dim $i
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
for $i = 0 to 50
ControlSend('Untitled - Notepad', '', 'Edit1', 'c:\~Projects\Convention2006\full-in-1.csv{ENTER}',0)
next

Did not faile once, on three tries.

EDIT: Added test code.

I have had it run dozens of times successfully, then it will randomly fail, usually once, but sometimes more than once, then it works again without problem for some time. I am begenning to suspect that it may be a hardware issue with the box the script runs on.

As for the program, it is 3rd party software called "The Raisers Edge" made by a company called Blackbaud. In my opinion, Blackbaud's software needs some serious reengineering, but that is a whole different topic for a different place.

Share this post


Link to post
Share on other sites

I have had it run dozens of times successfully, then it will randomly fail, usually once, but sometimes more than once, then it works again without problem for some time. I am begenning to suspect that it may be a hardware issue with the box the script runs on.

As for the program, it is 3rd party software called "The Raisers Edge" made by a company called Blackbaud. In my opinion, Blackbaud's software needs some serious reengineering, but that is a whole different topic for a different place.

Could be a memory glitch. You could try a iso from http://www.memtest86.com/ to test your memory.

Share this post


Link to post
Share on other sites

Did you try doing it like this:

ControlSend('Select Import File', '', 'Edit1', 'c:\~Projects\Convention2006\full-in-1.csv', 1)
ControlSend('Select Import File', '', 'Edit1', '{ENTER}')
That didn't fix it, but thank you.

Share this post


Link to post
Share on other sites

Could be a memory glitch. You could try a iso from http://www.memtest86.com/ to test your memory.

It passed the memory test.

I replaced the line:

Opt("SendKeyDelay", 15)

with

Opt("SendKeyDelay", 50)

So far, it has run without error, but as this is a random error, i don't truly knwo if I have solved the problem.

Share this post


Link to post
Share on other sites

That didn't fix it, but thank you.

The only other thing I can think of that might help if your PC isn't the thing having issues is:
ControlSetText('Select Import File', '', 'Edit1', 'c:\~Projects\Convention2006\full-in-1.csv')
ControlSend('Select Import File', '', 'Edit1', '{ENTER}')

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

The only other thing I can think of that might help if your PC isn't the thing having issues is:

ControlSetText('Select Import File', '', 'Edit1', 'c:\~Projects\Convention2006\full-in-1.csv')
ControlSend('Select Import File', '', 'Edit1', '{ENTER}')
I wont know until/if it errors again. So far, 3 seperate runs of the script after increasing the sendkeys delay have been successful. Althought it now sorta looks like it is getting its text form an old 300 baud modem. :)

Share this post


Link to post
Share on other sites

I wont know until/if it errors again. So far, 3 seperate runs of the script after increasing the sendkeys delay have been successful. Althought it now sorta looks like it is getting its text form an old 300 baud modem. :)

The set text doesn't need the send delay, that may be the route to take :mellow:

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

It passed the memory test.

I replaced the line:

Opt("SendKeyDelay", 15)

with

Opt("SendKeyDelay", 50)

So far, it has run without error, but as this is a random error, i don't truly knwo if I have solved the problem.

If you use your computer as I do (24/7) you should lett it run overnight, and with all the tests. I have computers passing the simple test and failing an extensive test.

Share this post


Link to post
Share on other sites

...Althought it now sorta looks like it is getting its text form an old 300 baud modem. :)

Are you changing/testing with your script or running what Smoke_N and Uten posted? ControlSetText is fast.

Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
For $i = 1 To 200
    If Not ControlSetText('Untitled - Notepad', '', 'Edit1', 'c:\~Projects\Convention2006\full-in-1.csv') Then MsgBox(0, "", "window/control is not found")
    If Not ControlSend('Untitled - Notepad', 'c:\~Projects\Convention2006\full-in-1.csv', 'Edit1', '^a{BS}') Then MsgBox(0, "", "possible typo from first controlsettext")
Next
WinClose('Untitled - Notepad')
Please just run that code and post the results.

It is important to know if you have replicated the problem with notepad... and is it only the one character the errs? Seems odd that hardware would be so selective about what to messup.


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

I wont know until/if it errors again. So far, 3 seperate runs of the script after increasing the sendkeys delay have been successful. Althought it now sorta looks like it is getting its text form an old 300 baud modem. :)

I you get the text from this modem just write in a log file what you received by

FileWriteLine("logfile.txt", @HOUR & ":" & @MIN & ":" & @SEC & " " & $recvstring)

You can prove that it is the modem or not :mellow:

Share this post


Link to post
Share on other sites

I you get the text from this modem just write in a log file what you received by

FileWriteLine("logfile.txt", @HOUR & ":" & @MIN & ":" & @SEC & " " & $recvstring)

You can prove that it is the modem or not :)

I think that was a joke... but then again I could be wrong :mellow:

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

The MODEM reference was a joke. I had set the delay so high that it looked like you were watching an old 300 baud MODEM putting text on the screen. (Yes, I've been working with computers that bloody long.)

As for running the memory test overnight, my scripts run at nigth so I can't, but I'll let it run all day as soon as I have the opportunity.

Also, I shall experiment with ControlSetText... that looks like a much better route to go for not only this script, but several other scripts.

Finally, I will experiment with the provided test code and see if Notepad will reproduce the error.

Ironically, I have only had problems when attempting to script The Raisers Edge, and only in 2 of my 4 Raisers Edge scripts. Both errors involve ControlSend, but SendKeys tends to work. There are too many variables for a quick resolution, especially since the glitch is random.

Standby for the results of further testing and experimentation (to be posted later today or tomorrow).

Share this post


Link to post
Share on other sites

...Finally, I will experiment with the provided test code and see if Notepad will reproduce the error...

I think that the notepad/script test will tell you a lot. It should be subject to the same hardware issues. The version that I posted uses ControlSetText and ControlSend... and it checks for the success of finding the control. However, I took jpm's input as a serious suggestion to add a filewrite into the mix. I think that he knows that modem = script in the context of this thread. You might want to add such. It gets the data being sent/checked out of the realm of the control functions and it would be easy to test for an errant character after the test.

Anyway, that is not why I was posting - if, say a 1000 iterations of the notepad tests pass, you might want to write a similar test script using the one window of the app of interest (The Raisers Edge). Bring up that window, send the text, check the text that was sent, close that window (ESC) and repeat as much as you would like.

Happy testing :-)


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

I think that the notepad/script test will tell you a lot. It should be subject to the same hardware issues. The version that I posted uses ControlSetText and ControlSend... and it checks for the success of finding the control. However, I took jpm's input as a serious suggestion to add a filewrite into the mix. I think that he knows that modem = script in the context of this thread. You might want to add such. It gets the data being sent/checked out of the realm of the control functions and it would be easy to test for an errant character after the test.

Anyway, that is not why I was posting - if, say a 1000 iterations of the notepad tests pass, you might want to write a similar test script using the one window of the app of interest (The Raisers Edge). Bring up that window, send the text, check the text that was sent, close that window (ESC) and repeat as much as you would like.

Happy testing :-)

There has become some confusion as to the purpose of this script. Writing the text to a file would be compeltely irrelevant as the text is hard-coded into the script and all it is is the lcoaiton of datafiles that need imported into The Raisers Edge. The line is from a larger section of code, which (as modified with suggestions posted by people here) now reads:

MouseClick ( "left", 515, 265)
  WinWaitActive ("Select Import File","")
  controlsend ("Select Import File","","#32770","{alt}n")
  ControlSetText('Select Import File', '', 'Edit1', 'c:\~Projects\Convention2006\full-in-1.csv')
  ControlSend('Select Import File', '', 'Edit1', '{ENTER}')
  WinWaitActive ("Import - !!AUTOMATION - Convention2006","")
  controlsend ("Import - !!AUTOMATION - Convention2006","", "","{ALT}fi")
  winwaitactive ("Import - The Raiser's Edge for Windows")
  controlClick ("Import - The Raiser's Edge for Windows","",1, "left")

There are 12 variations of this code, being used by 12 different import funcitons in the software. Due to each import being different, it was easier to copy/paste code and edit rather than loop it.

Unfortuantely, The Raisers Edge is written in such a way that scripting it is nearly impossible... unless you pay for their $7,000 VBA module. They have several other annoyances that make it very difficult to even find the controls you are trying to script. Sometimes mouse coordinates and sendkeys are the only option. They don't even have proper tab/keyboard shortcuts for many of their things. It is a pity our company is "stuck" with it.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I understood your original post to be dealing with something akin to a file open dialog box.

I was more interested in finding the root cause

(listed in no particular order):

AutoIt (not that you blamed this)

your code

your hardware

the app being controlled (my bet)

something else

In my last post, I attempted to convey that my little test (which I stole from Uten) has a problem. It uses one control function to test another control function. I should have stuck with the "If WinExits" for the automated check of ControlSend or ControlSetText.

A flaw in the way AutoIt uses the OS for Control functions

or

in the OS itself might not show up with that code. A filewrite or WinExists (or both) might help the test.

Then I attempted to say that you might want to code your own loop using the window from the app of interest (The Raisers Edge). It would sure be nice to hear that notepad had no problems and The Raisers Edge failed at times. Having notepad pass should take the hardware out of the mix. Right now, all we know is that The Raisers Edge fails at times with ControlSend and we don't know why.

Come to think of it, you should probably test with The Raisers Edge first to get a feel for the failure rate when testing with relatively fast loops. Oh well, sorry for any detour from where you may have wanted this thread to go.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

Is your computer harried? Too slow to keep up with the script automation? Memory poor? Too many other things running in the background?

Would putting a slight pause between the WinWaitActive and ControlSend/ControlClick allow The Raisers Edge to possibly finish painting the GUI or finish getting ready for further input?

WinWaitActive ( "title" [, "text" [, timeout]] )

Sleep ( delay )

ControlSend ( "title", "text", controlID, "string" [, flag] )

Notes from latest Help file: ControlSend is only unreliable for command prompts as that works differently to normal windows (seems to check physical states rather than accepting the keystroke messages).

Suggestion: Sprinkle Sleep commands throughout your script with a global delay variable just before sending any keystrokes or mouse clicks and see if the problem diminishes and then tweak that delay variable for a balance between reliability and speed of execution.

Share this post


Link to post
Share on other sites

Stepping back and looking at the overall picture from a greater distance (and having never been exposed to The Raisers Edge):

Are you getting The Raisers Edge to import a CSV file into Excel? Maybe you could do it another way, using the Microsoft Office COM functionality behind the scenes without having to purchase the VBA addon modules. Maybe you should be waiting for Excel to come up, or activating it with a WinWaitActive just prior to the import function so that the Excel import modules are memory resident and ready to go, rather than the next window of The Raisers Edge? Just wondering aloud...

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