Jump to content

Problem Changing a Combo Box


fett8802
 Share

Recommended Posts

Hi all!

I'm doing some regression automation for the company I work for and I'm caught at a relatively easy juncture. I'm not sure why I can't figure this out, but it's been giving me heck all afternoon. I'll post the code I have and then explain.

#Include <GuiComboBox.au3>

$Return = _LinkReg_ComboBoxSelect("Window Title", "TDBNumericListControl1", 6)
ConsoleWrite("Return: " & $Return & @CR & "@error: " & @error & @CR)

Func _LinkReg_ComboBoxSelect($WindowTitle, $ControlID, $Selection = -1)
    WinActivate($WindowTitle)                                                       
    If WinWaitActive($WindowTitle,"",2) = 0 Then Return SetError(1, 0, -1)
    $Handle = ControlGetHandle($WindowTitle,"",$ControlID)
    ConsoleWrite("Handle: " & $Handle & @CR)
    If _GUICtrlComboBox_SetCurSel($Handle,$Selection) = -1 Then Return SetError(2, 0, -1)


    Return 1

EndFunc   ;==>_LinkReg_ComboBoxSelect

Basically, I'm just trying to code a function to reliably select certain values in a combo box. It has to error handle well as this will be running over nights. Now, if you open any window with a combo box and feed that boxes ControlID in, you'll see that it always errors on the _GUICtrlComboBox_SetCurSel line and I can't figure out why. The help file isn't helping any and I'm sure it's just some small overlook in code and that I will feel incredibly stupid once someone points it out. But, that's where I'm stuck. Feel free to ask any questions.

Thanks everybody!

Edited by fett8802
[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

You didn't say how it failed, but your test is invalid. The returned value from _GUICtrlComboBox_SetCurSel() is the index of the new selection, not True or False. So check it more like this:

If _GUICtrlComboBox_SetCurSel($Handle,$Selection) <> $Selection Then Return SetError(2, 0, -1)

:x

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Stupid me. I must have misread the help file on some other function and thought the True/False was for pass/fail. I've changed it to reflect the help file. The new line is

If _GUICtrlComboBox_SetCurSel($Handle,$Selection) = -1 Then Return SetError(2, 0, -1)

So, it's basically checking to see if the cursor set failed.

Where I'm having problems is that the combo box doesn't change. Does this function apply only to combo boxes created in AutoIt? If so, is there a function somewhere that applies to non-AutoIt controls? I can control any other controls in this program with the various other control manipulators, but I can't seem to get this to work.

By the way, with that new line, it does not error out. It shows that it completed and returns a 0 for the selection, but it did not actually change the combo box.

Thanks for your help!

[sub]My UDF[/sub][sub] - Basics and Time extensions. Great for those new at AutoIt, also contains some powerful time extensions for pros.[/sub][sub]ScrabbleIt[/sub][sub] - Scrabble done in pure AutoIt. (In Progress)[/sub][sub]Nerd Party Extreme | My Portfolio | [email="fett8802@gmail.com"]Contact Me[/email][/sub]
Link to comment
Share on other sites

The UDF functions that start with _GuiCtrl<Class>_* mostly use the standard Windows APIs via DLL calls. They work on controls using those standard APIs. It is possible "TDBNumericListControl1" is not a standard Windows API control.

Do the other ComboBox UDF functions, like _GUICtrlComboBox_GetCount() and _GUICtrlComboBoxEx_GetItemText() work correctly on this control?

:x

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...