Jump to content

GUI and Switch


Recommended Posts

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)

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)

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

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

        Case $GUI_EVENT_CLOSE

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

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

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

        Case $nMsg = $Button2

Ini.ini file


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
Link to comment
Share on other sites

in helpfile:


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.

Link to comment
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.


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: - 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!"

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...