Jump to content

Replace String in Script.. HELP!


Go to solution Solved by JCEF,

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

; 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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

  • Solution

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
Link to comment
Share on other sites

 

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!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...