Jump to content

Command "AddString" in function ControlCommand get error


dd1978
 Share

Recommended Posts

take a look at following code:

Func Example_01()

    # I copy properties of win form and control by AutoIt window info tool
    Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1;INSTANCE:1]"
    Local $ctl_ppt = "[CLASS:WindowsForms10.LISTBOX.app.0.141b42a_r9_ad1;NAME:ListBox1;INSTANCE:1]"

    WinActivate($win_ppt, "")

    Local $ret = ControlCommand($win_ppt, "", $ctl_ppt, "AddString", 'line ii')

    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "Error")
    EndIf

EndFunc   #==>Example_01

The result of running the code is: get error and no new line is added to ListBox

Anyone can help, thanks.

Link to comment
Share on other sites

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

4 hours ago, dd1978 said:

Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1;INSTANCE:1]"

that doesn't seem right

in info Tools in the Windows tab it does not have Advanced mode as have the control tab

[TITLE:My Window; CLASS:My Class; INSTANCE:2]

... and the  # I copy properties of win form and control by AutoIt window info tool

 is better  with  ; I copy properties of win form and control by AutoIt window info tool

 

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

I have tested following code:

Func Example_01()

    Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1;INSTANCE:1]"
    Local $hWnd = WinGetHandle($win_ppt)

    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle.")
        Exit
    EndIf

    MsgBox($MB_SYSTEMMODAL, "", $hWnd)

EndFunc   ;==>Example_01

The MsgBox prints the value: 0x000306A2

and without error

I feel that this is a handle, right?

Link to comment
Share on other sites

I have tested the code for control:

Func Example_02()

    Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1;INSTANCE:1]"
    Local $ctl_ppt = "[CLASS:WindowsForms10.LISTBOX.app.0.141b42a_r9_ad1;NAME:ListBox1;INSTANCE:1]"

    Local $hControl = ControlGetHandle($win_ppt, "", $ctl_ppt)

    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the control handle.")
        Exit
    EndIf

    MsgBox($MB_SYSTEMMODAL, "", "The handle is: " & $hControl)

EndFunc   ;==>Example_02

has run without error

MsgBox prints the value of $hControl like a handle: 0x000E0610

any suggestions, thanks

Link to comment
Share on other sites

The UI to be tested against is a .net winform. I compile the UI application under VS2019 VB.Net

I have tested button click, button enable and disable, combo box show dropdown and hide dropdown. These tasks all work properly.

Now I stoped at using AddString command of ControlCommand function to add new line into ListBox.

Is there any configuration required for ListBox to get new line from my AutoIt script?

Link to comment
Share on other sites

Link to comment
Share on other sites

@Nine Thank you for the explanation

@dd1978  I honestly don't know. I just try to help

from help book  see Title special definition

e.g. Set the text of the .NET Winforms "textBoxFolder" control to "C:\Some\Folder"

ControlSetText("My Window", "", "[NAME:textBoxFolder]", "C:\Some\Folder")

   

I know that I know nothing

Link to comment
Share on other sites

@Nine@ioa747I'm back, with problem testing result

I have install the latest stable version of AutoIt, then run the following code:

Func Example_03()

    Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1]"
    Local $ctl_ppt = "[NAME:ListBox1]"
    Local $hWnd = WinActivate($win_ppt, "")
    Local $Test = ControlCommand($hWnd,  "",  $ctl_ppt , "GetCount", "")

    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "Error")
        Exit
    EndIf

    MsgBox($MB_SYSTEMMODAL, "", $Test)

EndFunc

The last MsgBox print: -1

no error occurs

My ListBox1 has three items before I run the code.

In this forum, I found somebody advise to use beta version and is it an answer?

Thanks.

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...