Jump to content

Checkboxes store in Array, how to call out ?


friends
 Share

Recommended Posts

hi all.

Lately, I try to write a tool for my company uses.

This tool will detect the PCs available in a workgroup (LAN).

The Computer Name of the PCs turned on will be stored in

Array as the daily PCs turn on are different each day.

Therefore, I need to know how to recall the value store in

array ?? Mind to show me an example ? Thanks...

Cos I'm stuck in this part... Big thanks

EDIT : 1) How to create "Select All" Checkboxes by using a button ?

2) How to "Invert Selection" for the checkboxes ?

Edited by friends
Link to comment
Share on other sites

hi all.

Lately, I try to write a tool for my company uses.

This tool will detect the PCs available in a workgroup (LAN).

The Computer Name of the PCs turned on will be stored in

Array as the daily PCs turn on are different each day.

Therefore, I need to know how to recall the value store in

array ?? Mind to show me an example ? Thanks...

Cos I'm stuck in this part... Big thanks

EDIT : 1) How to create "Select All" Checkboxes by using a button ?

          2) How to "Invert Selection" for the checkboxes ?

<{POST_SNAPBACK}>

I don't know about the GUI stuff, but here is an example of getting data out of an array (note the square brackets)

Dim $aToys[4]
$aToys[0] = "Drum"
$aToys[1] = "Doll"
$aToys[2] = "Train"
$aToys[3] = "Bike"

For $i = 0 to UBound($aToys) - 1
   MsgBox(4096, "My Toys", $i & ".  " & $aToys[$i])
Next
Exit

Phillip

Link to comment
Share on other sites

I used philip's example:

#include <GUIConstants.au3>
GUICreate("My Toys", 250, 250)

Dim $aToys[4]
$aToys[0] = GUICtrlCreateLabel("Drum", 5, 10, 70, 20)
$aToys[1] = GUICtrlCreateLabel("Doll", 5, 30, 70, 20)
$aToys[2] = GUICtrlCreateLabel("Train", 5, 50, 70, 20)
$aToys[3] = GUICtrlCreateLabel("Bike", 5, 70, 70, 20)

GUISetState(@SW_SHOW)

While 1
   $msg = GUIGetMsg()

   Select
      Case $msg = $GUI_EVENT_CLOSE
         GUIDelete()
         Exit
      
      Case $msg = $aToys[0]
         MsgBox(64, "My Toys", "0. Drum")

      Case $msg = $aToys[1]
         MsgBox(64, "My Toys", "1. Doll")

      Case $msg = $aToys[2]
         MsgBox(64, "My Toys", "2. Train")

      Case $msg = $aToys[3]
         MsgBox(64, "My Toys", "3. Bike")

   EndSelect
WEnd
Link to comment
Share on other sites

EDIT : 1) How to create "Select All" Checkboxes by using a button ?

          2) How to "Invert Selection" for the checkboxes ?

<{POST_SNAPBACK}>

Maybe this will help:

; Script generated by AutoBuilder 0.5 Prototype

#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("MyGUI", 392, 316,(@DesktopWidth-392)/2, (@DesktopHeight-316)/2)

$Checkbox_1 = GuiCtrlCreateCheckbox("Checkbox1", 20, 30, 90, 20)
$Checkbox_2 = GuiCtrlCreateCheckbox("Checkbox2", 20, 50, 90, 20)
$Checkbox_3 = GuiCtrlCreateCheckbox("Checkbox3", 20, 70, 90, 20)
$Checkbox_4 = GuiCtrlCreateCheckbox("Checkbox4", 20, 90, 90, 20)
$Checkbox_5 = GuiCtrlCreateCheckbox("Checkbox5", 20, 110, 90, 20)
$Checkbox_6 = GuiCtrlCreateCheckbox("Checkbox6", 20, 130, 90, 20)
$Checkbox_7 = GuiCtrlCreateCheckbox("Checkbox7", 20, 150, 90, 20)
$Checkbox_8 = GuiCtrlCreateCheckbox("Checkbox8", 20, 170, 90, 20)
$Checkbox_9 = GuiCtrlCreateCheckbox("Checkbox9", 20, 190, 90, 20)
$Checkbox_10 = GuiCtrlCreateCheckbox("Checkbox10", 20, 210, 90, 20)
$button_1 = GuiCtrlCreateButton("Select All", 20, 275, 90, 20)
$button_2 = GuiCtrlCreateButton("Reset All", 125, 275, 90, 20)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
   Case $msg = $button_1
      GuiCtrlSetState($checkbox_1, $GUI_CHECKED)
      GuiCtrlSetState($checkbox_2, $GUI_CHECKED)
      GuiCtrlSetState($checkbox_3, $GUI_CHECKED)
      GuiCtrlSetState($checkbox_4, $GUI_CHECKED)
      GuiCtrlSetState($checkbox_5, $GUI_CHECKED)
      GuiCtrlSetState($checkbox_6, $GUI_CHECKED)
      GuiCtrlSetState($checkbox_7, $GUI_CHECKED)
      GuiCtrlSetState($checkbox_8, $GUI_CHECKED)
      GuiCtrlSetState($checkbox_9, $GUI_CHECKED)
      GuiCtrlSetState($checkbox_10, $GUI_CHECKED)
      
   Case $msg = $button_2
      GuiCtrlSetState($checkbox_1, $GUI_UNCHECKED)
      GuiCtrlSetState($checkbox_2, $GUI_UNCHECKED)
      GuiCtrlSetState($checkbox_3, $GUI_UNCHECKED)
      GuiCtrlSetState($checkbox_4, $GUI_UNCHECKED)
      GuiCtrlSetState($checkbox_5, $GUI_UNCHECKED)
      GuiCtrlSetState($checkbox_6, $GUI_UNCHECKED)
      GuiCtrlSetState($checkbox_7, $GUI_UNCHECKED)
      GuiCtrlSetState($checkbox_8, $GUI_UNCHECKED)
      GuiCtrlSetState($checkbox_9, $GUI_UNCHECKED)
      GuiCtrlSetState($checkbox_10, $GUI_UNCHECKED)
      
    EndSelect
WEnd
Exit

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

You could use an array. I plan to offer some sort of control array option in AutoBuilder.

#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000
GuiCreate("MyGUI", 392, 316,(@DesktopWidth-392)/2, (@DesktopHeight-316)/2)

Dim $Checkbox[10]
For $i = 0 to 9
   $Checkbox[$i] = GuiCtrlCreateCheckbox("Checkbox" & ($i+1), 20, 30 + 20*$i, 90, 20)
Next

$button_1 = GuiCtrlCreateButton("Select All", 20, 275, 90, 20)
$button_2 = GuiCtrlCreateButton("Reset All", 125, 275, 90, 20)

GuiSetState()
While 1
   $msg = GuiGetMsg()
   
   Select
   Case $msg = $GUI_EVENT_CLOSE
      ExitLoop
      
   Case $msg = $button_1
      For $i = 0 to 9
         GuiCtrlSetState($Checkbox[$i], $GUI_CHECKED)
      Next
   
   Case $msg = $button_2
      For $i = 0 to 9
      GuiCtrlSetState($Checkbox[$i], $GUI_UNCHECKED)
   Next
   
   EndSelect
WEnd
Exit
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

OK... I've tested out CS example, and it works !

Now, how about the "Invert Selection" ? I know it has something to do

with BitNot() right ?

And, also I wanted my "Select All" button becomes "Reset All" when it

is pressed. I know how to change the button name by using GuiCtrlSetState()

function, but I don't know how to assign it to a variable when it became

"Reset All".

Please help me up with this.... Big Thanks

You could use an array.  I plan to offer some sort of control array option in AutoBuilder.

#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000
GuiCreate("MyGUI", 392, 316,(@DesktopWidth-392)/2, (@DesktopHeight-316)/2)

Dim $Checkbox[10]
For $i = 0 to 9
   $Checkbox[$i] = GuiCtrlCreateCheckbox("Checkbox" & ($i+1), 20, 30 + 20*$i, 90, 20)
Next

$button_1 = GuiCtrlCreateButton("Select All", 20, 275, 90, 20)
$button_2 = GuiCtrlCreateButton("Reset All", 125, 275, 90, 20)

GuiSetState()
While 1
   $msg = GuiGetMsg()
   
   Select
   Case $msg = $GUI_EVENT_CLOSE
      ExitLoop
      
   Case $msg = $button_1
      For $i = 0 to 9
         GuiCtrlSetState($Checkbox[$i], $GUI_CHECKED)
      Next
   
   Case $msg = $button_2
      For $i = 0 to 9
      GuiCtrlSetState($Checkbox[$i], $GUI_UNCHECKED)
   Next
   
   EndSelect
WEnd
Exit

<{POST_SNAPBACK}>

Link to comment
Share on other sites

#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000
GUICreate("MyGUI", 392, 316, (@DesktopWidth - 392) / 2, (@DesktopHeight - 316) / 2)

Dim $Checkbox[10]
For $i = 0 To 9
   $Checkbox[$i] = GUICtrlCreateCheckbox("Checkbox" & ($i + 1), 20, 30 + 20 * $i, 90, 20)
Next

$button_1 = GUICtrlCreateButton("Select All", 20, 275, 90, 20)

GUISetState()
While 1
   $msg = GUIGetMsg()
   $results = GUICtrlRead($button_1)
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
         
      Case $msg = $button_1
         Select
            Case $results = "Select All"
               GUICtrlSetData($button_1, "Reset All")
               For $i = 0 To 9
                  GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
               Next
            Case $results = "Reset All"
               GUICtrlSetData($button_1, "Select All")
               For $i = 0 To 9
                  GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED)
               Next
         EndSelect
   EndSelect
WEnd
Exit

Like That?

Edit: By the way ... nice trick using an array to dynamically build the checkboxes CS ... very nice :idiot:

Edited by sykes

We have enough youth. How about a fountain of SMART?

Link to comment
Share on other sites

Reset button example.

#include <GuiConstants.au3>
Dim $WS_OVERLAPPEDWINDOW = 0xCF0000, $WS_VISIBLE = 0x10000000, $WS_CLIPSIBLINGS = 0x04000000
$GUI = GuiCreate("MyGUI", 392, 316,(@DesktopWidth-392)/2, (@DesktopHeight-316)/2)

Dim $Checkbox[10]
For $i = 0 to 9
  $Checkbox[$i] = GuiCtrlCreateCheckbox("Checkbox" & ($i+1), 20, 30 + 20*$i, 90, 20)
Next

$button_1 = GuiCtrlCreateButton("Select All", 20, 275, 90, 20)
$button_2 = GuiCtrlCreateButton("Reset All", 125, 275, 90, 20)
$button_3 = GuiCtrlCreateButton("Invert Selection", 230, 275, 90, 20)

GuiSetState()
While 1
   $msg = GuiGetMsg()
   
   Select
   Case $msg = $GUI_EVENT_CLOSE
      ExitLoop
   
   Case $msg = $button_1
      For $i = 0 to 9
         GuiCtrlSetState($Checkbox[$i], $GUI_CHECKED)
      Next
      
   Case $msg = $button_2
      For $i = 0 to 9
         GuiCtrlSetState($Checkbox[$i], $GUI_UNCHECKED)
      Next

   Case $msg = $button_3
      For $i = 0 to 9
         If ControlCommand($GUI,"",$Checkbox[$i],"IsChecked","") Then
            GuiCtrlSetState($Checkbox[$i], $GUI_UNCHECKED)
         Else
            GuiCtrlSetState($Checkbox[$i], $GUI_CHECKED)
         EndIf
      Next
      
  EndSelect
WEnd
Exit

You might be tempted to do something like the following which uses a Not to invert the state:

; THIS WON'T WORK
$currentState = ControlCommand($GUI,"",$Checkbox[$i],"IsChecked","")
         GuiCtrlSetState($Checkbox[$i], Not $currentState)

The problem is that the values of GUI_CHECKED and GUI_UNCHECKED are 1 and 4 instead of 1 and 0.....

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
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...