Problem with OpenTextFile Procedure in a VBScript

Hi All, I having a vbscript that looks in a particular directory(s), for a file that will change text within that/those files.  When I get to the code line below, I get an error:
Invalid procedure call or argument code: 80A0005 LINE:22 CHAR:3

Set objFile = objFSO.OpenTextFile(strFileName1, ForReading)

I used this very code by itself, simpliar code and it worked.  Any ideas would be appreciated.

thanks,
John.

'----------------------------------------------------------------------------------------
Const USER_PROFILE = &H28&

'START AT THE USER'S PROFILE
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(USER_PROFILE)
Set objFolderItem = objFolder.Self 

'THEN BEGIN AT THE USER'S APPDATA AND PMM ROOT DIRECTORY
Set objShell2 = CreateObject("Shell.Application")
Set objFolder2 = objShell.Namespace(objFolderItem.Path & "\appdata\local\Atlantic_Realty_Developme")
Set objFolderItem2 = objFolder2.Self 

'CHANGE PMM CONFIG FILE IN EACH DIRECTORY
Set colItems = objFolder2.Items
For Each objItem in colItems
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	strFileName1 = objFolderItem.Path & "\AppData\Local\PROGNAME\" & objItem.Name & "\3.0.0.0\user.config"
	strFileName2 = objFolderItem.Path & "\AppData\Local\PROGNAME\" & objItem.Name & "\1.0.0.0\user.config"
	
	IF objFSO.FileExists(strFileName1) Then
		'CHANGE TEXT IN CONFIG FILES		
		Set objFile = objFSO.OpenTextFile(strFileName1, ForReading)
		strText = objFile.ReadAll
		objFile.Close
		strNewText = Replace(strText, strOldText, strNewText)

		Set objFile = objFSO.OpenTextFile(strFileName1, ForWriting)
		objFile.WriteLine strNewText
		objFile.Close
	END IF
	
	IF objFSO.FileExists(strFileName2) Then
		'CHANGE TEXT IN CONFIG FILES
		Set objFile = objFSO.OpenTextFile(strFileName2, ForReading)
		strText = objFile.ReadAll
		objFile.Close
		strNewText = Replace(strText, strOldText, strNewText)

		Set objFile = objFSO.OpenTextFile(strFileName2, ForWriting)
		objFile.WriteLine strNewText
		objFile.Close
	END IF
Next

Open in new window

LVL 4
Thunder724Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
You need to declare the I/O constants you are using in your code.  Add a line like this near the top:

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thunder724Author Commented:
That worked perfectly. thank you very much.
If you could, can you explain how those constants work?
0
Bill PrewCommented:
Think of them just like variables, the difference is a constant can't have it's value changed after it is set.

It has the same effect as doing this:

ForReading = 1
ForWriting = 2
ForAppending = 8

Then in the code that follows you can use the constant name and it makes the code much more readable and understandable.  There are a number of constants like this that can be passed to methods of the filesystemobject.

Here's a couple of links for further info:

http://support.microsoft.com/kb/163009
http://msdn.microsoft.com/en-us/library/314cz14s%28v=vs.84%29.aspx

~bp
0
Thunder724Author Commented:
Thanks very much for the explaination
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.