Jump to content

Loop through controls in a window


atc
 Share

Recommended Posts

In an application, I have a window created using GUICreate, eg.

$CMWindow = GUICreate($CMW_Title,$CMW_Width,$CMW_Height)

This window has a considerable number of input fields created using GUICtrlCreateEdit, eg.

$CM_Funct_Edit = GUICtrlCreateEdit ("", $CM_Col2_Left, $CMWR_Top, $CM_Col2_Width, $CMW_Row_Height)

$CM_ID_Edit = GUICtrlCreateEdit ("", $CM_Col2_Left, $CMWR_Top, $CM_Col2_Width, $CMW_Row_Height)

.... Etc.

In a few routines, I want to be able to loop through all of these controls, be able to (a) read the data, (B) reset all or selected controls, and/or © identify each control when running through the loop.

Is there a way I can loop through all controls in the window, identify each control and its type much as you can using Visual Basic Controls Collections?

Obviously I could hard code the relevant controls in each routine. However, this can be tedious and is a problem for future program maintenance.

Any help would be appreciated.

Thanks

Link to comment
Share on other sites

I use an array to store the control handles in that case.

Check the program in my signature, it uses the same principle.

Something(?) like:

Local $control[11]

For $i = 1 To 10
      $control[$i] = GUICtrlCreateEdit("", 10, 10, 100, 20)
      GUICtrlSetData($control[$i], $i)  ; Sets the controle number as data into the control
Next

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

I use an array to store the control handles in that case.

Check the program in my signature, it uses the same principle.

Something(?) like:

Local $control[11]

For $i = 1 To 10
      $control[$i] = GUICtrlCreateEdit("", 10, 10, 100, 20)
      GUICtrlSetData($control[$i], $i) ; Sets the controle number as data into the control
Next
Thanks,

That is one solution which I had considered and may well have to use.

However, because I need to access specific conbtrols in some places and at other times, all controls - it was felt that I would need to assign two variables (one with a user friendly name & the other in an array element) as I would not trust the array element numbers to remain fixed with future modifications and enhancements.

Link to comment
Share on other sites

Thanks,

That is one solution which I had considered and may well have to use.

However, because I need to access specific conbtrols in some places and at other times, all controls - it was felt that I would need to assign two variables (one with a user friendly name & the other in an array element) as I would not trust the array element numbers to remain fixed with future modifications and enhancements.

Then you could use a ScriptingDictionary object to store them.

Or, you can do both, save them all to an array, and also assign specific variable for some that you need particular access to.

:)

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