Jump to content

Looping With $Variale Help


John4
 Share

Recommended Posts

I have a piece of code that I use to set all the checkoxes on the page to on, and another section of code to turn them off. Below is a brief chunk...

Func JobSelectAll()

GUICtrlSetState($Checkbox_2, $GUI_CHECKED)

GUICtrlSetState($Checkbox_3, $GUI_CHECKED)

GUICtrlSetState($Checkbox_4, $GUI_CHECKED)

... and on and on

All my check boxed are sequentially numbered. Is there an easier way to loop from $Checkbox_2 to $Checkbox_45 in a loop or something?

Thanks, John

Edited by John4
Link to comment
Share on other sites

I have a piece of code that I use to set all the checkoxes on the page to on, and another section of code to turn them off. Below is a brief chunk...

Func JobSelectAll()

GUICtrlSetState($Checkbox_2, $GUI_CHECKED)

GUICtrlSetState($Checkbox_3, $GUI_CHECKED)

GUICtrlSetState($Checkbox_4, $GUI_CHECKED)

... and on and on

All my check boxed are sequentially numbered. Is there an easier way to loop from $Checkbox_2 to $Checkbox_45 in a loop or something?

Thanks, John

Use an array

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Sorry, arrays are kind foriegn to me. Maybe a short example? Thanks, John

Does this help?

; array example

Dim $array[11]

For $i = 1 to UBound($array)
    $array[$i] = $i
    MsgBox(0,'Array:', 'Array index ' & $i & ' Value = ' & $array[$i])
Next

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Sorry, arrays are kind foriegn to me. Maybe a short example? Thanks, John

Instead of numbering individual variables, arrays allow you to use 1 variable for several values

Heres a short example that works with 5 checkboxes

#include <GuiConstants.au3>

Global $Checkbox[6] ;declares the the checkboxes variable is an array

$GUI = GUICreate("Checkbox Demo", 150, 250) 
$Checkbox[1]= GUICtrlCreateCheckbox("Box 1", 10, 10)
$Checkbox[2]= GUICtrlCreateCheckbox("Box 2", 10, 40)
$Checkbox[3]= GUICtrlCreateCheckbox("Box 3", 10, 70)
$Checkbox[4]= GUICtrlCreateCheckbox("Box 4", 10, 100)
$Checkbox[5]= GUICtrlCreateCheckbox("Box 5", 10, 130)
$All = GuiCtrlCreateButton("Check All", 10, 160, 130, 30)
$Clear = GuiCtrlCreateButton("Uncheck All", 10, 200, 130, 30)
GUISetState()

While 1
    $Msg= GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE ;people clicked close
            Exit
        Case $All ;pushed select all
            For $i = 1 to 5
                GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
            Next
        Case $Clear ;pushed uncheck all
            For $i = 1 to 5
                GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED)
            Next
    EndSwitch
WEnd
Edited by Paulie
Link to comment
Share on other sites

Instead of numbering individual variables, arrays allow you to use 1 variable for several values

Heres a short example that works with 5 checkboxes

#include <GuiConstants.au3>

Global $Checkbox[6] ;declares the the checkboxes variable is an array

$GUI = GUICreate("Checkbox Demo", 150, 250) 
$Checkbox[1]= GUICtrlCreateCheckbox("Box 1", 10, 10)
$Checkbox[2]= GUICtrlCreateCheckbox("Box 2", 10, 40)
$Checkbox[3]= GUICtrlCreateCheckbox("Box 3", 10, 70)
$Checkbox[4]= GUICtrlCreateCheckbox("Box 4", 10, 100)
$Checkbox[5]= GUICtrlCreateCheckbox("Box 5", 10, 130)
$All = GuiCtrlCreateButton("Check All", 10, 160, 130, 30)
$Clear = GuiCtrlCreateButton("Uncheck All", 10, 200, 130, 30)
GUISetState()

While 1
    $Msg= GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE ;people clicked close
            Exit
        Case $All ;pushed select all
            For $i = 1 to 5
                GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
            Next
        Case $Clear ;pushed uncheck all
            For $i = 1 to 5
                GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED)
            Next
    EndSwitch
WEnd
That worked great! Thanks.

Just curious, why does the Global $Checkbox[6] have to be one greater than the actual number of variables? I have 45 checkboxs and had to set the Global to 46.

Thanks again, John

Link to comment
Share on other sites

That worked great! Thanks.

Just curious, why does the Global $Checkbox[6] have to be one greater than the actual number of variables? I have 45 checkboxs and had to set the Global to 46.

Thanks again, John

because when you declare i with "$checkbox[5]" five is how many "parts" you want it to have, now it starts off counting those parts as 0

so if you used 5, you would have to make your five checkboxes

Box 0, box 1, box 2, box 3, box 4

instead of 1,2,3,4,5

I just like counting starting from 1

Link to comment
Share on other sites

because when you declare i with "$checkbox[5]" five is how many "parts" you want it to have, now it starts off counting those parts as 0

so if you used 5, you would have to make your five checkboxes

Box 0, box 1, box 2, box 3, box 4

instead of 1,2,3,4,5

I just like counting starting from 1

I thought I would add something that I just found - now why this is not the definition of an array in the help file I will never know. I am not trying to say anything about the person that created the help file, but maybe it can be redone to include some better examples - I hope not to start anything, I have said this in the past.

Here is a definition of using arrays - http://www.autoitscript.com/wiki/index.php?title=Arrays

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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