Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TextStream object and overflow errors

Status
Not open for further replies.

petherin

Programmer
Dec 3, 2002
13
0
0
GB
I am using the FileSystemObject's TextStream object to create and write a file.

First I create the FileSystemObject and then check that some folders exist, creating them if not.

Code:
Set fso = CreateObject("Scripting.FileSystemObject")
   
If fso.FolderExists(App.Path & "\DATA") = False Then
   fso.CreateFolder App.Path & "\DATA"
End If
If fso.FolderExists(App.Path & "\DATA\" & m_Product) = False Then
   fso.CreateFolder App.Path & "\DATA\" & m_Product
End If

Then I loop through an array containing objects. Each object is converted into a PropertyBag. Then I give the contents of the PropertyBag to a Variant variable.

Code:
Set pb = Nothing
Set pb = New PropertyBag
pb.WriteProperty "Grid", cGridArray(i)
varTemp = pb.Contents

varTemp will now be an array of bytes. Then I write varTemp into a file:

Code:
The_DAT_File = App.Path & "\DATA\" & m_Product & ".DAT"
  
If fso.FileExists(The_DAT_File) Then
   fso.DeleteFile The_DAT_File, True
End If

Set fTextStream = fso.CreateTextFile(The_DAT_File, True)
sVarTemp = ""
For j = 0 To UBound(varTemp)
   sVarTemp = sVarTemp & Chr(varTemp(j))
Next
fTextStream.Write (sVarTemp)
fTextStream.Close
Set fTextStream = Nothing

At some point in here, an overflow error (Err.Number = 6)sometimes (not always) occurs. I've tried it with quite large files (170Kb), but really the files that are written are a lot smaller than that. I can't debug on the computer this is happening (it's in another country), and I can't replicate the error on my own machine.

I also recognise that the use of the PropertyBag may seem an unnecessary step, but it's old code I'm maintaining.

Can anyone see anything in this code that would cause an overflow error?

Thanks for anyone's help
Pete
 
I'd suspect the beginning of the FOR loop. How is j dimensioned and how large can the value of UBound(varTemp) be?
 
Yes, that's it. j was DIM'ed as an Integer and j was getting up to 35,000 and was overflowing. Changed to a Long and it's okay now.

Thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top