Hello, what I am trying to do is increment a value in a text file. Basically the text file contains numerous values like,
album1
album1
album1
album2
album2
album2
What I'm trying to do is increment the 2 to a 3, and the 1 to a 2. ie:
album2
album2
album2
album3
album3
album3
I've created a script that searches for album(x) and increments each instance, but my problem is when it reaches album9 it changes it to album20. If I run it again it'll change album20 to album30. I'm lost as to what the problem is and I'm hoping someone will spot the problem.
Here is the script:
album1
album1
album1
album2
album2
album2
What I'm trying to do is increment the 2 to a 3, and the 1 to a 2. ie:
album2
album2
album2
album3
album3
album3
I've created a script that searches for album(x) and increments each instance, but my problem is when it reaches album9 it changes it to album20. If I run it again it'll change album20 to album30. I'm lost as to what the problem is and I'm hoping someone will spot the problem.
Here is the script:
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
Dim i
i = 10
On Error Resume Next
Do
'Opens the file for reading and copies the contents to a string, then closes the file
Set objFile = objFSO.OpenTextFile("C:\test.txt" , ForReading)
strContents = objFile.ReadAll
objFile.Close
'replaces album(x-1) with album(x)
strNewContents = Replace(strContents, "album" & (i - 1) , "album" & i )
i = (i - 1)
'opens the file for editing, pastes in the contents of the string and closes the file
Set objFile = objFSO.OpenTextFile("C:\test.txt" , ForWriting)
objFile.WriteLine strNewContents
objFile.Close
Loop Until i = 0