Sign in to follow this  
Followers 0
lesmly

GUI and Switch

8 posts in this topic

#1 ·  Posted (edited)

Hi - first - sorry for my english :)

I wrote this script

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiButton.au3>
$iw = 3
$sd = IniReadSection ("ini.ini", "sd")

Global $wr[4]

$wr[1] = "a1"
$wr[2] = "a2"
$wr[3] = "a3"


#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("USTAWIENIA", 612, 476, 346, 119)
$Group1 = GUICtrlCreateGroup("1", 16, 16, 185, 105)
$Combo1 = GUICtrlCreateCombo("a1", 32, 56, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
;GUICtrlSetData(-1, "a2|a3")

For $i = 1 To $iw
 If $sd[1][1] = $i Then
   GUICtrlSetData($Combo1, "a2|a3", $wr[$i])
;  GUICtrlSetState ($Combo[$i], $GUI_checked)
 EndIf
Next

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Group2 = GUICtrlCreateGroup("2", 208, 16, 185, 105)
$Combo2 = GUICtrlCreateCombo("a1", 224, 56, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlCreateGroup("", -99, -99, 1, 1)

For $i = 1 To $iw
 If $sd[2][1] = $i Then
   GUICtrlSetData($Combo2, "a2|a3", $wr[$i])
;  GUICtrlSetState ($Combo[$i], $GUI_checked)
 EndIf
Next


GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button1 = GUICtrlCreateButton("Accept", 120, 408, 75, 25)
$Button2 = GUICtrlCreateButton("Exit", 200, 408, 75, 25)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit

        Case $nMsg = $Button1
                For $j=1 To 3
                    If StringCompare (GUICtrlRead ($Combo1), $wr[$j]) = 0 Then
                        ;ConsoleWrite (GUICtrlRead ($Combo1))
                        $wstawnumer1 = $j

                    EndIf
                Next
                IniWrite ( "ini.ini", "sd", "sd1", $wstawnumer1)

                For $j=1 To 3
                    If StringCompare (GUICtrlRead ($Combo2), $wr[$j]) = 0 Then
                        ;ConsoleWrite (GUICtrlRead ($Combo2))
                        $wstawnumer2 = $j
                    EndIf
                Next
                IniWrite ( "ini.ini", "sd", "sd2", $wstawnumer2)

        Case $nMsg = $Button2
            Exit
    EndSwitch
WEnd

Ini.ini file

[sd]
sd1=3
sd2=2

and I've got a problems...

1st when I press the "Accept" should write to file all values regardless of whether something has changed

2nd when I press the "Exit" should not save anything (I mean after press "Accept") and close the window

But if I press Exit or "X" - Close Window - all changes are written to ini

When I test and add lines: ConsoleWrite (GUICtrlRead ($Combo1)) ;ConsoleWrite (GUICtrlRead ($Combo2))all the time in console new data arrived... but I don't press "Accept" button !!! Why?

Edited by lesmly

Share this post


Link to post
Share on other sites



Look more carefully in helpfile for Select...Case...EndSelect and Switch...Case...EndSwitch.

Share this post


Link to post
Share on other sites

in helpfile:

"Remarks

If no cases match the Switch value, then the Case Else section, if present, is executed. If no cases match and Case Else is not defined, then none of the code inside the Switch structure, other than the condition, will be executed."

but in my script case $nMsg = $Button1 is executed before I press this button.

Share this post


Link to post
Share on other sites

Compare these two following lines

Case $GUI_EVENT_CLOSE
Case $nMsg = $Button1

Share this post


Link to post
Share on other sites

Compare these two following lines

Case $GUI_EVENT_CLOSE
Case $nMsg = $Button1

one is right the other wrong

Share this post


Link to post
Share on other sites

And this is - what I need. Thank you.

Compare these two following lines

Case $GUI_EVENT_CLOSE
Case $nMsg = $Button1

Share this post


Link to post
Share on other sites

No, what you need is to remove the $nMsg = from that case statement.

It should just be

Case $Button1

You only use the Case $nMsg = Button1 in a Select statement not in a Switch.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thank you too, today is my second day of coding.

Earlier I guessed what I did wrong - now I know how to fix it :)

Edited by lesmly

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