Sign in to follow this  
Followers 0
Adamrv1

Remebering variables after script exits

4 posts in this topic

This is my script:

Dim $variable

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("MyVar", 155, 90, 398, 238)
$Button1 = GUICtrlCreateButton("Create Variable", 8, 8, 137, 33, 0)
$Button2 = GUICtrlCreateButton("Display Variable", 8, 48, 137, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button1
            $variable = inputbox("Variable","type Something")
        Case $button2
            MsgBox(0,"Variable","The Variable is: " & $variable)
    EndSwitch
WEnd

When you run it a GUI appears with two buttons:

"create Variable" &

"Display Variable"

First you choose "Create Variable", then you enter some text

Next you choose "Display Variable", you will receive a msgbox displaying the variable you just created

Now Let's say i want to first create my variable, exit the script, reopen the script, click "Display variable" and see the variable i assigned before i closed the script

First off, Is this even possible, and if so, can someone please tell me how (examples would help)


Share this post


Link to post
Share on other sites



You'll need to write the variable to something - registry, a file, whatever - and read it back from there.

Share this post


Link to post
Share on other sites

Try

;Dim $variable

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("MyVar", 155, 90, 398, 238)
$Button1 = GUICtrlCreateButton("Create Variable", 8, 8, 137, 33, 0)
$Button2 = GUICtrlCreateButton("Display Variable", 8, 48, 137, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $variable = InputBox("Variable", "type Something")
            IniWriteSection(@ScriptDir & "\test.ini", "section name", "Variable=" & $variable)
        Case $Button2
            $variable = IniRead(@ScriptDir & "\test.ini", "section name", "Variable", "No variable has been created")
            MsgBox(0, "Variable", "The Variable Is: " & $variable)
    EndSwitch
WEnd

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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