Jump to content

Selecting Value In Combo Box


lmg
 Share

Recommended Posts

I am a newbie trying to select a value in a combo box in an established application. My code is as follows.

ControlClick( "Export event", "","TComboBox1" , "main",1)

$ret=ControlCommand ( "Export event", "", "TComboBox1", "FindString", 'Competitors' )

ControlCommand ( "Export event", "", "TComboBox1", "SetCurrentSelection", $ret )

However, no matter what I put in as my string I get a $ret value of 1 and I do not change the combo box value. Am I even close to being on the right track? What more do I need to do? I wasn't sure if my string should have single or double quotes but tried both - same result. Btw, I am using the control name rather than control ID as the controlID seems to change every time I bring up the application.

Link to comment
Share on other sites

  • Moderators

I am a newbie trying to select a value in a combo box in an established application. My code is as follows.

ControlClick( "Export event", "","TComboBox1" , "main",1)

$ret=ControlCommand ( "Export event", "", "TComboBox1", "FindString", 'Competitors' )

ControlCommand ( "Export event", "", "TComboBox1", "SetCurrentSelection", $ret )

However, no matter what I put in as my string I get a $ret value of 1 and I do not change the combo box value. Am I even close to being on the right track? What more do I need to do? I wasn't sure if my string should have single or double quotes but tried both - same result. Btw, I am using the control name rather than control ID as the controlID seems to change every time I bring up the application.

It' returning how many times it sees the 'occurence' of the 'string' your looking for. So in that combo box it has 'Competitors' 1 time.

On your 'SetCurrentSelecition' are you trying to select 'Competitors'?

You could do:

If ControlCommand('Export event', '', 'TComboBox1', 'FindString', 'Competitors') <> 0 Then
    ControlCommand('Export event', '', 'TComboBox1', 'SetCurrentSelection', 'Competitors')
EndIf

Or if you 100% sure that that is in there, you could just do:

ControlCommand('Export event', '', 'TComboBox1', 'SetCurrentSelection', 'Competitors')
More than likely.

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' returning how many times it sees the 'occurence' of the 'string' your looking for. So in that combo box it has 'Competitors' 1 time.

On your 'SetCurrentSelecition' are you trying to select 'Competitors'?

You could do:

If ControlCommand('Export event', '', 'TComboBox1', 'FindString', 'Competitors') <> 0 Then
    ControlCommand('Export event', '', 'TComboBox1', 'SetCurrentSelection', 'Competitors')
EndIf

Or if you 100% sure that that is in there, you could just do:

ControlCommand('Export event', '', 'TComboBox1', 'SetCurrentSelection', 'Competitors')
More than likely.
Thanks. That was what I tried initially but it didn't work. Have tried again with

If ControlCommand('Export event', '', 'TComboBox1', 'FindString', 'Competitors') <> 0 Then

ControlCommand('Export event', '', 'TComboBox1', 'SetCurrentSelection', 'Competitors')

else

MsgBox (0,"got to export event data", "no competitors")

EndIf

MsgBox (0,"got to export event data", "out of IF")

It seems to find 'Competitors' as I don't get the first msgbox, only the 2nd but the combobox is not changed. I should be seeing 'Competitors' selected in the box shouldn't I?

Link to comment
Share on other sites

  • Moderators

Here Try This:

If ControlCommand('Export event', '', 'TComboBox1', 'FindString', 'Competitors') <> 0 Then
    ControlCommand('Export event', '', 'TComboBox1', 'SelectString', 'Competitors')
EndIf

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

Thanks. That was what I tried initially but it didn't work. Have tried again with

If ControlCommand('Export event', '', 'TComboBox1', 'FindString', 'Competitors') <> 0 Then

ControlCommand('Export event', '', 'TComboBox1', 'SetCurrentSelection', 'Competitors')

else

MsgBox (0,"got to export event data", "no competitors")

EndIf

MsgBox (0,"got to export event data", "out of IF")

It seems to find 'Competitors' as I don't get the first msgbox, only the 2nd but the combobox is not changed. I should be seeing 'Competitors' selected in the box shouldn't I?

However, I have now found another item that has given me another approach. If anyone else is having this problem see:

http://www.autoitscript.com/forum/index.ph...urrentSelection. This works well for me.

Link to comment
Share on other sites

  • Moderators

Did you try the suggestion fo SelectString rather than SetCurrentSelection? I mean it's great you found an alternative, but it might have worked all the same.

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

Here Try This:

If ControlCommand('Export event', '', 'TComboBox1', 'FindString', 'Competitors') <> 0 Then
    ControlCommand('Export event', '', 'TComboBox1', 'SelectString', 'Competitors')
EndIf
Yes, that works as well - and is rather cleaner - Thanks
Link to comment
Share on other sites

  • 13 years later...

Hello autoitscripters,

I'm trying to do the same thing but the problems occur that all those solution mention above is not working. The command is success but I haven't notice any change to that combobox. FindString Return 1 but still nothing work.

The DllCall method doesn't work either.

So I have to try to make it work by 'dirty way' is

First I send a click through controlclick to that combobox.

ControlClick($Title, $Text, $ComboboxID)
Sleep(100)

Secondly, I send command '{DOWN}' and '{TAB}' to simulate to choose the option. If I don't click to this but setfocus to this combobox, those below command doesn't work:

ControlSend($Title, $Text, $ComboboxID, "{DOWN " $timeToPress & "}")
Sleep(200)
ControlSend($Title, $Text, $ComboboxID, "{TAB}")

This worked but problems may arise when the control change /update/delete the options in combobox.

So my question is there anyway to know can we get the order of the known combobox?

Any suggestion is appreciate!

Edited by Cheatmo
Link to comment
Share on other sites

Resurrecting a 13 years old thread is not the best idea as AutoIt has immensely changed over that period.  I would suggest next time to create a new thread.  But since we are here, what is the application you are trying to automate ? Have you tried the _GUICtrlComboBox_FindString ?  Read help file about it.  If you still have a problem, create a new thread and post the code you are struggling with, not just a few lines of code.  If possible make it so we can run it ourselves...

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