Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Skipping 2 lines in txt file!! HELP :)

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,61340
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Skipping 2 lines in txt file!! HELP :)
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Skipping 2 lines in txt file!! HELP :) - 6/13/2008 1:28:22 AM   
  rizakaya

 

Posts: 6
Score: 0
Joined: 6/13/2008
From: UK
Status: offline
Hi all,

I need help !!, below is the script to read from a text file and convert to a readable format. The txt file verifies converted actual number of records against verifying number on the actual txt file. This worked fine until  the new text file verifying number moved 2 lines down the text file.
I need to point the code " intFileRecords = CLng(Mid(strRecord, 55, 6)) " to 2 lines below.

Please can someone help and make the new code " intFileRecords = CLng(Mid(strRecord, 15, 6)) " but reading from the 2 lines down or if it helps the verifying number is all always going to be at the end of the text file. So either will help. End of the text file or skipping 2 lines.

Thank you in Advance.



'
' Check that all records in the file were read by comparing the no of records read to the number
' of records the file says it contains.
'

  
intFileRecords = CLng(Mid(strRecord, 55, 6))

If(intNoOfRecords <> intFileRecords) Then
 strErrNoOfRec = "Process Cancelled." & vbLF & vbLF & "The number of records copied from file '" & fsoRead.GetFileName(args(i)) & "' is " & intNoOfRecords & _
       ","  & vbLF & "but the number of records the file says it contains is " & intFileRecords & ". Please investigate."
 shellError.Popup strErrNoOfRec, 0, "Error in quantity of records!", 0 & 48
 Wscript.Quit()
End If
'
' Note the file successfully processed and increment the counters
'
strCopiedFiles = strCopiedFiles & strFileName & "  -  " & intNoOfRecords & vbLf
intTotNoOfRecords = intTotNoOfRecords + intNoOfRecords
intTotNoOfFiles = intTotNoOfFiles + 1
Next
'
' Copy the Temp file to the New files.
'
Set objTempFile = fsoWrite.GetFile(strTempFile)
objTempFile.Copy strNewFile, true
objTempFile.Copy "C:\FPAY Daily MailboxData.txt", true
'
' Inform the user of the files and records processed
'
strCopiedFilesMsg = "The following " & intTotNoOfFiles & " files were converted and copied to the files " & vbLf & _
     "'FPAY Daily MailboxData.txt' and 'FPAY\FPAY CAF,KKL Removed\" & fsoWrite.GetFileName(strNewFile) & "'.                   " & vbLf & vbLf & _
     "No of records in each file: " & vbLF & vbLF & strCopiedFiles & vbLF & _
     "Total No of Records:  " & intTotNoOfRecords
Msgbox strCopiedFilesMsg,,"Files Converted"
 
 
Post #: 1
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/13/2008 1:37:26 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi rizakaya,

the TextStream object provides a .SkipLine method. So if you have something like:


Set oTS = oF.OpenTextFile( ... )
....
    strRecord = oTS.ReadLine

then

Set oTS = oF.OpenTextFile( ... )
  ....
    oTS.SkipLine
    oTS.SkipLine
     strRecord = oTS.ReadLine

may work for you.

Good luck!

ehvbs

(in reply to rizakaya)
 
 
Post #: 2
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/13/2008 1:58:54 AM   
  rizakaya

 

Posts: 6
Score: 0
Joined: 6/13/2008
From: UK
Status: offline
Thanks for your rapid response ehvbs,

But that doesnt't work for me. If it helps I can post all of the script?

(in reply to ehvbs)
 
 
Post #: 3
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/13/2008 2:03:11 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi rizakaya,

yes, show your code!

Thanks

ehvbs

(in reply to rizakaya)
 
 
Post #: 4
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/15/2008 8:52:30 PM   
  rizakaya

 

Posts: 6
Score: 0
Joined: 6/13/2008
From: UK
Status: offline
Hi,
Below id the full code listing.

Thanks.




'************************************************************************************************************************************************************

'
'  Date: 20 March 2008
'
'------------------------------------------------------------------------------------------------------------------------------------------------------------

Option Explicit
Const strWriteFilePath = "C:\FPAY\FPAY CAF,KKL Removed\"
const intFirstRecord = 5 ' Line Number of the first record
Dim args  ' The collection of files dropped onto the program
Dim i   ' Counter to loop through the files
Dim result  ' Holds the users input from a Messagebox
Dim fsoRead   ' Object for reading
Dim fsoWrite   ' Object for writing
Dim readStrm   ' Text stream for reading from the file Mailbox files
Dim writeStrm  ' Text stream for writing to the temp file
Dim strFileName  ' Name of the Mailbox File being read
Dim strTempFile  ' Name of the Temp file being written to
Dim strNewFile  ' Name that the Temp file is changed to
Dim objTempFile  ' An instance of the Temporary file object
Dim strRecord  ' The record as read from the original file
Dim intNoOfRecords ' The no of records read from the Mailbox file
Dim intFileRecords ' The no of records in the Mailbox file according to the files report
Dim intTotNoOfRecords ' The total no of records in all files combined
Dim intTotNoOfFiles ' The total no of files converted
Dim strAmendedRecord ' The converted record ready to be written to the new file
Dim shellError  ' The shell used to display errors
Dim strErrNoArgs ' The No arguments error message
Dim strErrFileName ' The Incorrect file name message
Dim strErrNoOfRec ' Incorrect no of records message
Dim strErrDataType ' Incorrect data type for amount
Dim strCopiedFiles ' List of copied files
Dim strCopiedFilesMsg ' The message that is created to inform the user of the files copied
Dim straaa, strbbb, dblAmount, strName, strRef, strDate   

Set shellError = Wscript.CreateObject("Wscript.Shell")  ' Instantiate error object
Set args = fSortArray(Wscript.Arguments)
'
' Quit if user doesn't provide any files to process
'
If args.Count < 1 Then
strErrNoArgs = "Ctrl + click on the days files then drag and drop them onto this programs icon." & vbLF & _
        "All of the files will be concatenated into a file and the data will be converted into comma separated values for CAF,KKL,etc..Extraction."
shellError.Popup strErrNoArgs, 0, "No files to process!", 0 & 48
Wscript.Quit()
End If
Set fsoRead = Wscript.CreateObject("Scripting.FileSystemObject")
Set fsoWrite = Wscript.CreateObject("Scripting.FileSystemObject")
strTempFile = strWriteFilePath & "TMPFile.txt"
'
' Check that the new file does not exist. If it does, ask the user if they want to overwrite it. Otherwise cancel the operation.
'
strNewFile = strWriteFilePath & Left(fsoRead.GetFileName(args(0)), 6) & " FPAY MailboxDailyData.txt"
If fsoWrite.FileExists(strNewFile) Then
result = Msgbox("File 'FPAY\FPAY CAF,KKL Removed\" & fsoWrite.GetFileName(strNewFile) & "' already exists. " & _
  "Do you want " & vbLF & "to overwrite the existing file?", vbOK, "File already exists!")
 
If (result = vbOK) Then
 Set writeStrm = fsoWrite.CreateTextFile(strTempFile, True)
Else
 Wscript.Quit()
End If
Else
Set writeStrm = fsoWrite.CreateTextFile(strTempFile, True)
End If
intTotNoOfRecords = 0  ' Initialise the Total No of Records counter
intTotNoOfFiles = 0  ' Initialise the Total No of Files counter
writeStrm.WriteLine("Saa,Bbb,Amount,Name,Ref,Date")  ' Write titles to first row in file
'
' For each file that is parsed to the script...
'
For i = 0 to args.Count - 1

'
' Open the file for reading
'
Set readStrm = fsoRead.openTextFile(args(i), 1, False)
strFileName = fsoRead.GetFileName(args(i))
If (Not IsNumeric(Left(strFileName, 6))) Then
 strErrFileName = "Process cancelled." & vbLF & vbLF & "Could not create a date from the file name '" & strFileName & "'. Please make sure all the mailbox file names " & vbLF & _
    "start with a reverse Gregorian date (eg. 070925 Mailbox.txt)."
 shellError.Popup strErrFileName, 0, "Date not in title!", 0 & 48
 Wscript.Quit()
Else
 strDate = Mid(strFileName, 5, 2) & "/" & Mid(strFileName, 3, 2) & "/" & (2000 + Cint(Left(strFileName, 2)))
End If

'
' Skip through the irrelevant lines of metadata to get to the first record.
'
Do Until (readStrm.Line = intFirstRecord)
 readStrm.SkipLine()
Loop
intNoOfRecords = 0   ' Initialise record counter.
 
strRecord = readStrm.ReadLine()  ' Read the first record.
'
' Do the following to each record until the EOF trigger is reached.
'

Do Until (Left(strRecord, 3) = "EOF")
'
' Create concatenated string of data with commas then write it to the new file.
'
 intNoOfRecords = intNoOfRecords + 1
 straaa = Mid(strRecord, 18, 6)
 strbbb = Mid(strRecord, 24, 8)
 
 If(IsNumeric(Mid(strRecord, 36, 11))) Then
  dblAmount = Mid(strRecord, 36, 11)/100
 Else
  strErrDataType = "Process cancelled. " & vbLF & vbLF & "The following file has data in the amount field which is not of a numeric type." & vbLF & vbLF & _
     "File: " & strFileName & vbLF & _
     "Record No: " & intNoOfRecords & vbLF & _
     "Amount = '" & Mid(strRecord, 36, 11) & "'"
  shellError.Popup strErrDataType, 0, "Incorrect Data Type!", 0 & 48
  Wscript.Quit()
 End If
 strName = Trim(Mid(strRecord, 47, 18))
 strRef = Trim(Mid(strRecord, 65, 18))
 
 strAmendedRecord = straaa & "," & strbbb & "," & dblAmount & "," & _
      strName & "," & strRef & "," & strDate
 writeStrm.WriteLine(strAmendedRecord) ' Write the result to the temp file.
 
 strRecord = readStrm.ReadLine()  ' Read the next record.
 
 
Loop



readStrm.Close()
'
' Check that all records in the file were read by comparing the no of records read to the number
' of records the file says it contains.
'
Set oTS = oF.readStrm(strFileName)
    strRecord = oTS.ReadLine

Set oTS = oF.readStrm(strFileName)

    oTS.SkipLine
    oTS.SkipLine
     strRecord = oTS.ReadLine

  
intFileRecords = CLng(Mid(strRecord, 55, 6))

If(intNoOfRecords <> intFileRecords) Then
 strErrNoOfRec = "Process Cancelled." & vbLF & vbLF & "The number of records copied from file '" & fsoRead.GetFileName(args(i)) & "' is " & intNoOfRecords & _
       ","  & vbLF & "but the number of records the file says it contains is " & intFileRecords & ". Please investigate."
 shellError.Popup strErrNoOfRec, 0, "Error in quantity of records!", 0 & 48
 Wscript.Quit()
End If
'
' Note the file successfully processed and increment the counters
'
strCopiedFiles = strCopiedFiles & strFileName & "  -  " & intNoOfRecords & vbLf
intTotNoOfRecords = intTotNoOfRecords + intNoOfRecords
intTotNoOfFiles = intTotNoOfFiles + 1
Next
'
' Copy the Temp file to the New files.
'
Set objTempFile = fsoWrite.GetFile(strTempFile)
objTempFile.Copy strNewFile, true
objTempFile.Copy "C:\FPAY Daily MailboxData.txt", true
'
' Inform the user of the files and records processed
'
strCopiedFilesMsg = "The following " & intTotNoOfFiles & " files were converted and copied to the files " & vbLf & _
     "'FPAY Daily MailboxData.txt' and 'FPAY\FPAY CAF,KKL Removed\" & fsoWrite.GetFileName(strNewFile) & "'.                   " & vbLf & vbLf & _
     "No of records in each file: " & vbLF & vbLF & strCopiedFiles & vbLF & _
     "Total No of Records:  " & intTotNoOfRecords
Msgbox strCopiedFilesMsg,,"Files Converted"

'**********************************************************************************************************************************************************************************************

'  Function: fSortArray(aSortThisArray)
'  Arguments: One array containing the files to be processed
'  Return: One array containing the sorted files to be processed
'
'  Desc: This function is parsed an array containing the files to be processed. It then sorts the array of files
'  and returns the sorted array back to the calling program.
'---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Function fSortArray(aSortThisArray)
Dim oArrayList, iElement, oArrayDic
Set oArrayDic = CreateObject("Scripting.Dictionary")
Set oArrayList = CreateObject("System.Collections.ArrayList")
For iElement = 0 To aSortThisArray.Length - 1
 
 oArrayList.Add aSortThisArray(iElement)
Next
oArrayList.Sort
Set fSortArray = oArrayList
End Function

'**********************************************************************************************************************************************************************************************

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/15/2008 9:00:08 PM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi rizakaya,

Shouldn't intFirstRecord be changed in

Do Until (readStrm.Line = intFirstRecord)
 readStrm.SkipLine()
Loop

Regards

ehvbs

(in reply to rizakaya)
 
 
Post #: 6
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/15/2008 9:03:34 PM   
  rizakaya

 

Posts: 6
Score: 0
Joined: 6/13/2008
From: UK
Status: offline
Hi,

No because i need to skip the first 5 lines of the text file and read from there on..


Regards

(in reply to ehvbs)
 
 
Post #: 7
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/15/2008 9:09:03 PM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi rizakaya,

Ok, I see your point (and my error: readStrm.Line should increase
until it reaches intFirstRecord; it is not used as a counter).

But then you should specify in more detail what "doesn't work".

Regards

ehvbs

(in reply to rizakaya)
 
 
Post #: 8
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/15/2008 9:41:46 PM   
  rizakaya

 

Posts: 6
Score: 0
Joined: 6/13/2008
From: UK
Status: offline
Sorry I have posted the script with some tried solutions which did not work so below is the correct script pasted.

Hi,

The program needs to skip the first 5 lines and read the text after and conver to a comma delimited file. This works fine. The script also works fine when copying to a TEMP file but fails to leave a second copy in desired location because of the validation here:

intFileRecords = CLng(Mid(strRecord, 55, 6))

If(intNoOfRecords <> intFileRecords) Then
 strErrNoOfRec = "Process Cancelled." & vbLF & vbLF & "The number of records copied from file '" & fsoRead.GetFileName(args(i)) & "' is " & intNoOfRecords & _
       ","  & vbLF & "but the number of records the file says it contains is " & intFileRecords & ". Please investigate."
 shellError.Popup strErrNoOfRec, 0, "Error in quantity of records!", 0 & 48
 Wscript.Quit()
End If

 
What i would like the script to do is same validation but on the text 2 below.





Option Explicit
Const strWriteFilePath = "C:\FPAY\FPAY CAF,KKL Removed\"
const intFirstRecord = 5 ' Line Number of the first record
Dim args  ' The collection of files dropped onto the program
Dim i   ' Counter to loop through the files
Dim result  ' Holds the users input from a Messagebox
Dim fsoRead   ' Object for reading
Dim fsoWrite   ' Object for writing
Dim readStrm   ' Text stream for reading from the file Mailbox files
Dim writeStrm  ' Text stream for writing to the temp file
Dim strFileName  ' Name of the Mailbox File being read
Dim strTempFile  ' Name of the Temp file being written to
Dim strNewFile  ' Name that the Temp file is changed to
Dim objTempFile  ' An instance of the Temporary file object
Dim strRecord  ' The record as read from the original file
Dim intNoOfRecords ' The no of records read from the Mailbox file
Dim intFileRecords ' The no of records in the Mailbox file according to the files report
Dim intTotNoOfRecords ' The total no of records in all files combined
Dim intTotNoOfFiles ' The total no of files converted
Dim strAmendedRecord ' The converted record ready to be written to the new file
Dim shellError  ' The shell used to display errors
Dim strErrNoArgs ' The No arguments error message
Dim strErrFileName ' The Incorrect file name message
Dim strErrNoOfRec ' Incorrect no of records message
Dim strErrDataType ' Incorrect data type for amount
Dim strCopiedFiles ' List of copied files
Dim strCopiedFilesMsg ' The message that is created to inform the user of the files copied
Dim straaa, strbbb, dblAmount, strName, strRef, strDate   

Set shellError = Wscript.CreateObject("Wscript.Shell")  ' Instantiate error object
Set args = fSortArray(Wscript.Arguments)
'
' Quit if user doesn't provide any files to process
'
If args.Count < 1 Then
strErrNoArgs = "Ctrl + click on the days files then drag and drop them onto this programs icon." & vbLF & _
       "All of the files will be concatenated into a file and the data will be converted into comma separated values for CAF,KKL,etc..Extraction."
shellError.Popup strErrNoArgs, 0, "No files to process!", 0 & 48
Wscript.Quit()
End If
Set fsoRead = Wscript.CreateObject("Scripting.FileSystemObject")
Set fsoWrite = Wscript.CreateObject("Scripting.FileSystemObject")
strTempFile = strWriteFilePath & "TMPFile.txt"
'
' Check that the new file does not exist. If it does, ask the user if they want to overwrite it. Otherwise cancel the operation.
'
strNewFile = strWriteFilePath & Left(fsoRead.GetFileName(args(0)), 6) & " FPAY MailboxDailyData.txt"
If fsoWrite.FileExists(strNewFile) Then
result = Msgbox("File 'FPAY\FPAY CAF,KKL Removed\" & fsoWrite.GetFileName(strNewFile) & "' already exists. " & _
 "Do you want " & vbLF & "to overwrite the existing file?", vbOK, "File already exists!")

If (result = vbOK) Then
Set writeStrm = fsoWrite.CreateTextFile(strTempFile, True)
Else
Wscript.Quit()
End If
Else
Set writeStrm = fsoWrite.CreateTextFile(strTempFile, True)
End If
intTotNoOfRecords = 0  ' Initialise the Total No of Records counter
intTotNoOfFiles = 0  ' Initialise the Total No of Files counter
writeStrm.WriteLine("Saa,Bbb,Amount,Name,Ref,Date")  ' Write titles to first row in file
'
' For each file that is parsed to the script...
'
For i = 0 to args.Count - 1

'
' Open the file for reading
'
Set readStrm = fsoRead.openTextFile(args(i), 1, False)
strFileName = fsoRead.GetFileName(args(i))
If (Not IsNumeric(Left(strFileName, 6))) Then
strErrFileName = "Process cancelled." & vbLF & vbLF & "Could not create a date from the file name '" & strFileName & "'. Please make sure all the mailbox file names " & vbLF & _
   "start with a reverse Gregorian date (eg. 070925 Mailbox.txt)."
shellError.Popup strErrFileName, 0, "Date not in title!", 0 & 48
Wscript.Quit()
Else
strDate = Mid(strFileName, 5, 2) & "/" & Mid(strFileName, 3, 2) & "/" & (2000 + Cint(Left(strFileName, 2)))
End If

'
' Skip through the irrelevant lines of metadata to get to the first record.
'
Do Until (readStrm.Line = intFirstRecord)
readStrm.SkipLine()
Loop
intNoOfRecords = 0   ' Initialise record counter.

strRecord = readStrm.ReadLine()  ' Read the first record.
'
' Do the following to each record until the EOF trigger is reached.
'

Do Until (Left(strRecord, 3) = "EOF")
'
' Create concatenated string of data with commas then write it to the new file.
'
intNoOfRecords = intNoOfRecords + 1
straaa = Mid(strRecord, 18, 6)
strbbb = Mid(strRecord, 24, 8)

If(IsNumeric(Mid(strRecord, 36, 11))) Then
 dblAmount = Mid(strRecord, 36, 11)/100
Else
 strErrDataType = "Process cancelled. " & vbLF & vbLF & "The following file has data in the amount field which is not of a numeric type." & vbLF & vbLF & _
    "File: " & strFileName & vbLF & _
    "Record No: " & intNoOfRecords & vbLF & _
    "Amount = '" & Mid(strRecord, 36, 11) & "'"
 shellError.Popup strErrDataType, 0, "Incorrect Data Type!", 0 & 48
 Wscript.Quit()
End If
strName = Trim(Mid(strRecord, 47, 18))
strRef = Trim(Mid(strRecord, 65, 18))

strAmendedRecord = straaa & "," & strbbb & "," & dblAmount & "," & _
     strName & "," & strRef & "," & strDate
writeStrm.WriteLine(strAmendedRecord) ' Write the result to the temp file.

strRecord = readStrm.ReadLine()  ' Read the next record.


Loop



readStrm.Close()
'
' Check that all records in the file were read by comparing the no of records read to the number
' of records the file says it contains.

 
intFileRecords = CLng(Mid(strRecord, 55, 6))

If(intNoOfRecords <> intFileRecords) Then
strErrNoOfRec = "Process Cancelled." & vbLF & vbLF & "The number of records copied from file '" & fsoRead.GetFileName(args(i)) & "' is " & intNoOfRecords & _
      ","  & vbLF & "but the number of records the file says it contains is " & intFileRecords & ". Please investigate."
shellError.Popup strErrNoOfRec, 0, "Error in quantity of records!", 0 & 48
Wscript.Quit()
End If
'
' Note the file successfully processed and increment the counters
'
strCopiedFiles = strCopiedFiles & strFileName & "  -  " & intNoOfRecords & vbLf
intTotNoOfRecords = intTotNoOfRecords + intNoOfRecords
intTotNoOfFiles = intTotNoOfFiles + 1
Next
'
' Copy the Temp file to the New files.
'
Set objTempFile = fsoWrite.GetFile(strTempFile)
objTempFile.Copy strNewFile, true
objTempFile.Copy "C:\FPAY Daily MailboxData.txt", true
'
' Inform the user of the files and records processed
'
strCopiedFilesMsg = "The following " & intTotNoOfFiles & " files were converted and copied to the files " & vbLf & _
    "'FPAY Daily MailboxData.txt' and 'FPAY\FPAY CAF,KKL Removed\" & fsoWrite.GetFileName(strNewFile) & "'.                   " & vbLf & vbLf & _
    "No of records in each file: " & vbLF & vbLF & strCopiedFiles & vbLF & _
    "Total No of Records:  " & intTotNoOfRecords
Msgbox strCopiedFilesMsg,,"Files Converted"

'**********************************************************************************************************************************************************************************************

'  Function: fSortArray(aSortThisArray)
'  Arguments: One array containing the files to be processed
'  Return: One array containing the sorted files to be processed
'
'  Desc: This function is parsed an array containing the files to be processed. It then sorts the array of files
'  and returns the sorted array back to the calling program.
'---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Function fSortArray(aSortThisArray)
Dim oArrayList, iElement, oArrayDic
Set oArrayDic = CreateObject("Scripting.Dictionary")
Set oArrayList = CreateObject("System.Collections.ArrayList")
For iElement = 0 To aSortThisArray.Length - 1

oArrayList.Add aSortThisArray(iElement)
Next
oArrayList.Sort
Set fSortArray = oArrayList
End Function

'**********************************************************************************************************************************************************************************************

(in reply to ehvbs)
 
 
Post #: 9
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/16/2008 4:34:40 AM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi rizakaya,

I still don't get your problem(s). So all I can do is speculating.

(1) you write to your TEMP file (?) using

     writeStrm.WriteLine(strAmendedRecord) ' Write the result to the temp file.

    Do you close it before you try to copy it twice (?) using

     Set objTempFile = fsoWrite.GetFile(strTempFile)
     objTempFile.Copy strNewFile, true
     objTempFile.Copy "C:\FPAY Daily MailboxData.txt", true

   Do you get any error messages regarding this copy action?

(2) you validation

       ntFileRecords = CLng(Mid(strRecord, 55, 6))
       If(intNoOfRecords <> intFileRecords) Then

     depends on strRecord. AFAICanSee  it will hold "EOF ....". Is that
    your intention? If not, try to identify and save the line containing the
     NoOfRecs in your loop.

Sorry about being of not much help.

ehvbs

(in reply to rizakaya)
 
 
Post #: 10
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/16/2008 8:22:19 PM   
  rizakaya

 

Posts: 6
Score: 0
Joined: 6/13/2008
From: UK
Status: offline
Hi ehvbs,

No, you have been helpful enough thanks,


Right nearly there ( I think) :)
I am new to VBS so thanks for your patients

Answers to your questions above

(1)

It copies fine to the 2 location and closes after that, its the third copy I need which has the date in front of it.

I get the following error message when the original text file is dragged into the script.

" Process Cancelled.

The number of records copied from file '080616 FPAY MAilbox.txt' is 140,
but the number of records the file says is 0. Please investigate "


(2)
Yes it holds 'EOF', which indicates the end of file. But there are 2 EOF's on the file. But I want the 'intFileRecords' to contain the line I require which is at the botton of the original text file and always starts with 'UTL..'. The location within the line I require is column 39 and the 6 numbers.

Hope this might help.


Many thanks

Riza Kaya

(in reply to ehvbs)
 
 
Post #: 11
 
 RE: Skipping 2 lines in txt file!! HELP :) - 6/16/2008 8:43:17 PM   
  ehvbs

 

Posts: 2078
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi rizakaya,

from the error message we know

  If (intNoOfRecords <> intFileRecords) Then

is true because ntFileRecords is 0. So 

  ntFileRecords = CLng(Mid(strRecord, 55, 6))

is wrong. Either because "column 39 and the 6 numbers" is correct and 55 is
bad or because strRecord doesn't hold the line you are thinking of.

In general, you should put some diagnostic MsgBox .... or WScript.Echo ... in your
code.

Regards

ehvbs

(in reply to rizakaya)
 
 
Post #: 12
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Skipping 2 lines in txt file!! HELP :) Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts