Jump to content

Rather strange problem with a GUI and variables not updating


Recommended Posts

Hi Im having a problem wiich kinda blows my mind 

 

I have a finished GUI 100% workin or rather 99% % since im trying to add some error handling.My GUI also handles a 2nd GUI and the code is based on this example:

https://www.autoitscript.com/wiki/Managing_Multiple_GUIs

 

So Im hoping to avoid posting my entire code since its a lot so I will try to explain. I have created a settings panel with a few combo´s, checkboxes , selectors and what not : realized today that some of the settings are contradictory and instead of disabling some choices I would rather tell the end user what went wrong. 

 

So the end code works like this: 

Func On_Button()
    Switch @GUI_CtrlId ; See which button sent the message
        Case $idRadio1
          Get_RadioData()
        Case $idRadio2
          Get_RadioData()
        Case $idCheckbox
          Get_CheckboxData()
        Case $idComboBox
          Get_WaitingData()
        Case $idComboBox2
          Get_WaitingData()
        Case $idComboBox3
          Get_WaitingData()
        Case $idComboBox_fin
          Get_finishData()
        Case $g_idButton2
            GUICtrlSetState($g_idButton2, $GUI_DISABLE)
            gui2()
        Case $g_idButton3
            GUIDelete($g_hGUI2) ; If it was this GUI - we just delete the GUI <<<<<<<<<<<<<<<
            GUICtrlSetState($g_idButton2, $GUI_ENABLE)
         Case $g_idButton4 ;  <-------------- Start/OK btn
            Get_ListData()
            Get_RadioData()
            Get_SliderData()
            Get_CheckboxData()
            Get_WaitingData()
            Get_finishData()
                errCheck()
                if $errCheck <> True Then
              GUIDelete($g_hGUI1) ; If it was this GUI - we just delete the GUI <<<<<<<<<<<<<<<
              GUIDelete($g_hGUI2) ; If it was this GUI - we just delete the GUI <<<<<<<<<<<<<<<
              PreStart()
            Else
              SoundPlay( @ScriptDir & "\Sounds\Error.mp3")
              MsgBox(262144 ,"Error", $errMsg)
                EndIf
         Case $idRCombo ;Selection Change
           $eVar = GUICtrlRead($idRCombo)
           GUI_Selection_Change($eVar)
         Case $g_idButton5 ;OK btn popup
           $eVar = GUICtrlRead($idRCombo2)
          if _GUICtrlListBox_GetCount($List1) < 3 Then
            GUICtrlSetData($List1, $eVar)
            GUIDelete($g_hGUI2) ; If it was this GUI - we just delete the GUI <<<<<<<<<<<<<<<
            GUICtrlSetState($g_idButton2, $GUI_ENABLE)
            Get_ListData()
          Else
            MsgBox(262144 ,$errTitle, "Maximum 3 targets supported by script")
         EndIf
       case $clearall ; CLear BTN region
         GUICtrlSetData($List1, "")
         Get_ListData()
    EndSwitch
 EndFunc   ;==>On_Button

And the problem is whit my error check function

Func errCheck()
  Local $iCnt = _GUICtrlListBox_GetCount($List1)
      if  $StartDelay = "True" And $iCnt = 0 Then ; <Just for testing 
    $errCheck = True
    $errTitle = "Err - No data selected"
    $errMsg = $iCnt
  EndIf
  If $errCheck <> True Then
    if $StartDelay = "True" And $Data = "Select" Then
      $errCheck = True
      $errTitle = "Err - Click on Select"
      $errMsg = "When delay is selected you need select"
     EndIf
   EndIf
   If $errCheck <> True Then
     if $StartDelay = "True" And $hDelay = "0H" And $mDelay = "0M" Then
       $errCheck = True
       $errTitle = "Contradiction Error"
       $errMsg = "Delayed startup Selected. but Hour and minute timers set to 0"
     EndIf
   EndIf
EndFunc

So what happens is this , The error check gets activated and when I change the settings it looks like the error check still checks the old data , however I log the variables in a txt file and I can see that they are changed so what baffles me is that the error checks gets activated. When I relaunch the window and selects settings which avoids the errorr check the script runs , but when I select back to settings which should activate the error check same problem. 

 

So somehow it looks like the error check uses old data or I dont know , really strange problem..

 

any suggestions ? 

Edited by Acce
Link to comment
Share on other sites

  • Moderators

Acce,

Add some errorchecking to see what happens in the various Get_*Data() functions. From your description of the problem I suspect that these functions are not actually reading the new state of the reset controls. 

M23

P.S. And having now seen the "Maximum 3 targets supported by script" comment I suggest reading the Forum rules before you post again.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi thanks for your reply and info regarding rules , I dont think my little script is against any rules ?

"From your description of the problem I suspect that these functions are not actually reading the new state of the reset controls. "

- these get*data functions are actually the functions that sets alle variables. What I tried now is to set a global variables like so  

 

$Global $rData 

It gets updated elsewhere in the code, Have striped the error code a bit for error checking a error check code :) 

And when I read it just before err_check() Func it has the expected value , Also strangely enough it has expected data in the error function . However after this code:

 

  MsgBox(262144 ,"Info box", $rData ) ; < -- Found Here
    if $rData = "" Then
      $errCheck = True
      $errTitle = "Err - Unexpected Error"
      $errMsg = "error: " & $rData ;< Returns blank here ?????
    EndIf

Also reading the var after this func returns expected result 

Link to comment
Share on other sites

  • Moderators

Acce,

Of course it will be blank at that point - the If statement is only true if that is the case!

if $rData = "" Then

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I dont understand maybe I looked at too many numbers today and my brain is not with me anymore , lol 

 

In my mind if this gets read with expected result:

MsgBox(262144 ,"Info box", $rData ) ; < -- Found Here

Then this if statement shouldn't be activated ? 

if $rData = "" Then

But it gets activated , its almost like the if statement change the value of $rdata

Link to comment
Share on other sites

You can test the code:

Global $rData

$rData ="r2D2"
Test()
CW(" 1>>" & $rData & "<<")
CW("")
$rData =""
Test()
CW(" 2>>" & $rData & "<<")

Func Test()
    Local $errCheck, $errTitle, $errMsg
    ;MsgBox(262144, "Info box", $rData) ; < -- Found Here
    CW("Before>" & $rData & "<")
    If $rData = "" Then
        $errCheck = True
        $errTitle = "Err - Unexpected Error"
        $errMsg = "error: " & $rData ;< Returns blank here ?????
        CW(" > " & $rData & "<")
    EndIf

EndFunc   ;==>Test

Func CW($txt)
    ConsoleWrite($txt & @CRLF)
EndFunc   ;==>CW

you should get following output:

Quote

Before>r2D2<
 1>>r2D2<<

Before><
 > <
 2>><<

 

Some of my script sourcecode

Link to comment
Share on other sites

OK I think I found the problem. I had forget to reset the var $errCheck to false after clicking ok btn , now I feel a little silly :=) 

 

thanks for taking interest anyway  

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

  • Recently Browsing   0 members

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