kcvinu

How to loop through all textboxes in a form

23 posts in this topic

Hi all,

I have a form with 15 textboxes. I need to set all of them disabled when i press a button. So i decided to use a loop. But how can i do it. Any idea ?


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites



Thank you @Jos. So simple answer. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

Use an array for the control handles so you can use a For..Next loop,

Jos

how can we use array ....

can u give one small example?

i am new to autoit

i want to select checkbox using IE function 

how can i use array there ??

 

Share this post


Link to post
Share on other sites

There is a big difference between the question raised here, using your own gui with controls and using the IE functions.
Why did you think they are related so I understand what you mean?

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

hey,

Already i have one webpage i want select checkbox ,

i just want to know how can i do it ??

which functions can be used 

Share this post


Link to post
Share on other sites

Again, this thread is related to an AutoIt3 GUI, not a webpage.
Create your own thread with the question in the appropriate forum.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You can do something like this.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 595, 375, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 144, 24, 289, 21)
$Label1 = GUICtrlCreateLabel("Label1", 160, 64, 36, 17)
$Input2 = GUICtrlCreateInput("Input2", 152, 88, 281, 21)
$Button1 = GUICtrlCreateButton("Button1", 208, 136, 129, 17)
$Input3 = GUICtrlCreateInput("Input3", 32, 24, 89, 21)
$Input4 = GUICtrlCreateInput("Input4", 400, 168, 129, 21)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 72, 136, 97, 33)
$Button2 = GUICtrlCreateButton("Button2", 488, 72, 65, 33)
$Input5 = GUICtrlCreateInput("Input5", 176, 184, 193, 21)
$Input6 = GUICtrlCreateInput("Input6", 416, 240, 129, 21)
$Input7 = GUICtrlCreateInput("Input7", 40, 208, 217, 21)
$Input8 = GUICtrlCreateInput("Input8", 96, 256, 193, 21)
$Button3 = GUICtrlCreateButton("Disable Just Inputs", 200, 304, 209, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button3
        For $i=$Input1 to  $Button3
            if _WinAPI_GetClassName(GUICtrlGetHandle($i))="Edit" Then
                GUICtrlSetState($i,$GUI_DISABLE)
            EndIf
        Next

    EndSwitch
WEnd

Saludos

Share this post


Link to post
Share on other sites

@Danyfirex , I am confuced. You are looping through what ? just through control IDs ?. Please clarify the for loop.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

Yes I'm looping through all controls ID and check if is a Edit box. starting from first control ID (the first before the GUI)  till last one. this case $button3.

 

Saludos

 

 

1 person likes this

Share this post


Link to post
Share on other sites

Thanks. That is new knowledge for me to loop through declared control IDs. Then AutoIt considering control IDs as a list or range. Isn't it ?


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

Look inside SciTEConfig for the code that set's up the the "Edit Colors" window. I use a For..Next loop to create the 3 columns of CheckBoxes and also a For..Next loop to see which are checked/

Jos

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

kcvinu,

AutoIt ControlIDs are actually the index numbers of the internal array that AutoIt uses to track the native created controls. They are usually in numerical order, but to save space, the first empty index is used - this means that deleting controls will allow the same ControlID to be reused, as you can see here:

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("Test", 500, 500)

For $i = 0 To 9
    $cCID = GUICtrlCreateLabel("", 10, 10 + (20 * $i), 200, 20)
    GUICtrlSetData($cCID, $cCID)
Next

$cReuse = GUICtrlCreateButton("Delete/Recreate", 10, 450, 100, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cReuse

            GUICtrlDelete(5)
            $cCID = GUICtrlCreateLabel("", 10, 10 + (20 * $i), 200, 20)
            GUICtrlSetData($cCID, $cCID)
    EndSwitch

WEnd

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

@Melba23 Interesting !. So if you delete a control, it's ID will be allotted to a new control. But why did this example only shows labels with number 3 ?. I expect it should start from zero.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

@Jos , Did you meant these lines ?

For $x = 1 To 17
    $H_Syn_Label[$x] = GUICtrlCreateLabel($Syn_Label[$x], $BaseX + 5, $BaseY + 20 * $x, 150, 20)
    $H_Syn_Bold[$x] = GUICtrlCreateCheckbox("", $BaseX + 170, $BaseY + 20 * $x, 20, 20)
    $H_Syn_Italic[$x] = GUICtrlCreateCheckbox("", $BaseX + 195, $BaseY + 20 * $x, 20, 20)
    $H_Syn_Underline[$x] = GUICtrlCreateCheckbox("", $BaseX + 220, $BaseY + 20 * $x, 20, 20)
    $H_Syn_fColor[$x] = GUICtrlCreateButton("Fore", $BaseX + 245, $BaseY + 20 * $x, 40, 20)
    $H_Syn_bColor_Standard[$x] = GUICtrlCreateCheckbox("", $BaseX + 295, $BaseY + 20 * $x, 20, 20)
    $H_Syn_bColor[$x] = GUICtrlCreateButton("Back", $BaseX + 320, $BaseY + 20 * $x, 40, 20)
Next

And these are the lines in which you checked for the control state

; Check if one of the checkboxes is clicked
    For $x = 1 To 17
        If $Msg = $H_Syn_bColor_Standard[$x] Then
            $Syn_bColor_Default[$x] = GUICtrlRead($H_Syn_bColor_Standard[$x])
            If GUICtrlRead($H_Syn_bColor_Standard[$x]) = $GUI_CHECKED Then
                GUICtrlSetState($H_Syn_bColor[$x], $GUI_DISABLE)
                $Syn_bColor[$x] = $Background_Color
                GUICtrlSetBkColor($H_Syn_Label[$x], $Syn_bColor[$x])
            Else
                GUICtrlSetState($H_Syn_bColor[$x], $GUI_ENABLE)
            EndIf
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_Bold[$x] Then
            $Syn_Bold[$x] = Not $Syn_Bold[$x]
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_Italic[$x] Then
            $Syn_Italic[$x] = Not $Syn_Italic[$x]
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_Underline[$x] Then
            $Syn_Underline[$x] = Not $Syn_Underline[$x]
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_fColor[$x] Then
            $tempcolor = SelectColor($Syn_fColor[$x])
            $Syn_fColor[$x] = $tempcolor
            GUICtrlSetColor($H_Syn_Label[$x], $Syn_fColor[$x])
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_bColor[$x] Then
            $tempcolor = SelectColor($Syn_bColor[$x])
            $Syn_bColor[$x] = $tempcolor
            GUICtrlSetBkColor($H_Syn_Label[$x], $Syn_bColor[$x])
            $NeedsSave = 1
        EndIf
        If $Msg = $H_Syn_Bold[$x] Or $Msg = $H_Syn_Italic[$x] Or $Msg = $H_Syn_Underline[$x] _
                Or $Msg = $H_Syn_fColor[$x] Or $Msg = $H_Syn_bColor[$x] Then
            GUICtrlSetFont($H_Syn_Label[$x], $SYN_Font_Size, 400 + $Syn_Bold[$x] * 200, $Syn_Italic[$x] * 2 + $Syn_Underline[$x] * 4, $SYN_Font_Type)
            $NeedsSave = 1
        EndIf
    Next

 

Edited by kcvinu

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

kcvinu,

why did this example only shows labels with number 3 ?.

The first ControlID returned has always been 3 since I started using AutoIt - you will have to ask Jon why, but I imagine that the earlier elements are used for other things that AutoIt needs to track.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

@Melba23 Oh. I deleted label number 2 for a test. But nothing happened and label number 14 created. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

kcvinu,

As I explained above, the control ControlIDs start from 3, so using a lower value in a ControlID parameter will not affect any existing control. Thus in this case nothing is deleted and the next created control will follow on from the earlier sequence.

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Melba23,

But the earlier sequence was ended at 12. So, new control should be created as 13. But it indicates 14. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

kcvinu,

The first ControlID returned has always been 3 since I started using AutoIt - you will have to ask Jon why, but I imagine that the earlier elements are used for other things that AutoIt needs to track.

M23

always is 3 because autoit create two hidden controls internally. maybe internally use a counter for HMENU parameter of CreateWindowEx.

 

Saludos

 


 

1 person likes this

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

  • Similar Content

    • jannikrendl
      By jannikrendl
      Hey guys,
      I was trying to create a script with a GUI but when I start the script via pressing the startbutton in my GUI and then trying to stop the script it won't close/stop.
      Here is the script:
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Global $GUI = GUICreate("AlphaAgility", 218, 65, 1147, 123) Global $StartButton = GUICtrlCreateButton("Start", 24, 16, 75, 25) Global $StopButton = GUICtrlCreateButton("Stop", 120, 16, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $StartButton while(1) Agility() WEnd Case $StopButton Exit EndSwitch WEnd Global $agility = False Func Agility() MouseClick("Left",random(466,500),random(634,669),1,random(10,20));Balancier-Stamm If Not(@error) Then $agility = True sleep(random(0,200)) MouseMove(random(408,661),random(632,749),random(10,20));random Mousemovement Balancier-Stamm Else EndIf sleep(5500) MouseClick("Left",448,820,1,random(10,20));Netz If Not(@error) Then $agility = True sleep(random(0,200)) MouseMove(random(334,557),random(774,876),random(10,20));random Mousemovement Netz Else $agility = False EndIf sleep(3750) MouseClick("Left",480,706,1,random(10,20));Ast If Not(@error) Then $agility = True ;sleep(random(0,200)) ;MouseMove(random(95,953),random(117,1067),random(10,20)) -> kein random Mousemovement nötig Else $agility = False EndIf sleep(2750) MouseClick("Left",727,608,1,random(10,20));Balancier-Seil If Not(@error) Then $agility = True sleep(random(0,200)) MouseMove(random(723,891),random(572,676),random(10,20));random Mousemovement Balancier-Seil Else $agility = False EndIf sleep(6750) MouseClick("Left",698,633,1,random(10,20));Ast If Not(@error) Then $agility = True ;sleep(random(0,200)) ;MouseMove(random(95,953),random(117,1067),random(10,20)) -> kein random Mousemovement nötig Else $agility = False EndIf sleep(4000) MouseClick("Left",random(372,459),random(136,202),1,random(10,20));Netz If Not(@error) Then $agility = True sleep(random(0,200)) MouseMove(random(388,510),random(140,212),random(10,20));random Mousemovement Netz Else $agility = False EndIf sleep(6250) MouseClick("Left",random(362,401),random(363,409),1,random(10,20));Röhre If Not(@error) Then $agility = True ;sleep(random(0,200)) ;MouseMove(random(95,953),random(117,1067),random(10,20)) -> kein random Mousemovement nötig Else $agility = False EndIf sleep(7000) MouseClick("Left",14,654,1,random(10,20));Startposition If Not(@error) Then $agility = True ;sleep(random(0,200)) ;MouseMove(random(388,510),random(140,212),random(10,20)) -> kein random Mousemovement nötig Else EndIf sleep(4000) EndFunc Thanks in advance
      Jannik Rendl
    • nlta1992
      By nlta1992
      I want creat GUI, have button 1 to 10, but only use loop for ... to ... step ... next.
      Thanks.
    • ur
      By ur
      We are trying to automate the installation testing before sending to end users, our product.
      For Silent Installation, we have completed this part.
      But for GUI, the default installation is completed by sending the keys based on the window.
      But for GUI custom installation, we are struck.
      How to enable or disable features in the below screen using GUI automation.?

    • Trolleule
      By Trolleule
      Hi all,
      i was currently working with html when i got myself the question if there is a windows control that acts like a html container e.g. a div with the hidden attribute. The benfeit is obvious. You can put code in this container and at the moment it is hidden it doesnt take room but when i got visible it uses the room it needs. Is there something i can use with windows forms?
      Normally one have to recalculate the position of all controls and adjust them manually.
    • drapdv
      By drapdv
      I have a GUI with a parent window that has a menu and shortcut buttons at the top, and a child window which displays a list which is scrolled vertically.
      When the list is relatively small, like no more than 100 or so lines then it scrolls fine.  As the list gets larger, scrolling begins to slow, and if you start mixing up the scroll method (mousewheel, left-clicking the scrollbar box, etc) then it begins to hang.  When it hangs, dwm.exe CPU usage maxes out, and I can't even switch to another window.  Each line in the list is 1000px wide X 30px tall, and the lines alternate between a gray background and a white background, in case that matters.
      When a non-Aero theme is active, everything works fine.  So, I could disable DWM every time someone fires it up, but changing a client's color scheme is not ideal.
      I tried to utilize _WinAPI_DwmSetWindowAttribute($oGui_Parent,  $DWMWA_NCRENDERING_POLICY, $DWMNCRP_DISABLED), and although it succeeds in disabling DWM for that window, it doesn't seem to make any difference as far as the scrolling lag is concerned.
      The code is several thousand lines long and contains proprietary information, so I'm trying to avoid posting that, but these are the lines which are creating the GUIs.  Is there anything that anyone can think of off the top of their heads, or is there anything jumping out at you from this snippet of code?  Any help is appreciated!
      $oGui_Parent = GUICreate("Data Viewer", 700, 500, Default, Default, BitOR($WS_CAPTION, $WS_MINIMIZEBOX, $WS_POPUPWINDOW)) WinSetTrans($oGui_Parent, "", 255) _WinAPI_DwmSetWindowAttribute($oGui_Parent, $DWMWA_NCRENDERING_POLICY, $DWMNCRP_DISABLED) GUISetFont(9, 500, 0, "Calibri") GUISetBkColor(0xFFFFFF) $oGui_Child = GUICreate("", 700, 400, 0, 100, $WS_POPUP, $WS_EX_MDICHILD, $oGui_Parent) WinSetTrans($oGui_Child, "", 255) _WinAPI_DwmSetWindowAttribute($oGui_Child, $DWMWA_NCRENDERING_POLICY, $DWMNCRP_DISABLED) GUISetFont(9, 500, 0, "Calibri") GUISetBkColor(0xFFFFFF)