Jump to content
Sign in to follow this  
Hansio

Read the status of a checkbox, if other than 1 or 4

Recommended Posts

Hansio

Is there a way to see if a checkbox is checked if the value in the file is other than 1 or 4?

The value in config.ini will never be something definite. Here is what I have.

$config_ini = (@Scriptdir & "\config.ini")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$L_MB=GUICtrlCreateLabel("Auto Enter",50,53)
$MB=GUICtrlCreateCheckbox("", 30, 52, 17, 17)
GUICtrlSetState(-1, IniRead($config_ini, "section", "MB", 4))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$ja=FileGetShortcut("C:\ProgramData\something\else.lnk")
If @error Then
  MsgBox(0, "Auto Enter Error", "Auto Enter could not be located.")
  Else
  IniWrite($config_ini, "section", "MB", GUICtrlRead($MB))
  IniWrite($config_ini, "section", "MB", "")
  If GUICtrlRead($MB) = 1 Then Iniwrite($config_ini, "section", "MB", $ja[2])
   EndIf

Share this post


Link to post
Share on other sites
somdcomputerguy

I don't follow your post correctly I think, but try GUICtrlGetState and GUICtrlSetState. And probably not GUICtrlRead.

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
Hansio

If I open my gui. Then check box is not checked even though I marked it before.

Here there is no problem if I have marked it, then it is also next time I open my gui.

$L_H=GUICtrlCreateLabel("Some text", 50,152)
$H=GUICtrlCreateCheckbox("", 30, 150, 17, 17)
GUICtrlSetState(-1, IniRead($config_ini, "section", "Test", 4))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IniWrite($config_ini, "section", "Test", GUICtrlRead($H))

Share this post


Link to post
Share on other sites
Maffe811

I can't see anything...

Where is the gui creating happening.. And im not following anything....


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites
somdcomputerguy

And probably not GUICtrlRead.

Well yeah, it can be used. I use it like this: If BitAnd(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
Hansio

Select auto enter, next time it is not checked. I've tried with If BitAnd(GUICtrlRead($Checkbox1), $GUI_CHECKED) Then.

but can not get it to work

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
$config_ini = (@Scriptdir & "\config.ini")
 
GUICreate("TEST", 650, 450)
GUISetFont(10, 400)
GUICtrlCreateGroup("SETTINGS", 15, 15, 620, 420)
GUISetState(@SW_SHOW)
 
$L_MB=GUICtrlCreateLabel("Auto Enter",50,53)
$MB=GUICtrlCreateCheckbox("", 30, 52, 17, 17)   ;;;
GUICtrlSetState(-1, IniRead($config_ini, "section", "MB", 4))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$L_H=GUICtrlCreateLabel("TEXT", 50,152)
$H=GUICtrlCreateCheckbox("", 30, 150, 17, 17)   ;;;
GUICtrlSetState(-1, IniRead($config_ini, "section", "TEST", 4))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$Save = GUICtrlCreateButton("Save", 50, 380, 105, 25, 0)
;;;;;; ;;;;;;
While 1
$msg = GUIGetMsg()
;;;;;;:::::::
If $msg = $Save Then
IniWrite($config_ini, "section", "TEST", GUICtrlRead($H))
$ja=FileGetAttrib("C:\Program Files\Internet Explorer\iexplore.exe")
If @error Then
  MsgBox(0, "Auto Enter Error", "Auto Enter could not be located.")
  Else
  IniWrite($config_ini, "section", "MB", GUICtrlRead($MB))
  IniWrite($config_ini, "section", "MB", "")
  If GUICtrlRead($MB) = 1 Then Iniwrite($config_ini, "section", "MB", $ja)
  EndIf
$file = FileOpen($config_ini)
   FileClose($file)
   Exit
   EndIf
   WEnd

Share this post


Link to post
Share on other sites
Zedna

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("TEST", 650, 450)
GUISetFont(10, 400)
GUICtrlCreateGroup("SETTINGS", 15, 15, 620, 420)
$L_MB = GUICtrlCreateLabel("Auto Enter", 50, 53)
$MB = GUICtrlCreateCheckbox("", 30, 52, 17, 17) ;;;
$Save = GUICtrlCreateButton("Save", 50, 380, 105, 25, 0)
GUISetState(@SW_SHOW)

$config_ini = (@ScriptDir & "\config.ini")
$ini_mb = IniRead($config_ini, "section", "MB", "1") ; 0 or 1
If $ini_mb = "1" Then GUICtrlSetState($MB, $GUI_CHECKED)

While 1
    $msg = GUIGetMsg()
    If $msg = $Save Then
        If IsChecked($MB) Then
            $ini_mb = '1'
        Else
            $ini_mb = '0'
        EndIf
        IniWrite($config_ini, "section", "MB", $ini_mb)
        Exit
    EndIf
WEnd

Func IsChecked($control)
    Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
EndFunc

Share this post


Link to post
Share on other sites
Hansio

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
GUICreate("TEST", 650, 450)
GUISetFont(10, 400)
GUICtrlCreateGroup("SETTINGS", 15, 15, 620, 420)
$L_MB = GUICtrlCreateLabel("Auto Enter", 50, 53)
$MB = GUICtrlCreateCheckbox("", 30, 52, 17, 17) ;;;
$Save = GUICtrlCreateButton("Save", 50, 380, 105, 25, 0)
GUISetState(@SW_SHOW)
 
$config_ini = (@ScriptDir & "\config.ini")
$ini_mb = IniRead($config_ini, "section", "MB", "1") ; 0 or 1
If $ini_mb = "1" Then GUICtrlSetState($MB, $GUI_CHECKED)
 
While 1
    $msg = GUIGetMsg()
    If $msg = $Save Then
        If IsChecked($MB) Then
            $ini_mb = '1'
        Else
            $ini_mb = '0'
        EndIf
        IniWrite($config_ini, "section", "MB", $ini_mb)
        Exit
    EndIf
WEnd
 
Func IsChecked($control)
    Return BitAnd(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
EndFunc

But that is exactly my problem, there will NEVER be written the same to the key name

Share this post


Link to post
Share on other sites
Zedna

But that is exactly my problem, there will NEVER be written the same to the key name

I don't understand.

What's problem? What do you want exactly achieve?

I gave you working solution for your question already.

EDIT: In my example there is writen value 1 or 0 to INI file.

Edited by Zedna

Share this post


Link to post
Share on other sites
Hansio

Zedna > Thank you for your example :-)

I am a fool. But it's not easy when I'm not good at expressing myself in English.

And certainly not when I'm a total newbie in AutoIt.

Here is what I end up with. Is there a better and more simplified way to do it?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUICreate("TEST", 650, 450)
GUISetFont(10, 400)
$M=GUICtrlCreateCheckbox("M", 20, 20, 60, 17)
$MB=GUICtrlCreateCheckbox("MB", 20, 80, 60, 17)
$Save = GUICtrlCreateButton("Save", 50, 380, 105, 25, 0)
GUISetState(@SW_SHOW)
$config_ini = (@ScriptDir & "\config.ini")
$ini_M = IniRead($config_ini, "section", "Auto Enter", "No")
$ini_MB = IniRead($config_ini, "section 2", "Test", "No")
If $ini_M = "Yes" Then GUICtrlSetState($M, $GUI_CHECKED)
If $ini_MB = "Yes"Then GUICtrlSetState($MB, $GUI_CHECKED)

While 1
$msg = GUIGetMsg()
If $msg = $Save Then
  If IsChecked($M) Then
   $ini_M ='Yes'
  Else
   $ini_M ='No'
  EndIf
  IniWrite($config_ini, "section", "Auto Enter", $ini_M)
  If IniRead($config_ini, "section", "Auto Enter", "") = 'Yes' Then
   $ja=FileGetShortcut("C:\ProgramData\something\else.lnk")
  If @error Then
   MsgBox(0, "Auto Enter Error", "Auto Enter (ERROR)")
   IniWrite($config_ini, "section", "Auto Enter", "No")
  Else
   IniWrite($config_ini, "section", "Target", $ja[2])
  EndIf
EndIf
If IsChecked($MB) Then
   $ini_MB ='Yes'
  Else
   $ini_MB ='No'
  EndIf
  IniWrite($config_ini, "section 2", "Test", $ini_MB)
  Exit
EndIf
WEnd
Func IsChecked($control)
Return BitAND(GUICtrlRead($control),$GUI_CHECKED) = $GUI_CHECKED
EndFunc
Edited by Hansio

Share this post


Link to post
Share on other sites
Zedna

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("TEST", 650, 450)
GUISetFont(10, 400)
$M = GUICtrlCreateCheckbox("M", 20, 20, 60, 17)
$MB = GUICtrlCreateCheckbox("MB", 20, 80, 60, 17)
$Save = GUICtrlCreateButton("Save", 50, 380, 105, 25, 0)
GUISetState(@SW_SHOW)

$config_ini = (@ScriptDir & "\config.ini")
$ini_M = IniRead($config_ini, "section", "Auto Enter", "No")
$ini_MB = IniRead($config_ini, "section 2", "Test", "No")
If $ini_M = "Yes" Then GUICtrlSetState($M, $GUI_CHECKED)
If $ini_MB = "Yes" Then GUICtrlSetState($MB, $GUI_CHECKED)

While 1
    $msg = GUIGetMsg()
    If $msg = $Save Then
        CheckBox2INI($M, "section", "Auto Enter")
        If IsChecked($M) Then
            $ja = FileGetShortcut("C:\ProgramData\something\else.lnk")
            If @error Then
                MsgBox(0, "Auto Enter Error", "Auto Enter (ERROR)")
                IniWrite($config_ini, "section", "Auto Enter", "No")
            Else
                IniWrite($config_ini, "section", "Target", $ja[2])
            EndIf
        EndIf
        CheckBox2INI($MB, "section 2", "Test")
        Exit
    EndIf
WEnd

Func CheckBox2INI($control, $section, $name)
    $value = 'No'
    If IsChecked($control) Then $value = 'Yes'
    IniWrite($config_ini, $section, $name, $value)
EndFunc

Func IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

Share this post


Link to post
Share on other sites
Zedna

Added INI2CheckBox()

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("TEST", 650, 450)
GUISetFont(10, 400)
$M = GUICtrlCreateCheckbox("M", 20, 20, 60, 17)
$MB = GUICtrlCreateCheckbox("MB", 20, 80, 60, 17)
$Save = GUICtrlCreateButton("Save", 50, 380, 105, 25, 0)
GUISetState(@SW_SHOW)

$config_ini = (@ScriptDir & "\config.ini")
INI2CheckBox($M, "section", "Auto Enter")
INI2CheckBox($MB, "section 2", "Test")

While 1
    $msg = GUIGetMsg()
    If $msg = $Save Then
        CheckBox2INI($M, "section", "Auto Enter")
        If IsChecked($M) Then
            $ja = FileGetShortcut("C:\ProgramData\something\else.lnk")
            If @error Then
                MsgBox(0, "Auto Enter Error", "Auto Enter (ERROR)")
                IniWrite($config_ini, "section", "Auto Enter", "No")
            Else
                IniWrite($config_ini, "section", "Target", $ja[2])
            EndIf
        EndIf
        CheckBox2INI($MB, "section 2", "Test")
        Exit
    EndIf
WEnd

Func INI2CheckBox($control, $section, $name)
    $value = IniRead($config_ini, $section, $name, "No")
    If $value = "Yes" Then GUICtrlSetState($control, $GUI_CHECKED)
EndFunc

Func CheckBox2INI($control, $section, $name)
    $value = 'No'
    If IsChecked($control) Then $value = 'Yes'
    IniWrite($config_ini, $section, $name, $value)
EndFunc

Func IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.