Jump to content

Keep Data From Second GUI Form while closed.


Go to solution Solved by water,

Recommended Posts

Posted

Hello!

I am having a little problem with GUI's and its data. I want to keep data inside the input even when the data form is closed. Is it possible to do it? 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 613, 431, 192, 132)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem4 = GUICtrlCreateMenuItem("Load File", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenuItem("Save File", $MenuItem1)
$MenuItem6 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("Program")
$MenuItem7 = GUICtrlCreateMenuItem("Connector IP", $MenuItem2)
$MenuItem3 = GUICtrlCreateMenu("Help")
$MenuItem8 = GUICtrlCreateMenuItem("About", $MenuItem3)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem7
            Connector()
    EndSwitch
WEnd

Func Connector()
#Region ### START Koda GUI section ### Form=
$Connector = GUICreate("Connector IP", 614, 129, 192, 132)
$Label1 = GUICtrlCreateLabel("Insert IP", 24, 24, 51, 20)
$Input1 = GUICtrlCreateInput("", 80, 24, 121, 24)
$Button1 = GUICtrlCreateButton("Connect", 48, 88, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete($Connector)
            ExitLoop
    EndSwitch
WEnd
EndFunc


 

 

I have prepared a sample. What can you see is Func Conncetor() which has a couple of information. I am interested in $Input1, where I'd like to store data.
When I insert the data into it, and close $Connector's GUI, all the data is no longer available in program. 
If I'd like to click to "Save File" it'd show that there is no data to save. 

Is there any option to close that window without erasing data, and saving it ? 

Posted (edited)
47 minutes ago, StudentJack said:

Is there any option to close that window without erasing data, and saving it ? 

Not the most elegant way, but ...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_sConnector_IP = ''

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 613, 431, 192, 132)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem4 = GUICtrlCreateMenuItem("Load File", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenuItem("Save File", $MenuItem1)
$MenuItem6 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("Program")
$MenuItem7 = GUICtrlCreateMenuItem("Connector IP", $MenuItem2)
$MenuItem3 = GUICtrlCreateMenu("Help")
$MenuItem8 = GUICtrlCreateMenuItem("About", $MenuItem3)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem7
            Connector()
    EndSwitch
WEnd

Func Connector()
#Region ### START Koda GUI section ### Form=
$Connector = GUICreate("Connector IP", 614, 129, 192, 132)
$Label1 = GUICtrlCreateLabel("Insert IP", 24, 24, 51, 20)
$Input1 = GUICtrlCreateInput($g_sConnector_IP, 80, 24, 121, 24)
$Button1 = GUICtrlCreateButton("Connect", 48, 88, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            $g_sConnector_IP = GUICtrlRead($Input1)
            GUIDelete($Connector)
            ExitLoop
    EndSwitch
WEnd
EndFunc

 

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted (edited)
43 minutes ago, Musashi said:

Not the most elegant way, but ...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $g_sConnector_IP = ''

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 613, 431, 192, 132)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem4 = GUICtrlCreateMenuItem("Load File", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenuItem("Save File", $MenuItem1)
$MenuItem6 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("Program")
$MenuItem7 = GUICtrlCreateMenuItem("Connector IP", $MenuItem2)
$MenuItem3 = GUICtrlCreateMenu("Help")
$MenuItem8 = GUICtrlCreateMenuItem("About", $MenuItem3)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MenuItem7
            Connector()
    EndSwitch
WEnd

Func Connector()
#Region ### START Koda GUI section ### Form=
$Connector = GUICreate("Connector IP", 614, 129, 192, 132)
$Label1 = GUICtrlCreateLabel("Insert IP", 24, 24, 51, 20)
$Input1 = GUICtrlCreateInput($g_sConnector_IP, 80, 24, 121, 24)
$Button1 = GUICtrlCreateButton("Connect", 48, 88, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            $g_sConnector_IP = GUICtrlRead($Input1)
            GUIDelete($Connector)
            ExitLoop
    EndSwitch
WEnd
EndFunc

 

That works indeed. Thanks! ❤️ Also, I have around 60 inputs in my script, maybe is there faster way to do it?  
@ I have checked, and it works with case of 1 input, but with several inputs it doesn't. 

Edited by StudentJack
Posted
4 hours ago, StudentJack said:

That works indeed. Thanks! ❤️ Also, I have around 60 inputs in my script, maybe is there faster way to do it?  

There are several ways to create GUI's, e.g. using Arrays (possibly with the additional usage of ini-files).

Just have a look at the following thread : creating-menus-using-arrays

Analogously, input fields and labels can also be managed via arrays. However, this is not a trivial task, especially if you are not so familiar with the use of Arrays ;).

If you want to stick with single fields, then it would make at least sense to give them more meaningful names.

Example : Instead of

...
$Label1 = GUICtrlCreateLabel("Insert IP", 24, 24, 51, 20)
$Input1 = GUICtrlCreateInput($g_sConnector_IP, 80, 24, 121, 24)
...

use  

$idLblConnectorIP = GUICtrlCreateLabel("Insert IP", 24, 24, 51, 20)
$idInpConnectorIP = GUICtrlCreateInput($g_sConnector_IP, 80, 24, 121, 24)

This is more legible compared to $Input1...$Input60 and $Label1...$Label60.

 

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

  • Solution
Posted

Do not close the 2nd GUI, just disable it. That's the way I do it.
In the wiki there is a tutorial about working with multiple GUIs.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...