Jump to content

Yet another checkbox issue


Saitoh183
 Share

Recommended Posts

I have been trying to figure out why i cannot seem to get the proper value for my checkbox. Here is a snippet of my code:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form_opt = GUICreate("Form_opt", 615, 438, 1044, 160)
$Tab1 = GUICtrlCreateTab(32, 8, 553, 385)
$Label1 = GUICtrlCreateLabel("", 0, 376, 612, 4, $SS_SUNKEN)
$OK = GUICtrlCreateButton("OK", 104, 392, 81, 25)
$Cancel = GUICtrlCreateButton("Cancel", 408, 392, 81, 25)
$Saveset = GUICtrlCreateButton("Save", 256, 392, 81, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;TheRenamer TAB ######################################
$TRtab = GUICtrlCreateTabItem("TheRenamer")
GUICtrlSetState(-1,$GUI_SHOW)
GUICtrlSetTip(-1, "Set TheRenamer Path")
$x86 = GUICtrlCreateCheckbox("Windows 32bit", 40, 64, 89, 17)
$x64 = GUICtrlCreateCheckbox("Windows 64bit", 40, 96, 89, 17)
$custom = GUICtrlCreateCheckbox("Custom path",  40, 168, 81, 17)
$custompath = GUICtrlCreateInput("", 41, 192, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
$win = GUICtrlRead($x86) or GUICtrlRead($x64)
$win64cus = GUICtrlRead($custom)or GUICtrlRead($x64)
$win86cus = GUICtrlRead($custom)or GUICtrlRead($x86)
;###################################################
Global $iniTRpathinfo
While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
 
  Case $custom
   If $win = $GUI_CHECKED Then
    GUICtrlSetState($x86, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($x64, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($custom, $GUI_disable)
    GUICtrlSetState($custompath, $Gui_enable)
   EndIf
  Case $x86
   If $win64cus = $GUI_CHECKED Then
    GUICtrlSetState($custom, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($x64, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($custompath, $Gui_disable)
    GUICtrlSetState($x86, $GUI_disable)
   EndIf
  Case $x64
   If $win86cus = $GUI_CHECKED Then
    GUICtrlSetState($custom, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($x86, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($custompath, $Gui_disable)
    GUICtrlSetState($x64, $GUI_disable)
   EndIf
  Case $Anime
   If GUICtrlRead($anime) = $gui_checked Then
    GUICtrlSetState($ani_fetch, $Gui_enable)
    GUICtrlSetState($ani_Arch, $Gui_enable)
   ElseIf GUICtrlRead($anime) = $gui_unchecked Then
    GUICtrlSetState($ani_fetch, $Gui_disable)
    GUICtrlSetState($ani_Arch, $Gui_disable)
   endif
  Case $extra
   If GUICtrlRead($extra) = $gui_checked Then
    GUICtrlSetState($ext_fetch, $Gui_enable)
    GUICtrlSetState($ext_Arch, $Gui_enable)
   ElseIf GUICtrlRead($extra) = $gui_unchecked Then
    GUICtrlSetState($ext_fetch, $Gui_disable)
    GUICtrlSetState($ext_Arch, $Gui_disable)
   endif
  Case $ok
  Case $cancel
  Case $saveset
   If BitAND(GUICtrlGetState($x86),$gui_checked) = $gui_checked Then
    ConsoleWrite(GUICtrlGetState($x86) & BitAND(GUICtrlGetState($x86),$gui_checked) = $gui_checked)
    $iniTRpathinfo = '"C:\Program Files\theRenamer\theRenamer.exe"'
   ElseIf GUICtrlRead($x64) = 1 Then
    $iniTRpathinfo = '"C:\Program Files (x86)\theRenamer\theRenamer.exe"'
   Else
    $iniTRpathinfo = GUICtrlRead($custompath)
   EndIf
IniWrite("msettings.ini", "therenamer", "Path", $iniTRpathinfo)
   EndSwitch
WEnd

The problem is this part :

Case $saveset
   If BitAND(GUICtrlGetState($x86),$gui_checked) = $gui_checked Then
    ConsoleWrite(GUICtrlGetState($x86) & BitAND(GUICtrlGetState($x86),$gui_checked) = $gui_checked)
    $iniTRpathinfo = '"C:\Program Files\theRenamer\theRenamer.exe"'
   ElseIf GUICtrlRead($x64) = 1 Then
    $iniTRpathinfo = '"C:\Program Files (x86)\theRenamer\theRenamer.exe"'
   Else
    $iniTRpathinfo = GUICtrlRead($custompath)
   EndIf

For some reason,

ElseIf GUICtrlRead($x64) = 1 Then
 
    $iniTRpathinfo = '"C:\Program Files (x86)\theRenamer\theRenamer.exe"'
   Else
Works but
If BitAND(GUICtrlGetState($x86),$gui_checked) = $gui_checked Then
 
    ConsoleWrite(GUICtrlGetState($x86) & BitAND(GUICtrlGetState($x86),$gui_checked) = $gui_checked)

This always returns 4 even if the box is checked

What could be the problem. BTW im new to this :graduated:

Link to comment
Share on other sites

Use If GUICtrlRead($x86) = $GUI_CHECKED then instead of using getstate and see how it works for your script.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

If you look in the helpfile at GUICtrlRead() it tell you this:

For Checkbox, Radio control several states can be returned as $GUI_FOCUS and $GUI_CHECKED,. So use i.e. BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the control is checked.

So you should use BitAnd() to make sure the return from GUICtrlRead() is checked correctly...

Link to comment
Share on other sites

im having yet another issue with my script. its still checkbox related but im trying to use a Array within my Switch Case.

Here is my test script

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form_opt = GUICreate("Form_opt", 615, 438, 1044, 160)
$Tab1 = GUICtrlCreateTab(32, 8, 553, 385)
$Label1 = GUICtrlCreateLabel("", 0, 376, 612, 4, $SS_SUNKEN)
$OK = GUICtrlCreateButton("OK", 104, 392, 81, 25)
$Cancel = GUICtrlCreateButton("Cancel", 408, 392, 81, 25)
$Saveset = GUICtrlCreateButton("Save", 256, 392, 81, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###  
;TheRenamer TAB ######################################
$TRtab = GUICtrlCreateTabItem("TheRenamer")
GUICtrlSetState(-1,$GUI_SHOW)
GUICtrlSetTip(-1, "Set TheRenamer Path")
Global $x86 = GUICtrlCreateCheckbox("Windows 32bit", 40, 64, 89, 17)
$x64 = GUICtrlCreateCheckbox("Windows 64bit", 40, 96, 89, 17)
$custom = GUICtrlCreateCheckbox("Custom path",  40, 168, 81, 17)
$custompath = GUICtrlCreateInput("", 41, 192, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
;CheckboxChecked########################################
$win = GUICtrlRead($x86) or GUICtrlRead($x64)
$win64cus = GUICtrlRead($custom)or GUICtrlRead($x64)
$win86cus = GUICtrlRead($custom)or GUICtrlRead($x86)
;####################################################
;Fetching Extra TAB#########################################
$Fetext = GUICtrlCreateTabItem("Fetching / Extras")
GUICtrlSetTip(-1, "")
$Anime = GUICtrlCreateCheckbox("  Anime", 36, 49, 81, 17)
$Ani_fetch_lab = GUICtrlCreateLabel("Anime Fetch Folder :", 36, 73, 101, 17)
$Ani_fetch = GUICtrlCreateInput("", 36, 91, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
$Ani_arch_lab = GUICtrlCreateLabel("Anime Archive Folder :", 36, 121, 110, 17)
$Ani_arch = GUICtrlCreateInput("", 36, 145, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
$Extra = GUICtrlCreateCheckbox("  Extra", 36, 177, 81, 17)
$ext_fetch_lab = GUICtrlCreateLabel("Extra Fetch Folder :", 36, 201, 96, 17)
$ext_fetch = GUICtrlCreateInput("", 36, 225, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
$ext_arch_lab = GUICtrlCreateLabel("Extra  Archive Folder :", 36, 249, 108, 17)
$ext_arch = GUICtrlCreateInput("", 36, 273, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
$TV_fet = GUICtrlCreateCheckbox("TV Fetcher", 36, 305, 81, 17)
GUICtrlSetTip(-1, "If TV Settings are activated in TheRename, check this box")
$Mov_fet = GUICtrlCreateCheckbox("Movie Fetcher", 36, 337, 89, 17)
GUICtrlSetTip(-1, "If Movie Settings are activated in TheRename, check this box")
;LOG TAB#########################################
$Logtab = GUICtrlCreateTabItem("Log Settings")
$TVlog_lab = GUICtrlCreateCheckbox("TV Log name", 36, 49, 79, 17)
$TVlogname = GUICtrlCreateInput("", 36, 73, 113, 21)
GUICtrlSetState(-1, $Gui_disable)
GUICtrlSetLimit(-1, 12)
GUICtrlSetTip(-1, 'Max 12 letters (no extension".log")')
$TVlogpath_lab = GUICtrlCreateLabel("TV Log Path :", 188, 49, 70, 17)
$TVlogpath = GUICtrlCreateInput("", 188, 73, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
$Movlogname = GUICtrlCreateInput("", 36, 145, 113, 21)
GUICtrlSetState(-1, $Gui_disable)
GUICtrlSetLimit(-1, 12)
GUICtrlSetTip(-1, 'Max 12 letters (no extension".log")')
$Movlogpath = GUICtrlCreateInput("", 188, 145, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
$Movlogpath_lab = GUICtrlCreateLabel("Movie Log Path :", 188, 121, 85, 17)
$Movlog_lab = GUICtrlCreateCheckbox("Movie Log name", 36, 121, 95, 17)
$Anilogname = GUICtrlCreateInput("", 36, 217, 113, 21)
GUICtrlSetState(-1, $Gui_disable)
GUICtrlSetLimit(-1, 12)
GUICtrlSetTip(-1, 'Max 12 letters (no extension".log")')
$Anilogpath = GUICtrlCreateInput("", 188, 217, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
$Anilogpath_lab = GUICtrlCreateLabel("Anime Log Path :", 188, 193, 85, 17)
$Anilog_lab = GUICtrlCreateCheckbox("Anime Log name", 36, 193, 95, 17)
$extlogname = GUICtrlCreateInput("", 36, 289, 113, 21)
GUICtrlSetState(-1, $Gui_disable)
GUICtrlSetLimit(-1, 12)
GUICtrlSetTip(-1, 'Max 12 letters (no extension".log")')
$extlogpath = GUICtrlCreateInput("", 188, 289, 393, 21)
GUICtrlSetState(-1, $Gui_disable)
$extlogpath_lab = GUICtrlCreateLabel("Extra Log Path :", 188, 265, 80, 17)
$extlogname_lab = GUICtrlCreateCheckbox("Extra Log name", 36, 265, 95, 17)
Global $iniTRpathinfo, $inianime1, $inianime2, $s_inianime, $iniextra1, $iniextra2, $s_iniextra
Global $test[4][3]=[["$TVlog_lab", "$TVlogname", "$TVlogpath"],["$Movlog_lab", "$Movlogname", "$Movlogpath"], _
["$Anilog_lab", "$Anilogname", "$Anilogpath"], ["$extlog_lab", "$extlogname", "$extlogpath" ]]
_ArrayDisplay($test,"")
While 1
    $msg = GuiGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
 
  Case $custom
   If $win = $GUI_CHECKED Then
    GUICtrlSetState($x86, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($x64, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($custom, $GUI_disable)
    GUICtrlSetState($custompath, $Gui_enable)
   EndIf
  Case $x86
   If $win64cus = $GUI_CHECKED Then
    GUICtrlSetState($custom, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($x64, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($custompath, $Gui_disable)
    GUICtrlSetState($x86, $GUI_disable)
   EndIf
  Case $x64
   If $win86cus = $GUI_CHECKED Then
    GUICtrlSetState($custom, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($x86, $GUI_UNCHECKED + $gui_enable)
    GUICtrlSetState($custompath, $Gui_disable)
    GUICtrlSetState($x64, $GUI_disable)
   EndIf
  Case $Anime
   If GUICtrlRead($anime) = $gui_checked Then
    GUICtrlSetState($ani_fetch, $Gui_enable)
    GUICtrlSetState($ani_Arch, $Gui_enable)
   ElseIf GUICtrlRead($anime) = $gui_unchecked Then
    GUICtrlSetState($ani_fetch, $Gui_disable)
    GUICtrlSetState($ani_Arch, $Gui_disable)
   endif
  Case $extra
   If GUICtrlRead($extra) = $gui_checked Then
    GUICtrlSetState($ext_fetch, $Gui_enable)
    GUICtrlSetState($ext_Arch, $Gui_enable)
   ElseIf GUICtrlRead($extra) = $gui_unchecked Then
    GUICtrlSetState($ext_fetch, $Gui_disable)
    GUICtrlSetState($ext_Arch, $Gui_disable)
   endif
  Case $test[0][0] to $test[3-1][0]
   For $y = 0 To 3 - 1
   if $msg = $test[$y][0] then
   If GUICtrlRead($test[$y][0]) = $gui_checked Then
    ConsoleWrite($test[$y][0] & @crlf & $test[$y][1] & @crlf & $test[$y][2]) ; <===== to check if its ouputing anything
    GUICtrlSetState($test[$y][1], $Gui_enable)
    GUICtrlSetState($test[$y][2], $Gui_enable)
   ElseIf GUICtrlRead($test[$y][0]) = $gui_unchecked Then
    GUICtrlSetState($test[$y][1], $Gui_disable)
    GUICtrlSetState($test[$y][2], $Gui_disable)
   EndIf
   endif
   Next
  EndSwitch
WEnd

And here is the part of script that is repetitive that i want to transform into a Array within my Switch Case (i have other repetitive scriplets but if i figure out 1 the rest will follow)

Case $TVlog_lab
   If GUICtrlRead($TVlog_lab) = $gui_checked Then
    GUICtrlSetState($TVlogname, $Gui_enable)
    GUICtrlSetState($TVlogpath, $Gui_enable)
   ElseIf GUICtrlRead($TVlog_lab) = $gui_unchecked Then
    GUICtrlSetState($TVlogname, $Gui_disable)
    GUICtrlSetState($TVlogpath, $Gui_disable)
   endif
  Case $Movlog_lab
   If GUICtrlRead($Movlog_lab) = $gui_checked Then
    GUICtrlSetState($Movlogname, $Gui_enable)
    GUICtrlSetState($Movlogpath, $Gui_enable)
   ElseIf GUICtrlRead($Movlog_lab) = $gui_unchecked Then
    GUICtrlSetState($Movlogname, $Gui_disable)
    GUICtrlSetState($Movlogpath, $Gui_disable)
   endif
  Case $Anilog_lab
   If GUICtrlRead($Anilog_lab) = $gui_checked Then
    GUICtrlSetState($Anilogname, $Gui_enable)
    GUICtrlSetState($Anilogpath, $Gui_enable)
   ElseIf GUICtrlRead($Anilog_lab) = $gui_unchecked Then
    GUICtrlSetState($Anilogname, $Gui_disable)
    GUICtrlSetState($Anilogpath, $Gui_disable)
   endif
  Case $TVlog_lab
   If GUICtrlRead($TVlog_lab) = $gui_checked Then
    GUICtrlSetState($TVlogname, $Gui_enable)
    GUICtrlSetState($TVlogpath, $Gui_enable)
   ElseIf GUICtrlRead($TVlog_lab) = $gui_unchecked Then
    GUICtrlSetState($TVlogname, $Gui_disable)
    GUICtrlSetState($TVlogpath, $Gui_disable)
   endif

The part im trying to create

Case $test[0][0] to $test[3-1][0]
   For $y = 0 To 3 - 1
   if $msg = $test[$y][0] then
   If GUICtrlRead($test[$y][0]) = $gui_checked Then
    ConsoleWrite($test[$y][0] & @crlf & $test[$y][1] & @crlf & $test[$y][2]) ; <===== to check if its ouputing anything
    GUICtrlSetState($test[$y][1], $Gui_enable)
    GUICtrlSetState($test[$y][2], $Gui_enable)
   ElseIf GUICtrlRead($test[$y][0]) = $gui_unchecked Then
    GUICtrlSetState($test[$y][1], $Gui_disable)
    GUICtrlSetState($test[$y][2], $Gui_disable)
   EndIf
   endif

I based myself of this post

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