Jump to content
Sign in to follow this  
swstrau118

Replace String in Script.. HELP!

Recommended Posts

swstrau118

Is there a way to take a variable: $Test = "hello world" and replace the string "hello world" to whatever you want it to be through an inputbox? and whatever you change the string to it will save that value in the script until you change it again?

Share this post


Link to post
Share on other sites
BrewManNH

Is there a way to take a variable: $Test = "hello world" and replace the string "hello world" to whatever you want it to be through an inputbox? 

Yes, use this, it will return whatever is inside the InputBox to the variable $Test.

$Test = InputBox("Some Title", "Some Prompt", "Hello World")

 

and whatever you change the string to it will save that value in the script until you change it again?

Not in the script directly, you'd need to recompile the script, if it's a compiled exe, with the new default value for the InputBox. Or use an INI file to save the contents of the variable to be used the next time the script is started.

There are hundreds of examples posted on how to do this on the forum.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
swstrau118

Yes, use this, it will return whatever is inside the InputBox to the variable $Test.

$Test = InputBox("Some Title", "Some Prompt", "Hello World")

Not in the script directly, you'd need to recompile the script, if it's a compiled exe, with the new default value for the InputBox. Or use an INI file to save the contents of the variable to be used the next time the script is started.

There are hundreds of examples posted on how to do this on the forum.

 

Ok great! I thought there was a way to change the value for the variable, in a exe, without having to re-compile the code. Would it be possible when you first run that script it would prompt you to type an input value for the variable $Test and store that input as an array? as long as you don't close that script it will remember that variable's value until you close the script. Would that be possible?

Share this post


Link to post
Share on other sites
0xdefea7

Maybe what you want is possible without an array, like this:

$Test = InputBox("Some Title", "Some Prompt")

While 1 ;Loop forever
    ConsoleWrite("The value of $Test is: " & $Test & @CRLF) ;Write it out to the console
    Sleep(5000) ;Stop for 5 seconds, then start the loop over
Wend
Edited by 0xdefea7

Share this post


Link to post
Share on other sites
swstrau118

Here is the code I am trying to use this on: I still can't get the Input box to change/remember the value I put in for the variable $uname

; Press Esc to terminate script, Pause/Break to "pause"
#Include<IE.au3>
Global $Paused
HotKeySet("{`}", "Terminate")


Func Terminate()
$oIE = _IECreate ("website")
$oForm = _IEFormGetObjByName ($oIE, "MAIN")
$oQuery1 = _IEFormElementGetObjByName ($oForm, "SITE")
$oQuery2 = _IEFormElementGetObjByName ($oForm, "LOGON_ID")
$sin="1001"
$uname ;This is where I am trying to change the value by input field (only once) and will keep it in memory until script is closed

_IEFormElementSetValue ($oQuery1,$sin)
_IEFormElementSetValue ($oQuery2,$uname)
$oButton=_IEGetObjById($oIE,"ENTER")
_IEAction ($oButton, "click")
_IELoadWait($oIE,0)

EndFunc   ;==>Terminate
Edited by swstrau118

Share this post


Link to post
Share on other sites
0xdefea7

; Press Esc to terminate script, Pause/Break to "pause"
#Include<IE.au3>
Global $Paused
HotKeySet("{`}", "Terminate")

$sUserName = InputBox("", "Please enter your username: ") ;Get data from the input

Terminate($sUserName) ;use it later to change the name


Func Terminate($uname)
$oIE = _IECreate ("website")
$oForm = _IEFormGetObjByName ($oIE, "MAIN")
$oQuery1 = _IEFormElementGetObjByName ($oForm, "SITE")
$oQuery2 = _IEFormElementGetObjByName ($oForm, "LOGON_ID")
$sin="1001"
$uname ;This has been set before the function was called and will remain the same as the value that was input for the duration of the script

_IEFormElementSetValue ($oQuery1,$sin)
_IEFormElementSetValue ($oQuery2,$uname)
$oButton=_IEGetObjById($oIE,"ENTER")
_IEAction ($oButton, "click")
_IELoadWait($oIE,0)

EndFunc   ;==>Terminate

Share this post


Link to post
Share on other sites
swstrau118
; Press Esc to terminate script, Pause/Break to "pause"
#Include<IE.au3>
Global $Paused
HotKeySet("{`}", "Terminate")

$sUserName = InputBox("", "Please enter your username: ") ;Get data from the input

Terminate($sUserName) ;use it later to change the name


Func Terminate($uname)
$oIE = _IECreate ("website")
$oForm = _IEFormGetObjByName ($oIE, "MAIN")
$oQuery1 = _IEFormElementGetObjByName ($oForm, "SITE")
$oQuery2 = _IEFormElementGetObjByName ($oForm, "LOGON_ID")
$sin="1001"
$uname ;This has been set before the function was called and will remain the same as the value that was input for the duration of the script

_IEFormElementSetValue ($oQuery1,$sin)
_IEFormElementSetValue ($oQuery2,$uname)
$oButton=_IEGetObjById($oIE,"ENTER")
_IEAction ($oButton, "click")
_IELoadWait($oIE,0)

EndFunc   ;==>Terminate

I tried this code but it will not allow me to use the HotKey for some reason - do you know why? And thanks so much for helping me out.

Share this post


Link to post
Share on other sites
JCEF

See if this helps

#include<IE.au3>

While 1
    Sleep(250)
    HotKeySet("`", "Terminate")
    HotKeySet("{ESC}", "Sair")
WEnd

Func Sair()
    Exit
EndFunc   ;==>Sair

Func Terminate()
    $sUserName = InputBox("", "Please enter your username: ") ;Get data from the input
    $oIE = _IECreate("website")
    $oForm = _IEFormGetObjByName($oIE, "MAIN")
    $oQuery1 = _IEFormElementGetObjByName($oForm, "SITE")
    $oQuery2 = _IEFormElementGetObjByName($oForm, "LOGON_ID")
    $sin = "1001"
    _IEFormElementSetValue($oQuery1, $sin)
    _IEFormElementSetValue($oQuery2, $sUserName)
    $oButton = _IEGetObjById($oIE, "ENTER")
    _IEAction($oButton, "click")
    _IELoadWait($oIE, 0)
EndFunc   ;==>Terminate

Share this post


Link to post
Share on other sites
swstrau118

 

See if this helps

#include<IE.au3>

While 1
    Sleep(250)
    HotKeySet("`", "Terminate")
    HotKeySet("{ESC}", "Sair")
WEnd

Func Sair()
    Exit
EndFunc   ;==>Sair

Func Terminate()
    $sUserName = InputBox("", "Please enter your username: ") ;Get data from the input
    $oIE = _IECreate("website")
    $oForm = _IEFormGetObjByName($oIE, "MAIN")
    $oQuery1 = _IEFormElementGetObjByName($oForm, "SITE")
    $oQuery2 = _IEFormElementGetObjByName($oForm, "LOGON_ID")
    $sin = "1001"
    _IEFormElementSetValue($oQuery1, $sin)
    _IEFormElementSetValue($oQuery2, $sUserName)
    $oButton = _IEGetObjById($oIE, "ENTER")
    _IEAction($oButton, "click")
    _IELoadWait($oIE, 0)
EndFunc   ;==>Terminate

The button works now however, is it possible to have the script hold the username in memory while it's running? So every time you hit the "HotKey" it would pass the input you previously put in. Once you close the script then you would have to retype that input to then hold it in memory till closed again. I am trying to avoid having to have the input box come up every time. Do you think this is possible?

Share this post


Link to post
Share on other sites
JCEF

Is this what you want?

#include<IE.au3>

$sUserName = InputBox("", "Please enter your username: ") ;Get data from the input

While 1
    Sleep(250)
    HotKeySet("`", "Terminate")
    HotKeySet("{ESC}", "Sair")
WEnd

Func Sair()
    ;MsgBox(0, "User", $sUserName, 2); If you want to confirm the "username" immediately before exit the script, uncomment this line
    Exit
EndFunc   ;==>Sair

Func Terminate()
    $oIE = _IECreate("website")
    $oForm = _IEFormGetObjByName($oIE, "MAIN")
    $oQuery1 = _IEFormElementGetObjByName($oForm, "SITE")
    $oQuery2 = _IEFormElementGetObjByName($oForm, "LOGON_ID")
    $sin = "1001"
    _IEFormElementSetValue($oQuery1, $sin)
    _IEFormElementSetValue($oQuery2, $sUserName)
    $oButton = _IEGetObjById($oIE, "ENTER")
    _IEAction($oButton, "click")
    _IELoadWait($oIE, 0)
EndFunc   ;==>Terminate

Share this post


Link to post
Share on other sites
swstrau118

 

Is this what you want?

#include<IE.au3>

$sUserName = InputBox("", "Please enter your username: ") ;Get data from the input

While 1
    Sleep(250)
    HotKeySet("`", "Terminate")
    HotKeySet("{ESC}", "Sair")
WEnd

Func Sair()
    ;MsgBox(0, "User", $sUserName, 2); If you want to confirm the "username" immediately before exit the script, uncomment this line
    Exit
EndFunc   ;==>Sair

Func Terminate()
    $oIE = _IECreate("website")
    $oForm = _IEFormGetObjByName($oIE, "MAIN")
    $oQuery1 = _IEFormElementGetObjByName($oForm, "SITE")
    $oQuery2 = _IEFormElementGetObjByName($oForm, "LOGON_ID")
    $sin = "1001"
    _IEFormElementSetValue($oQuery1, $sin)
    _IEFormElementSetValue($oQuery2, $sUserName)
    $oButton = _IEGetObjById($oIE, "ENTER")
    _IEAction($oButton, "click")
    _IELoadWait($oIE, 0)
EndFunc   ;==>Terminate

Yes! that's awesome! Now looking at the code it seems so easy..

Thanks alot!

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  

×