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 intDECLARE @hr intDECLARE @src varchar(255), @desc varchar(255)DECLARE @return intDECLARE @property intEXEC @hr = sp_OACreate 'Scripting.FileSystemObject', @object OUTIF @hr <> 0BEGIN EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc PRINT @src RETURNENDEXEC @hr = sp_OAMethod @object, 'CreateTextFile', @property OUT, 'C:\PIS\Test.zip'IF @hr <> 0BEGIN EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc print @src print @desc RETURNENDDECLARE @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, @xxIF @hr <> 0BEGIN EXEC sp_OAGetErrorInfo @property, @src OUT, @desc OUT SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc print @src print @desc RETURNEND-- Destroy the object.EXEC @hr = sp_OADestroy @objectIF @hr <> 0BEGIN EXEC sp_OAGetErrorInfo @object, @src OUT, @desc OUT SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc RETURNEND
Thank you for any help.