Jump to content

ControlSend ":"


THeckel
 Share

Recommended Posts

When using ControlSend to send a string to an "edit" field I get unexpected results. So, I need some guidance from the community.

I'm sending a string in the form yyyy-ddd-HH:MM:SS. For now I'm hard coding the year and time. So for now I'm sending a string that looks like this: "2012-311-13:33:33".

What I get in the edit box is something on the order of "2012-311-13:33#3". The actual value seems to vary a litle with each run. I can substitute a space or another character like an "a" for the second ":" and the string populates the box just fine. It is the second ":" that seems to be the problem.

Info Window:

>>>> Window <<<<
Title: Telemetry_Analysis
Class: TopLevelShell
Position: 100, 100
Size: 808, 702
Style: 0x16CF0000
ExStyle: 0x00000100
Handle: 0x000D03AC

>>>> Control <<<<
Class: Edit
Instance: 15
ClassnameNN: Edit15
Name:
Advanced (Class): [CLASS:Edit; INSTANCE:15]
ID:
Text: text
Position: 379, 69
Size: 139, 17
ControlClick Coords: 67, 9
Style: 0x540000C0
ExStyle: 0x00000200
Handle: 0x00230476

>>>> Mouse <<<<
Position: 550, 201
Cursor ID: 0
Color: 0xA6A6A6

Code section, it's a bit messy due to trying to troubleshoot this problem:

$step = 10
pre_step($step)
$sStartID = "Edit15"
$sStartYear = "2012"
$sStartDay = @YDAY - 30 ;;;;;;;;;;;;;; need to calculate for first 30 days of the year !!!!!
;$sStartTime = "13:33:33"
$sStartHour = "13"
$sStartMin = "33"
$sStartSec = "33"
$sStopID = "Edit14"
$sStopYear = "2012"
$sStopDay = @YDAY
$sStopTime = "13:44:44"
$sColon = ":"
$ctrlID = "ListBox3"
$sMnemonic = "ACS10000"
$sAddSelect = "Button15"
wait_win($TelemAnalysis_gui, $step)
$iWinExists = WinExists($TelemAnalysis_gui)
if $iWinExists Then
;Set start and stop times
tim_set_textbox($TelemAnalysis_gui, $sStartID, $sStartYear & "-" & $sStartday & "-" & $sStartHour & ":" & $sStartMin & $sColon & $sStartSec, $step)
tim_set_textbox($TelemAnalysis_gui, $sStopID, $sStopYear & "-" & $sStopday & "-" & $sStopTime, $step)
;ControlSend($TelemAnalysis_gui, "", $sStartID, $sStartDate & "-" & $sStartHour & ":" & $sStartMin & ":" & $sStartSec)
;ControlSend($TelemAnalysis_gui, "", $sStopID, $sStopDate & "-" & $sStopTime)
;click the add select button
listbox_select_item_clicks($TelemAnalysis_gui, $sMnemonic, $ctrlID, 1)
btn_clk($TelemAnalysis_gui, $sAddSelect, $step)
logup($TelemAnalysis_gui & " Completed " & $step)
EndIf

logup("Step " & $step & " complete")
ps($step)


Func tim_set_textbox($win, $ctrlID, $string, $step)
jiggle_button($win, $ctrlID, 2, 30)
wait_ctrl($win, $ctrlID, 5000)
ControlFocus($win, "", $ctrlID)
;ControlSend($win, "", $ctrlID, "^{LEFT}^+{END}{DEL}")
;ControlSend($win, "", $ctrlID, "{HOME}+{END}{DEL}")
;MsgBox(0, "DEBUG", "Sending " & $string)
;ControlSend($win, "", $ctrlID, $string & "+{End}{DEL}")
;ControlSend($win, "", $ctrlID, $string & "+{END}{DEL}")
ControlSend($win, "", $ctrlID, $string)
$txt = ControlGetText($win, "", $ctrlID)
;MsgBox(0, "DEBUG", "Got " & $txt)
if $txt = $string then
logup("Step " & $step & ": text box set to " & $txt)
return 1
Else
;TODO Add $error_tag
logup("Step " & $step & ": text box not set correctly" & $error_tag)
;TODO Add time-out
;MsgBox(0, "Script Error", "Please manually set the text box to " & $string & " then select Enter")
WinActivate($win)
return 0
EndIf

EndFunc
Edited by THeckel
Link to comment
Share on other sites

Try to send the text as "raw". That means: Add a flag to the ControlSend function:

ControlSend($win, "", $ctrlID, $string, 1)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This reproducer seems to work fine.

Run("Notepad.exe")

WinWaitActive("Untitled - Notepad")

Global Const $sColon = ':'

Global Const $send_string = @YEAR & '-' & "Tuesday" & '-' & @HOUR & ':' & @MIN & $sColon & @SEC

ControlSend("Untitled - Notepad", '', "Edit1", $send_string)

What happens if you type the string into the program manually?

Edited by LaCastiglione
Link to comment
Share on other sites

  • Moderators

This issue has been noted before, but for the life of me, I can't remember who made a wrapper solution for it. I thought it was Martin, but can't find it.

Anyway, have you tried ControlSetText() ?

Edit:

Maybe it was Zedna, I really don't know, I know I've seen the issue many times on the forum.

Here's a link to Zedna's solution/suggestion:

Edited by SmOke_N

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.

Link to comment
Share on other sites

It is appropriate for me to mention I had similar problem with controlsend here? The problem seems to be intermittent

This happens when I upload picture files. when sending a filename or directory, like "d:folder1folder2folder3image.jpg".

There are times when

1. ":"(colon) will become ":" (semi-colon)

2. "" become a pipe, "|"

A few thing I also notice.

1. if the time between a pop up dialogue box till my controlsend is too short, there is more likely for this to happen! I use sleep(250) to introduce the delay. Although the problem may still happen sometimes. If i use sleep(150), I will get the error more frequently.

2.I run a few programs at the same time, like firefox, chrome, thunderbird, itune. I suspense the system memory may have cause this problem.

These are intermittent problem. I could not generate this error consistently and therefore I could not submit a bug report.

The only way to work around was to run a loop to re-controlsend if there is an error, in my case.

Edit: I forgot to mention that similar problem happen if I use "send" too.

Edited by sktan7
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...