Hi everyone,
First off, I want to thank everyone again for sharing their knowledge. I truly appreciate your hard work and dedication.
I am trying to modify a .ini file that has some similar wording inside. What I have tried is to use the bracket header as my search criteria and then use mid to modify what I want it to do. What is happening is somehow the data I write to the file gets written, but then gets overwritten by other data later on in the script. Here's a copy of my script. I am sure there is a better way to modify all the variables, but this was the only way I could get it to "semi work" without erasing words within the .ini file.
------------------------
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShl = WScript.CreateObject("WScript.Shell")
strZero = ("000000")
strRange = ("First")
strPrefix = InputBox("Please enter the letter prefix:")
If strPrefix = "" Then
Wscript.Quit
Else
strPriBegin = InputBox("Please enter the first range beginning #'s:")
If strPriBegin = "" Then
WScript.Quit
Else
strPriMaxNum = InputBox("Please enter the maximum number for the first range:")
If strPriMaxNum = "" Then
WScript.Quit
Else
strSecBegin = InputBox("Please enter the second range beginning #'s:")
If strSecBegin = "" Then
WScript.Quit
Else
strSecMaxNum = InputBox("Please enter the maximum number of the second range:")
If strSecMaxNum = "" Then
WScript.Quit
Else
End If
End If
End If
End If
End If
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strPre = Mid(strCFG, InStr(strCFG, "[LastName]") + 17, 1)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent1 = replace(strCFG, strPre, strPrefix)
objFile.WriteLine strContent1
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strPriBeg = Mid(strCFG, InStr(strCFG, "[BeginningNumbers]") + 28, 6)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent2 = replace(strCFG, strPriBeg, strPriBegin)
objFile.WriteLine strContent2
objFile.Close
WScript.Sleep (200)
'
Set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strPriUsed = Mid(strCFG, InStr(strCFG, "[EndingNumbers1]") + 34, 6)
objFile.Close
Set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent3 = replace(strCFG, strPriUsed, strZero)
objFile.WriteLine strContent3
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strPriMax = Mid(strCFG, InStr(strCFG, "[MaxBeginning1]") + 24, 3)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent4 = replace(strCFG, strPriMax, strPriMaxNum)
objFile.WriteLine strContent4
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strSecBeg = Mid(strCFG, InStr(strCFG, "[BeginningNumbers2]") + 27, 6)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent5 = replace(strCFG, strSecBeg, strSecBegin)
objFile.WriteLine strContent5
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strSecMax = Mid(strCFG, InStr(strCFG, "[MaxSecondary2]") + 26, 3)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent6 = replace(strCFG, strSecMax, strSecMaxNum)
objFile.WriteLine strContent6
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strSecUsed = Mid(strCFG, InStr(strCFG, "[SecondaryLastNum]") + 36, 6)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent7 = replace(strCFG, strSecUsed, strZero)
objFile.WriteLine strContent7
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strRangeInUse = Mid(strCFG, InStr(strCFG, "[InUse]") + 25, 8)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent8 = replace(strCFG, strRangeInUse, strRange)
objFile.WriteLine strContent8
objFile.Close
WScript.Sleep (200)
---------------------------------
Again, I know it is probably not written the best as far as the looks of it. Would someone be able to tell me why for instance, the beginning numbers get overwritten by my strZero variable? If I do it piece by piece, it works great. Inside the file looks something like this:
[BeginningNumbers]
Begin=123456
I am trying to include the bracketed text in my search and then count out the spaces to the 6 digit number. I cannot just use "Begin" because our secondary numbers look like this:
[BeginningNumbers2]
Begin=67890
So if I just search for "Begin" then I change both sets of numbers under different bracket headings.
Any help or different ideas on how to change the data is greatly appreciated. Thank you all for your time.
Pellet
First off, I want to thank everyone again for sharing their knowledge. I truly appreciate your hard work and dedication.
I am trying to modify a .ini file that has some similar wording inside. What I have tried is to use the bracket header as my search criteria and then use mid to modify what I want it to do. What is happening is somehow the data I write to the file gets written, but then gets overwritten by other data later on in the script. Here's a copy of my script. I am sure there is a better way to modify all the variables, but this was the only way I could get it to "semi work" without erasing words within the .ini file.
------------------------
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShl = WScript.CreateObject("WScript.Shell")
strZero = ("000000")
strRange = ("First")
strPrefix = InputBox("Please enter the letter prefix:")
If strPrefix = "" Then
Wscript.Quit
Else
strPriBegin = InputBox("Please enter the first range beginning #'s:")
If strPriBegin = "" Then
WScript.Quit
Else
strPriMaxNum = InputBox("Please enter the maximum number for the first range:")
If strPriMaxNum = "" Then
WScript.Quit
Else
strSecBegin = InputBox("Please enter the second range beginning #'s:")
If strSecBegin = "" Then
WScript.Quit
Else
strSecMaxNum = InputBox("Please enter the maximum number of the second range:")
If strSecMaxNum = "" Then
WScript.Quit
Else
End If
End If
End If
End If
End If
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strPre = Mid(strCFG, InStr(strCFG, "[LastName]") + 17, 1)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent1 = replace(strCFG, strPre, strPrefix)
objFile.WriteLine strContent1
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strPriBeg = Mid(strCFG, InStr(strCFG, "[BeginningNumbers]") + 28, 6)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent2 = replace(strCFG, strPriBeg, strPriBegin)
objFile.WriteLine strContent2
objFile.Close
WScript.Sleep (200)
'
Set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strPriUsed = Mid(strCFG, InStr(strCFG, "[EndingNumbers1]") + 34, 6)
objFile.Close
Set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent3 = replace(strCFG, strPriUsed, strZero)
objFile.WriteLine strContent3
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strPriMax = Mid(strCFG, InStr(strCFG, "[MaxBeginning1]") + 24, 3)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent4 = replace(strCFG, strPriMax, strPriMaxNum)
objFile.WriteLine strContent4
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strSecBeg = Mid(strCFG, InStr(strCFG, "[BeginningNumbers2]") + 27, 6)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent5 = replace(strCFG, strSecBeg, strSecBegin)
objFile.WriteLine strContent5
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strSecMax = Mid(strCFG, InStr(strCFG, "[MaxSecondary2]") + 26, 3)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent6 = replace(strCFG, strSecMax, strSecMaxNum)
objFile.WriteLine strContent6
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strSecUsed = Mid(strCFG, InStr(strCFG, "[SecondaryLastNum]") + 36, 6)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent7 = replace(strCFG, strSecUsed, strZero)
objFile.WriteLine strContent7
objFile.Close
WScript.Sleep (200)
'
set objFile = objFSO.OpenTextFile ("C:\CustomerNumbers.ini", ForReading)
strCFG = objFile.ReadAll
strRangeInUse = Mid(strCFG, InStr(strCFG, "[InUse]") + 25, 8)
objFile.Close
set objFile = objFSO.OpenTextFile("C:\CustomerNumbers.ini", ForWriting, true)
strContent8 = replace(strCFG, strRangeInUse, strRange)
objFile.WriteLine strContent8
objFile.Close
WScript.Sleep (200)
---------------------------------
Again, I know it is probably not written the best as far as the looks of it. Would someone be able to tell me why for instance, the beginning numbers get overwritten by my strZero variable? If I do it piece by piece, it works great. Inside the file looks something like this:
[BeginningNumbers]
Begin=123456
I am trying to include the bracketed text in my search and then count out the spaces to the 6 digit number. I cannot just use "Begin" because our secondary numbers look like this:
[BeginningNumbers2]
Begin=67890
So if I just search for "Begin" then I change both sets of numbers under different bracket headings.
Any help or different ideas on how to change the data is greatly appreciated. Thank you all for your time.
Pellet