Jump to content

Control Command Newbie Question


Ibike2
 Share

Recommended Posts

Newbie's First post. I have reviewed the forums but unfortunately have not found a solution.

I am writing a script to automate some repetitive tasks in a hydraulic modeling program called HEC-RAS. What I would like to happen is for the script to prompt the user to select a river and reach (each which has its own combobox). After the user makes their selection and presses ok to leave the screen, I would like the script to remember the selections to be called later during future iterations. I have done this successfully in another window in a listbox, but am not having success with the combobox. I would like the text of the combobox that is displayed to be stored to $River and $Reach for the appropriate control ID. Occasionally this will run and store the correct information in the correct variable and display it in the message box, but occasionally the $Reach value is 0 instead of the Reach name selected.

It seems impractical to include the entire code and HEC-RAS, so the portion of code that seems to have errors is as follows (I understand you will not be able to replicate my problem though).

Is there a more appropriate way to store this information upon close of the window than to keep storing the current selection until the window that opens following the user pressing ok (Steady Flow Analysis) appears?

Thanks so much.

MsgBox(0, "User input required", "Please select River and Reach to Optimize and press OK to continue with script")
WinWaitActive("Encroachments")

While 1
    If WinActive("Steady Flow Analysis") Then
        ExitLoop
    EndIf
    $River= ControlCommand("Encroachments", "", "[ID:12]", "GetCurrentSelection", "")
    $Reach= ControlCommand("Encroachments", "", "[ID:11]", "GetCurrentSelection", "")
    sleep(10)
WEnd

MsgBox(0, "River and Reach", $River & "," & $Reach)
Link to comment
Share on other sites

  • Moderators

Ibike2,

Welcome to the AutoIt forum. :D

One thing that immediately strikes me is the use of [iD:##] to identify the control in your ControlCommand lines.

Some apps give controls different IDs each time they are created - are you sure that the relevant combo is always [iD:11]? Is there anything else that the AU3 Window Info tool gives you which could help identify that combo?

Sorry I cannot be of more help, but the fact that the error is only occasional makes me suspicious of the ID method as I have run into this problem myself in the past. :huggles:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks for the response Melba23.

I noticed that the handle changes each time the "Encroachments" window is opened as I had tried to use the handle to identify the comboboxes, so I switched to ID, but so far every time I've had it opened the ID's remained 11 and 12 for these two comboboxes. Would the classnamenn be more stable (called ThunderRT6ComboBox4 and ThunderRT6ComboBox5) or would it be possible for these to be dynamic as well?

Thanks

Link to comment
Share on other sites

I changed the code slightly and no longer get the occasional '0' return. I'm not sure why this worked, someone more experiences may wish to lend some insight.

I changed $River and $Reach to Global instead of Dim when initializing.

I added the line WinActivate("Encroachments")

Thanks for such a great forum.

While 1     WinActivate("Encroachments")    If WinActive("Steady Flow Analysis") Then       ExitLoop    EndIf   $River= ControlCommand("Encroachments", "", "[ID:12]", "GetCurrentSelection", "")   $Reach= ControlCommand("Encroachments", "", "[ID:11]", "GetCurrentSelection", "")   sleep(10) WEnd
Link to comment
Share on other sites

  • Moderators

Ibike2,

You should always use Global/Local rather than Dim. AutoIt tries to give you the scope it thinks you need but it is best to be specific.

As to WinActivate - it is probably that that did the trick.

Sounds like an interesting application! Delighted that it works now. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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