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.
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.
varTemp will now be an array of bytes. Then I write varTemp into a file:
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
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