Advertisement

07.08.2008 at 01:44PM PDT, ID: 23548238
[x]
Attachment Details

Making sure FSO.Write finishes writing before moving on

Asked by jamesrbarnes in MS SQL DTS, MS SQL Server, Visual Basic Programming

Tags: Microsoft, SQL 2000

I am writing a DTS package that reads in a text file. If the file is larger than 60,000 lines it breaks it into files of 60,000 lines.

I am using the fso.line property to check when the read gets to 60,000 lines and then it creates a new file.  The problem is the last line doesn't write fully before the file is closed and the first line of the new file begins where the last one left off.  Is there a way to check to see if the write process is complete before closing the file and beginning a new one?

The code I am using is attached below.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
iLineCounter = 60000
 
	set filesys = CreateObject("Scripting.FileSystemObject")
	Set text = filesys.CreateTextFile(sFullFileName)
 
	set readfile = filesys.OpenTextFile(sReadFileName, 1, false)
	Do Until ReadFile.AtEndOfStream
		If readFile.Line > iLineCounter Then 
			text.Close
			iLineCounter = iLineCounter + 60000
			iFileIncrement = iFileIncrement + 1
			sFileName = "MMDB_COSMOS_" & sFileDate & "_" & sFileYesterday & "004450" & iFileIncrement & ".dat"
			sFullFileName = "\\unpiox51pn\ova_mbr_sql\MMDB\DBSW\PTEST\" & sFileName
			Set text = filesys.CreateTextFile(sFullFileName)
		End If
		contents = readfile.Read(665)
		text.Write contents
	Loop
	readfile.close
	text.close
[+][-]07.09.2008 at 04:06AM PDT, ID: 21962242

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 07:30AM PDT, ID: 21963984

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.09.2008 at 06:25PM PDT, ID: 21969737

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL DTS, MS SQL Server, Visual Basic Programming
Tags: Microsoft, SQL 2000
Sign Up Now!
Solution Provided By: acperkins
Participating Experts: 2
Solution Grade: B
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628