Sign in to follow this  
Followers 0
msalperen

Checkbox in OnEvent Mode

5 posts in this topic

Hi,

I'm trying to update an edit box due to the value returned by a checkbox. I'm using On event mode

Func btnOpenForm6_click()
      $SwiftKodu = GUICtrlRead($Combo401) 
      $Header= StringFormat("some variable here", $SwiftKodu)
      $sonuc = StringFormat("%s", $Header) & $Deneme
      $sonuc2 = StringFormat(" Basic Header ")
     
        if BitAnd(GUICtrlRead($Checkbox1), $GUI_CHECKED) == $GUI_CHECKED Then
            GUICtrlSetData($Edit1, $sonuc)
        Else
            GUICtrlSetData($Edit1, $sonuc2)
        Endif

EndFunc

As far as what I've read from the forum, this should do the trick but it always turns $sonuc2 whether the checkbox is ticked or not. I have tried to include it in a while wend loop but no success. I appreciate any help on my issue.

Kindly

Share this post


Link to post
Share on other sites



It's something about how you handle your strings, because this works fine:

#include <GuiConstantsEx.au3>

Opt("GuiOnEventMode", 1)

Global $hGUI, $Edit1, $Checkbox1

$hGUI = GUICreate("Test", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

$Edit1 = GUICtrlCreateEdit("", 20, 20, 260, 20)

$Checkbox1 = GUICtrlCreateCheckbox("Test Me!", 20, 60, 260, 20)
GUICtrlSetOnEvent(-1, "btnOpenForm6_click")

GUISetState()

While 1
    Sleep(10)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func btnOpenForm6_click()
    Local $sonuc = "Checked!"
    Local $sonuc1 = "Unchecked!"
    If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) == $GUI_CHECKED Then
        GUICtrlSetData($Edit1, $sonuc)
    Else
        GUICtrlSetData($Edit1, $sonuc1)
    EndIf
EndFunc   ;==>btnOpenForm6_click


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

It's something about how you handle your strings, because this works fine:

#include <GuiConstantsEx.au3>

Opt("GuiOnEventMode", 1)

Global $hGUI, $Edit1, $Checkbox1

$hGUI = GUICreate("Test", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

$Edit1 = GUICtrlCreateEdit("", 20, 20, 260, 20)

$Checkbox1 = GUICtrlCreateCheckbox("Test Me!", 20, 60, 260, 20)
GUICtrlSetOnEvent(-1, "btnOpenForm6_click")

GUISetState()

While 1
    Sleep(10)
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Func btnOpenForm6_click()
    Local $sonuc = "Checked!"
    Local $sonuc1 = "Unchecked!"
    If BitAND(GUICtrlRead($Checkbox1), $GUI_CHECKED) == $GUI_CHECKED Then
        GUICtrlSetData($Edit1, $sonuc)
    Else
        GUICtrlSetData($Edit1, $sonuc1)
    EndIf
EndFunc   ;==>btnOpenForm6_click

There's something certainly I'm missing but I can not find it. Your example turns "Unchecked!" in both condition within my code. And also the following one which uses combobox control works well!

$Combo401 = GUICtrlCreateCombo("ASTRFKM", 392, 80, 137, 25)
GUICtrlSetData(-1, "BKCHCNBJ|ABNATRIS|ISBKTRIS|")


... Gui details here ...

Func btnOpenForm6_click()
      $DummyVariable = GUICtrlRead($Combo401) 
        $Header= StringFormat("  some text %s ", $DummyVariable)
        $Deneme = StringFormat(" some text here also")
      $sonuc = StringFormat("%s", $Header) & $Deneme
        GUICtrlSetData($Edit1, $sonuc)
EndFunc

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

you must be doing something wrong with the strings. Simply take PsaltyDS's code and replace it with yours

and seriously, there is no need to use StringFormat, it will complicate your code

Edited by trung0407

Share this post


Link to post
Share on other sites

There's something certainly I'm missing but I can not find it. Your example turns "Unchecked!" in both condition within my code.

You have yet to provide a short, runnable, reproducer script that shows your symptoms.

When you run my unmodified demo, does it work? I'll bet it does.

Now you post a short, complete, runnable script that demonstrates your issue.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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  
Followers 0