Thank you for your reply. I passed the arguments by dragging and dropping file names on the VBScript icon.
I got the code to run properly late yesterday evening. Apparently the line that was causing the problem was: sTextadd = Trim(sTextadd & vbCrLf & arr(y)). sTextadd had not been assigned a value earlier in the program. I added the following line before the loop and if statements, and was almost home: sTextadd = arr (0). (I had to remove the "ST" and "&" from the line : objFile.Write "ST" & sTextadd, as well).
I was kind of surprised by what the actual problem was. It didn't seem correct that this adjustment would fix a problem related to multiple file arguments versus single file arguments. Apparently it effected the flow somehow, though I am so new to this that I can't say how.
The following is the code that I currently have that is working. I have cleanup to do on it yet, however:
Code:
Dim strFile, strFile2, strFile3, strFile4
Dim objFSO, objFile, arr, arr2, y
Dim sText, sTextadd, sText9, sText11, sTexty
Dim sTexty0, sTexty1, sTexty2, sTexty3, RsTexty1
Dim NewTextLine, NArray
Dim strFileBase, strFileExt, strTmpFile, strTmpFile2, strTmpFile3
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
On Error Resume Next
For Each strFile In WScript.Arguments
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFileBase = objFso.GetBaseName (strFile)
strFileExt = objFso.GetExtensionName (strFile)
strFile2 = objFso.GetParentFolderName(strFile)
strTmpFile = strFile2 & "\TmpStart.txt"
strTmpFile2 = strFile2 & "\TmpEnd.txt"
strTmpFile3 = strFile2 & "\Reversed.txt"
strFile3 = strFile2 & "\BACKUP"
CreateFullPath strFile3
CopyFile strFile, strFile3
strFile4 = strFile2 & "\CHANNELS"
CreateFullPath strFile4
If objFSO.FileExists (strTmpFile) Then objFSO.DeleteFile (strTmpFile)
If objFSO.FileExists (strTmpFile2) Then objFSO.DeleteFile (strTmpFile2)
If objFSO.FileExists (strTmpFile3) Then objFSO.DeleteFile (strTmpFile3)
Set objFile = objFSO.CreateTextFile (strTmpFile2,ForReading)'TmpEnd.txt
objFile.Close
Set objFile = objFSO.CreateTextFile (strTmpFile3,ForReading)'Reversed.txt
objFile.Close
Set objFile = objFSO.OpenTextFile (strFile, ForReading)'Original nc1 file
sText = objFile.ReadAll
objFile.Close
arr = Split(sText,vbCrLf)
sText9 = arr (8)
sText11 = arr (10)
sTextadd = arr (0)
If Instr(1, sText9,"C",vbTextCompare) Then 'IF#1
For y = 1 To UBound(arr)
sTextadd = Trim(sTextadd & vbCrLf & arr(y))
If Instr(1,(arr (y)),"BO",vbTextCompare) Then'IF#2
Do Until InStr (1, arr (y + 1), "EN", vbTextCompare)<> 0
sTexty = arr (y + 1)
sTexty = Trim (sTexty)
Do While InStr (1, sTexty, " ")
sTexty = Replace (sTexty, " ", " ")
Loop
arr2 = Split (sTexty," ",-1)
sTexty0 = arr2 (0)
sTexty1 = arr2 (1)
sTexty2 = arr2 (2)
sTexty3 = arr2 (3)
sTexty1 = Left (sTexty1, Len (sTexty1) - 1)
RsTexty1 = sText11 - sTexty1
NArray = Array (sTexty0, RsTexty1 & "o", sTexty2, sTexty3)
NewTextLine = Join (NArray, " ")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile (strTmpFile2,ForAppending)'TmpEnd.txt
objFile.Write NewTextLine & vbCrLf
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
y = y + 1
Loop
READUP
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile (strTmpFile,ForWriting)'TmpStart.txt
objFile.Write sTextadd
objFile.Close
Set objFile = Nothing
Set objFSO = Nothing
CombineFiles
End If''''''''#2
Next'For y = 1 To UBound(arr)
End If'If #1
Set y = Nothing
Set NewTextLine = Nothing
Set sText = Nothing
Set arr = Nothing
Set sTextadd = Nothing
Next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sub CreateFullPath (byval path)
dim parent
path = objfso.GetAbsolutePathname(path)
parent = objfso.GetParentFolderName(path)
if not objfso.FolderExists(parent) then
CreateFullPath parent
end if
if not objfso.FolderExists(path) then
objfso.CreateFolder(path)
end if
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub CopyFile(FileSpec, NewFolder)
On Error Resume Next
If Right(NewFolder,1) <> "\" Then NewFolder = NewFolder & "\"
CheckForFile = objFSO.FileExists(FileSpec)
CheckForFolder = objFSO.FolderExists(NewFolder)
If CheckForFolder = TRUE Then
If CheckForFile = TRUE Then
FileName = objFSO.GetFileName(FileSpec)
NewFileName = NewFolder & FileName
If objFSO.FileExists(NewFileName) = TRUE Then
ClearAttributes NewFileName
End If
End If
objFSO.CopyFile FileSpec, NewFolder, TRUE
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ClearAttributes(FileName)
On Error Resume Next
CheckforFile = objFSO.FileExists(FileName)
If CheckforFile = TRUE Then
Set objf = objFSO.GetFile(FileName)
'Clear hidden, system, or read-only attributes if necessary
If objf.attributes and 1 Then objf.attributes = objf.attributes - 1
If objf.attributes and 2 Then objf.attributes = objf.attributes - 2
If objf.attributes and 4 Then objf.attributes = objf.attributes - 4
Set objf = Nothing
End If
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub ReadUP
Dim arrFileLines()
ind = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strTmpFile2, ForReading)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(ind)
arrFileLines(ind) = objFile.ReadLine
ind = ind + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Set objFile2 = objFSO.OpenTextFile (strTmpFile3, ForAppending)'Reversed.txt
objFile2.Write arrFileLines (l) & vbCrLf
objFile2.Close
Next
Set objFile2 = objFSO.OpenTextFile (strTmpFile3,ForAppending)'Reversed.txt
objFile2.Write "EN"
objFile2.Close
Set objFile = Nothing
Set objFile2 = Nothing
Set objFSO = Nothing
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub CombineFiles
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile (strFile4 & "\" & strFileBase & "." & strFileExt)'New nc1 file
Set objTextFile = objFSO.OpenTextFile(strTmpFile, ForReading)'TmpStart.txt
strText = objTextFile.ReadAll
objTextFile.Close
objOutputFile.WriteLine strText
Set objTextFile = objFSO.OpenTextFile(strTmpFile3, ForReading)'Reversed.txt
strText = objTextFile.ReadAll
objTextFile.Close
objOutputFile.WriteLine strText
objOutputFile.Close
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
I had a response in another forum that stated that the following lines were "wrong":
Set y = Nothing
Set NewTextLine = Nothing
Set sText = Nothing
Set arr = Nothing
Set sTextadd = Nothing
I asked for a clarification, but have not gotten a response yet. I was under the impression that it was good practice to set variables to "Nothing" when done with them. Do you have any thoughts for me as a beginner in this regard? (One of the "cleanup" things that I was going to undertake was to make sure that all my variables were set back to "Nothing" when I was done with them. I don't know, now, wheter I should do that, or not.)
Thanks again for the reply !!