Sign in to follow this  
Followers 0
dascondor

HELP It "_ReplaceStringInFile" isn't working for me

8 posts in this topic

#1 ·  Posted

Okay so I know its me that's doing it wrong but let me see if you guys can figure it out.

So this is the Error I'm getting:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Dlex\Dropbox\New folder\IPfolder\math.au3"    
"C:\Users\Dlex\Dropbox\New folder\IPfolder\math.au3" (33) : ==> Variable used without being declared.:
_ReplaceStringInFile($sFilePath, $replace2)
_ReplaceStringInFile(^ ERROR
>Exit code: 1    Time: 1.713

I can't figure out what is what is happening with the Variable.

Please Help if you can.

 

 

IP_List.txt

math.au3

Share this post


Link to post
Share on other sites



#2 ·  Posted

Okay so I know its me that's doing it wrong but let me see if you guys can figure it out.

So this is the Error I'm getting:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Dlex\Dropbox\New folder\IPfolder\math.au3"    
"C:\Users\Dlex\Dropbox\New folder\IPfolder\math.au3" (33) : ==> Variable used without being declared.:
_ReplaceStringInFile($sFilePath, $replace2)
_ReplaceStringInFile(^ ERROR
>Exit code: 1    Time: 1.713

I can't figure out what is what is happening with the Variable.

Please Help if you can.

 

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#Region ### START Koda GUI section ### Form=c:\users\dlex\documents\koda_1.7.3.0\forms\dascondorstart.kxf
$DasCondor = GUICreate("DasCondor", 509, 242, -1, -1)
GUISetBkColor(0xFFFF00)
$Store = GUICtrlCreateLabel("What Store Are You Working At?", 112, 40, 311, 33)
GUICtrlSetFont(-1, 18, 800, 0, "Arial Narrow")
GUICtrlSetColor(-1, 0x000000)
$gobutton = GUICtrlCreateButton("GO", 88, 184, 75, 25)
GUICtrlSetBkColor(-1, 0x00FF00)
$clearbutton = GUICtrlCreateButton("Clear ", 224, 184, 75, 25)
GUICtrlSetBkColor(-1, 0x00FFFF)
$exitbutton = GUICtrlCreateButton("Exit", 384, 184, 75, 25)
GUICtrlSetBkColor(-1, 0xFF0000)
$data1 = GUICtrlCreateInput("1", 144, 112, 89, 36, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "Arial Rounded MT Bold")
$data2 = GUICtrlCreateInput("23", 254, 115, 89, 36, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
GUICtrlSetFont(-1, 18, 400, 0, "Arial Rounded MT Bold")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

 While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

         Case $gobutton
            _ReplaceStringInFile($sFilePath, $replace2)

        Case $exitbutton
            exit

    EndSwitch
WEnd
Global $replace2= "Second"



Global $sFilePath = 'C:\Users\Dlex\Dropbox\New folder\IPfolder\IP_List.txt'

Func replace()
_ReplaceStringInFile ( $sFilePath, $replace2,$data1,0)


Global $replace2= "Second"



Global $sFilePath = 'C:\Users\Dlex\Dropbox\New folder\IPfolder\IP_List.txt'

EndFunc

 

 

Edited by JLogan3o13

Share this post


Link to post
Share on other sites

#4 ·  Posted

Move these lines to the top of your script.

Global $replace2= "Second" 
Global $sFilePath = 'C:\Users\Dlex\Dropbox\New folder\IPfolder\IP_List.txt'

Because they're after the While loop, they'll never get processed. Also, don't REDECLARE them inside the function, you're doing it wrong, just declare them once.


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

#5 ·  Posted

@dascondor in the future, please use code tags when posting your code - keeps our collective eyes from bleeding while trying to read it. See here how to do it ;)


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

Share this post


Link to post
Share on other sites

#6 ·  Posted

Is there Anyway to tell "_ReplaceStringinFile" to not touch certain numbers that it might select?

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

Just now, dascondor said:

Is there Anyway to tell "_ReplaceStringinFile" to not touch certain numbers that it might select?

No, you'd have to create your own version of it that takes more parameters, or use a RegEx on the file instead that does what you're looking to do.

1 person likes this

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

#8 ·  Posted

Still some errors to clean up.

_ReplaceStringInFile() has at least 3 required parameters.

Case $gobutton
            _ReplaceStringInFile($sFilePath, $replace2)

I think you meant to call your Replace() function? Else I do not see anywhere in the script its actually being called/used?

When I was brand new to this, what I usually did was write a script that ran once until I got it working, then added the GUI after.

This may help you get where you need to be as well.

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