Jump to content
Sign in to follow this  
SecretRaindrop

edit variable in script without opening editor

Recommended Posts

SecretRaindrop

What I want to be able to do:

Start script, window with text box opens.

I enter a number,press OK.

That number replaces the default 0 in a global variable in the script.

Could someone walk me through how that can be done?

Thx in advance

Share this post


Link to post
Share on other sites
JLogan3o13

Look at the ini functions in the Help File. Prompt for the variable you want, then overwrite it in the file.

Edit: Home sick and bored, so here's a freebee as an example:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$oINI = @DesktopDir & "\My.ini"
$oVal = IniRead($oINI, "MyVar", "Var1", "")
GUICreate("Test", 200, 100)
$sInput = GUICtrlCreateInput($oVal, 10, 10, 180, 30)
 GUICtrlSetFont(-1, 14, 400, Default, "Arial")
$btnUpdate = GUICtrlCreateButton("Update", 10, 60, 50, 30)

GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE
    ExitLoop
   Case $btnUpdate
    $newVal = GUICtrlRead($sInput)
    IniWrite($oINI, "MyVar", "Var1", $newVal)
  EndSwitch
    WEnd
GUIDelete()
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
SecretRaindrop

And the popup window with a textbox part?

Share this post


Link to post
Share on other sites
JLogan3o13

Did you try the code?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
SecretRaindrop

commented before i saw the update, will try

Share this post


Link to post
Share on other sites
SecretRaindrop

So this obviously wirtes to an .ini file, but how do i get it to write to the .au3 file that the variable i want to change is?

I am very new to scrpting and am currently messing around with my first script learning stuff as i go.

Share this post


Link to post
Share on other sites
SmOke_N

Be deliberate and specific in your questions.  Show code you've tried, don't leave it to us to be mind readers and supply code.

Do you mean to change a variable to an .au3 file you're NOT running? (I seriously hope not, if that's the case, then just use the ini file idea, and have the other .au3 file read the ini file and assign the value to the global variable)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
SecretRaindrop

Sorry, hadent really tried anything as i had no idea how to do the GUI part.

Using the code he supplied, i removed the INI part and tried to make the gui save the text in the textbox to a variable, then copying that variable to the global variable.

Here is the code:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.12.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("a", "Regi")
HotKeySet("{Esc}", "On_Exit")

Global $Val = 0
Global $Counter = 0

GUICreate("Test", 200, 100)
$sInput = GUICtrlCreateInput($Val, 10, 10, 180, 30)
 GUICtrlSetFont(-1, 14, 400, Default, "Arial")
$btnUpdate = GUICtrlCreateButton("Update", 10, 60, 50, 30)

GUISetState(@SW_SHOW)
    While 1
        Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE
    ExitLoop
   Case $btnUpdate
    $Counter = $Val
  EndSwitch
    WEnd
GUIDelete()

While 1
   Sleep(100)
   WEnd

Func Regi()
   While 1
   Send("{Enter}")
   Sleep(848)
   Send("{Enter}")
   Sleep(400)
   Send("{Enter}")
   Sleep(736)
   Send("{Enter}")
   Sleep(672)
   Send("{Enter}")
   Sleep(448)
   Send("{Enter}")
   Sleep(500)
   $Counter = $Counter + 1
   If $Counter = 410 Then Exit 
   WEnd

EndFunc



Func On_Exit()
   Exit
EndFunc

Share this post


Link to post
Share on other sites
JLogan3o13

Again, can you explain what you're trying to do, what window/application you're trying to automate? 99% of the time there is a better way than scripting a bunch of Sends.


√-1 2^3 ∑ π, and it was delicious!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.