Jump to content

Getting Combobox value after Manual change


Grasoft
 Share

Recommended Posts

Greetings everyone,

I'm writing a software that edit an ini file section by section with adding/renaming abilities

but whenever I manually change the combobox to value other than constducted previously, I cannot get this value.

THIS is a clean version of the code:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiEdit.au3>
#include <MsgBoxConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Program Files (x86)\AutoIt3\SciTE\Koda\Forms\QuickRepEditList7.kxf
$SecMgr = GUICreate("Sections Manager", 1159, 690)
GUISetFont(12, 800, 0, "MS Sans Serif")
$EditSec = GUICtrlCreateEdit("", 45, 45, 1090, 644, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $ES_NOHIDESEL))
$Edit2 = GUICtrlCreateEdit("", 11, 45, 33, 617, BitOR($ES_RIGHT, $ES_READONLY, $ES_WANTRETURN))
GUICtrlSetData(-1, StringFormat(" 1:\r\n 2:\r\n 3:\r\n 4:\r\n 5:\r\n 6:\r\n 7:\r\n 8:\r\n 9:\r\n10:\r\n11:\r\n12:\r\n13:\r\n14:\r\n15:\r\n16:\r\n17:\r\n18:\r\n19:\r\n20:\r\n21:\r\n22:\r\n23:\r\n24:\r\n25:\r\n26:\r\n27:\r\n28:\r\n29:\r\n30:"))
$Label1 = GUICtrlCreateLabel("Select Section:", 7, 13, 126, 24)
GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")
$Savesec = GUICtrlCreateButton("Save Changes", 375, 7, 129, 33)
$NewSec = GUICtrlCreateButton("New Section", 700, 7, 121, 33)
$SecDwn = GUICtrlCreateButton("Section Down", 830, 7, 137, 33)
$SecUp = GUICtrlCreateButton("Section Up", 980, 7, 129, 33)
$copystrs = GUICtrlCreateButton("*******", 507, 7, 73, 33)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$HeavySep = GUICtrlCreateButton("====", 581, 7, 73, 33)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
Global $SecSel
Global $secno
Global $secn = "NULLz"
Global $sFilePathtemp
Global $aArray
Global $SecNames
Global $secnnew
Global $ssecn
$SecSel = GUICtrlCreateCombo("", 110, 10, 257, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
queysecs()
Filledit()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$secno=GUICtrlRead($SecSel)
$changed=0
While 1
    $secn = GUICtrlRead($SecSel)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            saveeditedmsg()
            Exit
        Case $SecSel
            $secno=GUICtrlRead($SecSel)
            queysecs()
            Filledit()
        Case $Savesec
            saveeditedmsg()
            queysecs()
        Case $NewSec
        Case $SecDwn
        Case $SecUp
        Case $copystrs
            ClipPut("**************************************************************************************************************************************************************")
        Case $HeavySep
            ClipPut("==============================================================================================================================================================")

    EndSwitch
WEnd

Func queysecs();query section names
    $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini"
    $aArray = IniReadSectionNames($sFilePath)
    $SecNames = $aArray[1]
    If $secn = "NULLz" Then
        $secn = $aArray[1]
    EndIf
    If Not @error Then
        For $i = 2 To $aArray[0]
            $SecNames = $SecNames & "|" & $aArray[$i]
        Next
        GUICtrlSetData($SecSel, "", "")
        GUICtrlSetData($SecSel, $SecNames, $secn)
        $secno = $secn
    EndIf
EndFunc   ;==>queysecs

Func Filledit(); transfer section values on the edit box
    GUICtrlSetData($EditSec, "")
    $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini"
    For $i = 1 To 30
        $sRead = IniRead($sFilePath, $secn, $i, "")
        GUICtrlSetData($EditSec, $sRead & @CRLF, 1)
    Next
    GUISetState(@SW_SHOW)
EndFunc   ;==>Filledit

Func saveeditedmsg(); save or rename modified section
    If $secn <> $secno Then
        $iMsgBoxAnswer = MsgBox(3, "NEW/RENAME", "Press YES to Add this as NEW section" & @CRLF & "Press NO to rename and save this section from " & $secno & "To" & $secn)
        Select
            Case $iMsgBoxAnswer = 6 ;YES
                $secn = $secno
                save($secn)
                $secn = GUICtrlRead($SecSel)
                $secno = $secn
            Case 7 ;NO
                $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini"
                IniRenameSection($sFilePath, $secno, $secn)
                save($secn)
                $secn = GUICtrlRead($SecSel)
                $secno = $secn
        EndSelect
    Else
        $iMsgBoxAnswer = MsgBox(4, "Do you want to save changes to this section", "Save Section: " & $secn)
        Select
            Case $iMsgBoxAnswer = 6 ;yes
                save($secn)
        EndSelect
    EndIf
EndFunc   ;==>saveeditedmsg

;MsgBox(4, "Do you want to add this to Database?",$secn)
Func save($ssecn); save edit control to a file and then rewrite modified values by line order.
    $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8)
    $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini"
    FileWrite($sFilePathtemp, GUICtrlRead($EditSec))
    $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_UTF8)
    For $i = 1 To 30
        $sRead = FileReadLine($sFilePathtemp, $i)
        IniWrite($sFilePath, $ssecn, $i, $sRead)
    Next
    GUISetState(@SW_SHOW)
EndFunc   ;==>save

And this is with som test msg boxes to know how to get it

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <GuiEdit.au3>
#include <MsgBoxConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Program Files (x86)\AutoIt3\SciTE\Koda\Forms\QuickRepEditList7.kxf
$SecMgr = GUICreate("Sections Manager", 1159, 690)
GUISetFont(12, 800, 0, "MS Sans Serif")
$EditSec = GUICtrlCreateEdit("", 45, 45, 1090, 644, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $ES_NOHIDESEL))
$Edit2 = GUICtrlCreateEdit("", 11, 45, 33, 617, BitOR($ES_RIGHT, $ES_READONLY, $ES_WANTRETURN))
GUICtrlSetData(-1, StringFormat(" 1:\r\n 2:\r\n 3:\r\n 4:\r\n 5:\r\n 6:\r\n 7:\r\n 8:\r\n 9:\r\n10:\r\n11:\r\n12:\r\n13:\r\n14:\r\n15:\r\n16:\r\n17:\r\n18:\r\n19:\r\n20:\r\n21:\r\n22:\r\n23:\r\n24:\r\n25:\r\n26:\r\n27:\r\n28:\r\n29:\r\n30:"))
$Label1 = GUICtrlCreateLabel("Select Section:", 7, 13, 126, 24)
GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif")
$Savesec = GUICtrlCreateButton("Save Changes", 375, 7, 129, 33)
$NewSec = GUICtrlCreateButton("New Section", 700, 7, 121, 33)
$SecDwn = GUICtrlCreateButton("Section Down", 830, 7, 137, 33)
$SecUp = GUICtrlCreateButton("Section Up", 980, 7, 129, 33)
;$LineNo = GUICtrlCreateInput("LineNo", 664, 7, 65, 28)
$copystrs = GUICtrlCreateButton("*******", 507, 7, 73, 33)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$HeavySep = GUICtrlCreateButton("====", 581, 7, 73, 33)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
Global $SecSel
Global $secno
Global $secn = "NULLz"
Global $sFilePathtemp
Global $aArray
Global $SecNames
Global $secnnew
Global $ssecn
$SecSel = GUICtrlCreateCombo("", 110, 10, 257, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
queysecs()
Filledit()
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$secno=GUICtrlRead($SecSel)
$changed=0
While 1
    $secn = GUICtrlRead($SecSel)
    ;If $secn <> $secno and $changed=0 Then
    ;   $secns = $secn
    ;   $changed=1
    ;EndIf
    $nMsg = GUIGetMsg()
    ;MsgBox(4, "TEST1?", $secn)
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            saveeditedmsg()
            Exit
        Case $SecSel
            ;MsgBox(4, "TEST?", GUICtrlRead($SecSel))
            ;MsgBox(4, "TEST1?", $secns)
            ;MsgBox(4, "TEST2?", $secn)
            $secno=GUICtrlRead($SecSel)
            ;saveeditedmsg()
            queysecs()
            Filledit()
            ;$changed=0
        Case $Savesec
            saveeditedmsg()
            queysecs()
        Case $NewSec
        Case $SecDwn
        Case $SecUp
        Case $copystrs
            ClipPut("**************************************************************************************************************************************************************")
        Case $HeavySep
            ClipPut("==============================================================================================================================================================")

    EndSwitch
    ; MsgBox(4, "TEST2?", $secn)
WEnd

Func queysecs();query section names
    $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini"
    $aArray = IniReadSectionNames($sFilePath)
    $SecNames = $aArray[1]
    ; MsgBox(4, "test3?", $secn)
    If $secn = "NULLz" Then
        $secn = $aArray[1]
    EndIf
    If Not @error Then
        For $i = 2 To $aArray[0]
            $SecNames = $SecNames & "|" & $aArray[$i]
        Next
        GUICtrlSetData($SecSel, "", "")
        GUICtrlSetData($SecSel, $SecNames, $secn)
        $secno = $secn
        ;MsgBox(4, "test4?", $secn)
    EndIf
EndFunc   ;==>queysecs

Func Filledit(); transfer section values on the edit box
    GUICtrlSetData($EditSec, "")
    $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini"
    For $i = 1 To 30
        $sRead = IniRead($sFilePath, $secn, $i, "")
        GUICtrlSetData($EditSec, $sRead & @CRLF, 1)
    Next
    GUISetState(@SW_SHOW)
EndFunc   ;==>Filledit

Func saveeditedmsg(); save or rename modified section
    If $secn <> $secno Then
        $iMsgBoxAnswer = MsgBox(3, "NEW/RENAME", "Press YES to Add this as NEW section" & @CRLF & "Press NO to rename and save this section from " & $secno & "To" & $secn)
        Select
            Case $iMsgBoxAnswer = 6 ;YES
                $secn = $secno
                save($secn)
                $secn = GUICtrlRead($SecSel)
                $secno = $secn
            Case 7 ;NO
                $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini"
                IniRenameSection($sFilePath, $secno, $secn)
                save($secn)
                $secn = GUICtrlRead($SecSel)
                $secno = $secn
        EndSelect
    Else
        $iMsgBoxAnswer = MsgBox(4, "Do you want to save changes to this section", "Save Section: " & $secn)
        Select
            Case $iMsgBoxAnswer = 6 ;yes
                save($secn)
        EndSelect
    EndIf
EndFunc   ;==>saveeditedmsg

;MsgBox(4, "Do you want to add this to Database?",$secn)
Func save($ssecn); save edit control to a file and then rewrite modified values by line order.
    $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8)
    $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini"
    FileWrite($sFilePathtemp, GUICtrlRead($EditSec))
    $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_UTF8)
    For $i = 1 To 30
        $sRead = FileReadLine($sFilePathtemp, $i)
        IniWrite($sFilePath, $ssecn, $i, $sRead)
    Next
    GUISetState(@SW_SHOW)
EndFunc   ;==>save

The ini file withthe au3 attached

This is how I want: when the user changes the combo, the script will check the text combo. In case of changed text it will ask user if I should rename or add it as a new section and then save. If not changed the text of combo it will ask to save only.

IF NOT possible, Will it possible with _GUICtrlComboBox__GUICtrlComboBoxEx_Create or _GUICtrlComboBoxEx_Create or not

 

THANK you very much in advance

QuickSecEdit.zip

Edited by Grasoft
Link to comment
Share on other sites

Hmm. It looks like that you save the changes (in saveeditedmsg func) before reading the new combo value

Func saveeditedmsg(); save or rename modified section
    If $secn <> $secno Then
        $iMsgBoxAnswer = MsgBox(3, "NEW/RENAME", "Press YES to Add this as NEW section" & @CRLF & "Press NO to rename and save this section from " & $secno & "To" & $secn)
        Select
            Case $iMsgBoxAnswer = 6 ;YES
                $secn = $secno
        msgbox(0,"before save", $secn) ; <<<< old value
                save($secn)  ; <<<<<<< new values saved here 
                $secn = GUICtrlRead($SecSel) ; <<<<<< combo read here
        msgbox(0,"after save", $secn) ; <<<< new value
                $secno = $secn
                
            Case 7 ;NO   ; <<<<<< should be "Case $iMsgBoxAnswer = 7" or "Case Else"

 

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

×
×
  • Create New...