Jump to content
Sign in to follow this  
EndFunc

Error handling with Checkboxes

Recommended Posts

EndFunc

Hello,

I have a script/Gui that has checkboxes that are populated via an INIfile. So the values from the ini file creates the checkboxes upon startup.

What I want to do is be able to say if an certain checkbox is check it, it will not allow another one to be checked.

For example

Checkbox 1

Checkbox 2

Checkbox 3

Checkbox 4

Checkbox 5

If check box 2 is checked it will not allow checkbox 5. I can't figure that out for the life of me because of the fact that the checkboxes are dynamically created and the numeric value doesn't seem constant.

In my For loop I tried doing condition statments but I either break the loop or it doesn't work. Here is part of my code at the for loop when I run it.

Local $sProgs, $aProgs
For $i = 1 To $InstallPrograms[0][0]    
If GUICtrlRead($ProgCtrl[$i]) = $GUI_CHECKED Then
$Progs = GUICtrlRead($LabelCtrl[$i])
$sProgs &= $Progs & "," 
GUICtrlSetState($ProgCtrl[$i], $GUI_UNCHECKED)
EndIf
Next

Thanks


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
GodlessSinner

This may help you:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $Checkbox = 0
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 532, 208, 260, 356)

$Cb1 = GUICtrlCreateCheckbox("Checkbox1", 40, 24, 273, 33)
$set1 = IniRead(@ScriptDir & "\settings.ini", "set1","key","0")
$Checkbox = $Cb1
_Check($Checkbox)
$Cb2 = GUICtrlCreateCheckbox("Checkbox2", 40, 56, 289, 25)
$set1 = IniRead(@ScriptDir & "\settings.ini", "set2","key","0")
$Checkbox = $Cb2
_Check($Checkbox)
$Cb3 = GUICtrlCreateCheckbox("Checkbox3", 40, 88, 297, 25)
$set1 = IniRead(@ScriptDir & "\settings.ini", "set3","key","0")
$Checkbox = $Cb3
_Check($Checkbox)
$Cb4 = GUICtrlCreateCheckbox("Checkbox4", 40, 120, 297, 25)
$set1 = IniRead(@ScriptDir & "\settings.ini", "set4","key","0")
$Checkbox = $Cb4
_Check($Checkbox)
$Cb5 = GUICtrlCreateCheckbox("Checkbox5", 40, 152, 297, 33)
$set1 = IniRead(@ScriptDir & "\settings.ini", "set5","key","0")
$Checkbox = $Cb5
_Check($Checkbox)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Cb1
            $set = "set1"
            $Cb= $Cb1
            _CheckNow($Cb, $set)
        Case $Cb2
            $set = "set2"
            $Cb= $Cb2
            _CheckNow($Cb, $set)    
        Case $Cb3
            $set = "set3"
            $Cb= $Cb3
            _CheckNow($Cb, $set)    
        Case $Cb4
            $set = "set4"
            $Cb= $Cb4
            _CheckNow($Cb, $set)    
        Case $Cb5
            $set = "set5"
            $Cb= $Cb5
            _CheckNow($Cb, $set)    
        
    EndSwitch
WEnd

Func _Check($Checkbox)
    If $set1 = 1 Then 
    GUICtrlSetState($Checkbox, $GUI_CHECKED)
Else
    GUICtrlSetState($Checkbox, $GUI_UNCHECKED)
EndIf
    EndFunc
Func _CheckNow($Cb, $set)
        If GUICtrlRead($Cb)=1 Then
            IniWrite(@ScriptDir & "\settings.ini", $set,"key","1")
        Else
            IniWrite(@ScriptDir & "\settings.ini", $set,"key","0")
        EndIf
EndFunc

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
EndFunc

Thanks, you gave me something to work with. I didnt think about making a seperate function to check them.


EndFuncAutoIt is the shiznit. I love it.

Share this post


Link to post
Share on other sites
llewxam

I had a similar question recently and was turned on to GUICtrlCreateGroup which made my life easier than writing a function. I think you have to use radios instead of checkboxes, but oh well, small price.....

Ian


My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

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
Sign in to follow this  

×