Jump to content

Recommended Posts

Posted

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

  • Moderators
Posted (edited)

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

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.

  • Moderators
Posted

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.

Posted

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
  • Moderators
Posted

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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