How do I extend or pad out a binary file?
- From: FUBARinSFO <file1303@xxxxxxxxx>
- Date: Sun, 17 Feb 2008 00:56:37 -0800 (PST)
Hi:
I'm trying to create a binary file of arbitrary length by attempting
to position the .position property past the end of file, and then
writing the file to disk. My understanding was that ADO would pad out
the file with nulls and not object.
But here I'm using the below function in VBScript, and getting the
error under Windows Script Host (WSH 5.6) "Provider: the parameter is
incorrect" whenever I attempt to set the .position attribute past the
end of the file. The below code is stripped down from the actual code
for illustration, and the file is zero-length. When I try to set
the .position property at anything greater than zero, WSH objects. Is
this possibly some sort of security measure instituted in VBScript?
Thank you in advance for your help.
-- Roy Zider
Function SaveBinaryData(FileName, text)
Const adTypeBinary = 1
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
Const adModeReadWrite = 3
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
BinaryStream.Type = adTypeBinary
BinaryStream.Mode = adModeReadWrite
BinaryStream.Open
' get error "Provider: the parameter is incorrect"
' so can't position past end of file?
BinaryStream.Position = 0 ' error if more than 0.
BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
BinaryStream.Close
Set BinaryStream = Nothing
SaveBinaryData = "OK"
End Function
rc = SaveBinaryData("binfile.bin", "lsz")
MsgBox "rc: " & rc
.
- Prev by Date: Re: How to create editable recordset without using a database table?
- Next by Date: Command object and batching stored procedure calls
- Previous by thread: How to create editable recordset without using a database table?
- Next by thread: Command object and batching stored procedure calls
- Index(es):