Jump to content

ControlGetText failed to return Calculator output


hSarvesh
 Share

Go to solution Solved by jdelaney,

Recommended Posts

Here are some of the facts which I came across in first hand.. i tried same with other function and it works.

here is little background - Today I needed to complete following task

 #cs ----------------------------------------------------------------------------

 
 Prompt the user for two numbers, checking that each is a valid integer.
 Then start the Windows Calculator in a way that will not break if a workstation does not use the default “Windows” folder name.
 Use calculator to add the client’s two numbers together without using the “send” command.
 When complete, obtain the result from the calculator’s “display”, close calculator, and generate a message box with the result that was read.
 (Hint:  Look at the AU3Info.exe tool provided in Autoit’s program files...)
#ce ----------------------------------------------------------------------------
 
 
Here I was expecting that end of the script, i will be able to read the output of calculator using ControlGetText function. 
 
Global $hWnd

Local $intNUmber1
Local $intNUmber2
Local $o_speech = ObjCreate("SAPI.SpVoice")

$intNUmber1 = InputBox("company", "Please enter number 1 : ")
$intNUmber2 = InputBox("Company", "Please enter number 2 : ")

; validating numbers
;

$validateNumber1 = StringIsInt($intNUmber1)
$validateNumber2 = StringIsInt($intNUmber2)

If $validateNumber1 = True And $validateNumber2 = True Then
    MsgBox(32, "Company", "We are good")
Else
    MsgBox(32, "Com", "We are NOT good")
    MsgBox(32, "Com", "Please try again.. Bye Bye...")
    Exit
EndIf


;MsgBox ( 32, "Com", $test)



; 0 = ClassnameNN: Button6
; 1 = ClassnameNN: Button5
; 2 = ClassnameNN: Button11
; 3 = ClassnameNN: Button16
; 4 = ClassnameNN: Button4
; 5 = ClassnameNN: Button10
; 6 = ClassnameNN: Button15
; 7 = ClassnameNN: Button3
; 8 = ClassnameNN: Button9
; 9 = ClassnameNN: Button14
; C = ClassnameNN: Button13
; + = ClassnameNN: Button23
; - = ClassnameNN: Button22
; * = ClassnameNN: Button21
; = = ClassnameNN: Button28

Func Input_Number($val)

    $cnt = 1
    $length = StringLen($val)
    While ($cnt <= $length)
        ; Identifying char in string to enter on calculator
        $calcinput = StringMid($val, $cnt, 1)
        ; MsgBox (0 , "COM", $calcinput)
        Switch $calcinput
            Case 0
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:6]")
                $cnt = $cnt + 1
            Case 1
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:5]")
                $cnt = $cnt + 1
            Case 2
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:11]")
                $cnt = $cnt + 1
            Case 3
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:16]")
                $cnt = $cnt + 1
            Case 4
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:4]")
                $cnt = $cnt + 1
            Case 5
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:10]")
                $cnt = $cnt + 1
            Case 6
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:15]")
                $cnt = $cnt + 1
            Case 7
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:3]")
                $cnt = $cnt + 1
            Case 8
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:9]")
                $cnt = $cnt + 1
            Case 9
                ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:14]")
                $cnt = $cnt + 1
            Case Else
                MsgBox(32, "Com", "Someone Wrong in Input - I got " & $calcinput)
        EndSwitch
    WEnd
EndFunc   ;==>Input_Number



Run("Calc")
WinWaitActive("Calculator")
$hWnd = WinGetHandle("Calculator")

Input_Number($intNUmber1)
MsgBox(32, "Com", "Number 1 Done")
ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:23]")

Input_Number($intNUmber2)
MsgBox(32, "Com", "Number 2 Done")

ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:28]")

$Content = ControlGetText($hWnd, "", "ID=#327701")

MsgBox(64, "Com", $Content)

WinKill("Calculator")
 
I wrote a simple function to map different buttons on the Calc.exe and till that point everything was working good. when it comes to reading to output from calc.exe - there is no way its reading this correctly. it always returned blank.
 
When i try with something like ControlGetHandle and then perform WinGetText this works well but not with ControlGetText. i tried all possible ways to read the output using ControlGetText but it didn;t worked. 
 
I suspect something is wrong with the function. 
 
I tried to check for updates and even with the newer version as well this didn;t work.
 
can someone confirm this for me?
 
Please note this could have been easy for me to simply send ^C and get the output using clipget(). I am trying to findout if we can complete this without sending ^C.
 
Thank you.
 
Regards,
--
S a r v e s h
Edited by SmOke_N
formatted code to autoit tags
Link to comment
Share on other sites

  • Moderators

I fixed added code tags to your code (see the autoit blue square symbol when you're typing above).

This is a General Help and Support question... Not a Developer Chat section.

Moving...

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

  • Solution

Class #37220 is a sub window embedded in the parent window.

You'll need to grab the proper control relative to that window to get the value.  Use my signature to grab all the controls...you should be using 150 to grab the text.

Run("calc")
$h = WinWait("Calculator")
ControlSend($h,"","","!1")
; 9 * 8 =
ControlClick($h,"",139)
ControlClick($h,"",92)
ControlClick($h,"",138)
ControlClick($h,"",121)
ConsoleWrite(ControlGetText($h,"",150) & @CRLF)

Output:

72

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...