Sign in to follow this  
Followers 0
Tobytja

Saving GUI inputs

7 posts in this topic

Hello,

when I want to put some variable to script, which's value is defined through GUICtrlCreateInput function, I can predefine the value by putting the appropriate text as the first function parameter. Can I somehow modify the parameter from the GUI? Like by creating a "save" button, which would rewrite the original function parameters inside of the script with the actual values in Input fields.

Thanks

Share this post


Link to post
Share on other sites



Do you mean GuiCtrlSetData to set the value of a Control? Or do you want to save the input to a file so that if you start the script again can retrieve the current value of the control from the file?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I mean, for example I have this command defined:

GLOBAL $Input3 = GUICtrlCreateInput("Script", 134, 90, 209, 21)

Which puts a word "Script" to the Input field, when the GUI is opened. After clicking on a button, script reads the value and starts. But if I modify the input value, the script doesn't remember it and next time the word "Script" appears there again.

Say that someone else wants to have "DeuBa Script" as a preset value. Now he must open the script for editing and manually rewrite the parameter from "Script" to "DeuBa Script" or rewrite the value in the Input field each time he opens the GUI. I'd like to find a way to edit the command inside of the script, without having to open it for editing, so that it inside of the script looks like this:

GLOBAL $Input3 = GUICtrlCreateInput("DeuBa Script", 134, 90, 209, 21)

Is there any way to do this?

Edited by Tobytja

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Something like this? It reads the value for the input control from a ini file. As soon as you press "Save" the current value is saved to the input file and will be displayed as soon as you restart the script.

#include <GUIConstantsEx.au3>

Global $hSave, $msg
Global $sInput = IniRead("Test.ini", "Config", "Input", "")
GUICreate(" My GUI input", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45)
Global $hInput = GUICtrlCreateInput($sInput, 10, 5, 300, 20)
$hSave = GUICtrlCreateButton("Save", 40, 75, 60, 20)
GUISetState()
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $hSave
            $sInput = GUICtrlRead($hInput)
            IniWrite("Test.ini", "Config", "Input", $sInput)
    EndSelect
WEnd
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Can it be done without any additional file? It would be more "idiot-proof", since most of the people using the script have no IT skill, they are just "trained monkeys". That's the reason I'm looking for a way to simplify the way to change preset values in the first place. So it could easily happen, that they forget they need this file, delete it and then come crying "hey, why it doesn't work?"

Share this post


Link to post
Share on other sites

Well, another way is to write to and retrieve from the Registry.

Obviously, if it finds no entry there, then it writes in the defaults ... which is what would happen if the program was run on another PC. An ini file is less intrusive though, and the program can also be set to recreate the ini with defaults if missing. Most users don't know about ini files and don't need to, as it should be an invisible interaction.

To do as you request, would mean having to change the code of a compiled script, and then recompile it each time, which is even more of a hassle than worrying about ini files. At least with the registry option, the program can be relocated at will anywhere on the same PC, and have no problem recalling stored values.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

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  
Followers 0