Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 T-SQL: How to save a null character to a file

Author  Topic 

dee-u
Starting Member

14 Posts

Posted - 2009-08-27 : 03:24:23
I have this VB6 code for compressing file which I want to convert into an SP, I have a problem with writing a null character to the zip file, can anyone help me out?

This is the line in the VB6 code which I am unable to convert. From what I understand String$(18, 0) should be Replicate(Char(0),18) but it is not outputting a valid zip file, only the first 4 characters are being written and not the null character, why is this?
strZIPHeader = Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String$(18, 0)


And here is my attempt. Everything should be fine but I am unable to save a null character to the file.
DECLARE @object int
DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
DECLARE @return int
DECLARE @property int

EXEC @hr = sp_OACreate 'Scripting.FileSystemObject', @object OUT
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
PRINT @src
RETURN
END



EXEC @hr = sp_OAMethod @object, 'CreateTextFile', @property OUT, 'C:\PIS\Test.zip'
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
print @src
print @desc
RETURN
END

DECLARE @xx nchar(22)
SET @xx = CHAR(80) + CHAR(75) + CHAR(5) + CHAR(6) + REPLICATE(CHAR(0),18)

PRINT len(@xx)

EXEC @hr = sp_OAMethod @property, 'Write', NULL, @xx
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @property, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
print @src
print @desc
RETURN
END

-- Destroy the object.
EXEC @hr = sp_OADestroy @object
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END


Thank you for any help.
   

- Advertisement -