holmeswa09
MIS
I'm trying to grab the first 6 characters of the first line in a text file, but only if that line does NOT have a certain character in column 42. Below are the first couple of lines of text from that file. My script needs to skip line 1 in this case because it contains a minus in column 42 instead of a plus.
0333I610627Company Name 090312000186032-00000
7941I610627Company Name 090312000186032+00000
The following code works, except that it doesn't skip that invalid first line the way I want:
0333I610627Company Name 090312000186032-00000
7941I610627Company Name 090312000186032+00000
The following code works, except that it doesn't skip that invalid first line the way I want:
Code:
Option Explicit
Const ForReading = 1
Const ForWriting = 2 'set text file for writing
Const ForAppending = 8
Dim objFSO ' File System Object
Dim objFile, objFile1, objFile2
Dim ts ' output file object
Dim strReportFileName ' output file
Dim BegstrCharacters, EndstrCharacters, strCharacters
Dim strNextLine, BegstrLine, EndstrLine, EndstrLine2
Dim objShell, filesys, searchstring, strContents
strReportFileName = "c:\temp\report.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ts = objFSO.CreateTextFile(strReportFileName)
ts.Close
Set ts = objFSO.OpenTextFile(strReportFileName, ForWriting)
If objFSO.FileExists("f:\company\file.txt") Then
Set objFile = objFSO.OpenTextFile("f:\company\file.txt", ForReading)
End If
If NOT IsEmpty(objFile) then
BegstrCharacters = objFile.Read(6)
strNextLine = objFile.ReadLine
If Len(strNextLine) > 0 Then
BegstrLine = BegstrCharacters
End If
objFile.Close
Set ts = objFSO.OpenTextFile(strReportFileName, ForAppending)
ts.write "BegInv: " & BegstrLine & vbCrLf
ts.Close
End If
Set objShell = CreateObject("WScript.Shell")
objShell.Run "notepad " & strReportFileName