Jump to content
Sign in to follow this  
msz006plus

My GUI Closed after a For loop finished in function

Recommended Posts

Hi everyone, I'm fresh to AutoIt.

Recently, I'm making a GUI to save my settings into a ini file. 

Part of my design is that when "CLEAR" button is hit, a default ini file will be loaded.

Therefore, I created a function which include a for loop to load the ini file.

However, my GUI is closed after the function is executed at the very end of the for loop (Next)

 

I tried my best googling and search this great forum , i found these for reference (cause they use a for loop for button function too): 

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

 

Would anyone give me some advice please?

(if any violating the forum rules, please let me know)

 

#include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

... (plot GUI part) ...

Local $VENDOR_5G_STATE = GUICtrlRead($CID_VENDOR_5G)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $CID_LAYER2_ATM
            GUICtrlSetState($CID_SELECT_ETH, $GUI_DISABLE)

        Case $CID_LAYER2_PTM
            GUICtrlSetState($CID_SELECT_ETH, $GUI_DISABLE)

        Case $CID_LAYER2_ETH
            GUICtrlSetState($CID_SELECT_ETH, $GUI_ENABLE)

        Case $CID_WIFI_YES
            GUICtrlSetState($CID_5G_YES, $GUI_ENABLE)
            GUICtrlSetState($CID_5G_NO, $GUI_ENABLE)

        Case $CID_WIFI_NO
            GUICtrlSetState($CID_5G_YES, $GUI_DISABLE)
            GUICtrlSetState($CID_5G_NO, $GUI_DISABLE)
            GUICtrlSetState($CID_VENDOR_5G, $GUI_DISABLE)
            GUICtrlSetState($CID_SUB_IP, $GUI_DISABLE)

        Case $CID_5G_YES
            GUICtrlSetState($CID_VENDOR_5G, $GUI_ENABLE)

        Case $CID_5G_NO
            GUICtrlSetState($CID_VENDOR_5G, $GUI_DISABLE)
            GUICtrlSetState($CID_SUB_IP, $GUI_DISABLE)

        Case $CID_BTN_CLEAR
            GUI_Load_Config("Default.ini")

        Case $CID_BTN_EXIT
            $tempini = @ScriptDir & "\temp.ini"
            GUI_Save_Config($tempini)
            Exit

    EndSwitch

    If GUICtrlRead($CID_VENDOR_5G) <> $VENDOR_5G_STATE Then
        If GUICtrlRead($CID_VENDOR_5G) == "QUANTENNA" Then
            GUICtrlSetState($CID_SUB_IP, $GUI_ENABLE)
        Else
            GUICtrlSetState($CID_SUB_IP, $GUI_DISABLE)
        EndIf
    EndIf
    $VENDOR_5G_STATE = GUICtrlRead($CID_VENDOR_5G)

WEnd


Func GUI_Load_Config($Load_ini)

    MsgBox(0,"","Clear hit")
    $Section_Array = IniReadSection(@ScriptDir & "\" & $Load_ini, "BASIC INFO")
    $ROWS = UBound($Section_Array, $UBOUND_ROWS)
    _ArrayDisplay($Section_Array)

    For $i = 1 To $ROWS
        $temp_key = $Section_Array[$i][0]
        $temp_value = $Section_Array[$i][1]
        $srch_row = _ArraySearch($BASIC_INFO, $temp_key, 0, 0, 1, 1, 1)
        $mod_CID = $BASIC_INFO[$srch_row][1]

        GUICtrlSetData($mod_CID, $temp_value)
    Next
EndFunc

Share this post


Link to post
Share on other sites

Please post something that can be run, you're missing functions and there's no way for us to test this.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

You're right BrewManNH, sorry for that. 
I made another .au3 file as attached to specify my question.

I tried to make a GUI that can save and load my settings into a .ini file.

I got 2 questions:

1. I set group caption fonts color white, but when I run this script, it still black

2. Load function can read .ini file and write into BASIC INFO group. But when it done writing, my GUI also close.

 

Can anyone help me? :)

 

save_load.au3

Load.ini

Share this post


Link to post
Share on other sites

Do you read your Scite console ? 

 

(86) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.

That mean you have to check that $Var : $temp_key 

You are trying to access an non existant row. 

 

You can reproduce this bug by doing this : 

$ClearHit = "x"

MsgBox(0,"",$ClearHit[2])

;Actualy your script is doing this. :/

 

You have to

Ubound

it first.

 

Check that in Scite help file and come back here if you need help :)

 

Fixed exemple : 

$ClearHit = "x"

$ClearHitRow = UBound ($ClearHit)

If $ClearHitRow = 3 Or $ClearHitRow = "3" Then 
    MsgBox(0,"",$ClearHit[2])
EndIf

;Now it is fixed you wont get error doing this.

 

Edited by caramen

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Here's the corrected func of your script:

Func Load_Config($Load_ini)
    MsgBox(0, "", "Clear hit")
    $Section_Array = IniReadSection(@ScriptDir & "\" & $Load_ini, "BASIC INFO")
    ;$ROWS = UBound($Section_Array, $UBOUND_ROWS) -1 ;isn't needed yours 1 to big 
    _ArrayDisplay($Section_Array)

    For $i = 1 To $Section_Array[0][0] ;note: your array is not 0 based element 0 | 0 = number of real data rows
    _ArrayDisplay($Section_Array)

    For $i = 1 To $Section_Array[0][0] ;note: your array is not 0 based element 0 | 0 = number of rows
        $temp_key = $Section_Array[$i][0]
        $temp_value = $Section_Array[$i][1]
        $srch_row = _ArraySearch($BASIC_INFO, $temp_key, 0, 0, 1, 1, 1)
        If Not @error Then      ;do only if no error occurs not realy needed error only occurs if someone change ini in this very small time 
            $mod_CID = $BASIC_INFO[$srch_row][1]
            GUICtrlSetData($mod_CID, $temp_value)
        EndIf
    Next
EndFunc   ;==>Load_Config

you have to read in the help about arrays if my small comments are not enough.

Edited by AutoBert

Share this post


Link to post
Share on other sites
3 minutes ago, AutoBert said:

you have to read in the help about arrays if my small comments are not enough.

That's why you should remove your fix and let him find the fix.

Edited by caramen

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks caramen, your explanation is just wonderful! I did read the help file before, however I didn't notice the console message.

AutoBert, thanks so much! I miscalculated the iteration index.

Both of you gave me a big jump.

What about the other question about the fonts color?

Is it "Checkbox, Radio, Group or Progress controls cannot be painted if the "Windows XP/Vista style" is used." in help file the reason that my Group caption stay black?

(my OS is windows 10)

;$ROWS = UBound($Section_Array, $UBOUND_ROWS)-1

Share this post


Link to post
Share on other sites

You are welcome,

It is the same problem as before :)

Syntaxt and knowledge problem

 

you have to read try learn ;)

 

$Group1 = GUICtrlCreateGroup("BASIC INFO", 24, 24, 249, 161)
    GUICtrlSetFont(-1, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xF0F0F0)

$Label1 = GUICtrlCreateLabel("Name:", 56, 72, 65, 28)
    GUICtrlSetColor(-1, 0xF0F0F0)

Try that and you will understand yourself i am sure.


My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...