Sign in to follow this  
Followers 0
lmg

Selecting Value In Combo Box

7 posts in this topic

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.

Share this post


Link to post
Share on other sites



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.

[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' 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?

Share this post


Link to post
Share on other sites

Here Try This:

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


[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

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.

Share this post


Link to post
Share on other sites

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.


[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

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

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