ADO Stream Write wont work

Hi All
I can t get ADODB Stream.write to work. I get Runtime error 3001.
'Arguments are of wrong type, are out of acceptable range, or are in conflict with one another'

I use Writeline all the time but this is my first time writing binary. Any clues

here is my test code

Private Sub subStreamTest()

Dim cnnLocal As New ADODB.Connection
Dim stmStream As ADODB.Stream
Dim strMcomDir As String
Dim bufBuffer(3) As Variant
Dim bytTest As Byte
strMcomDir = "R:\NewDB\" & funDateString & ".tpf"

bufBuffer(0) = &H5
bufBuffer(1) = &H2
bufBuffer(2) = &HCA

Set stmStream = New ADODB.Stream
stmStream.Type = adTypeBinary

stmStream.Open
bytTest = bufBuffer(2)

stmStream.Write bufBuffer(2)

stmStream.SaveToFile strMcomDir, adSaveCreateOverWrite
stmStream.Close

Set stmStream = Nothing
Set cnnLocal = Nothing

End Sub



Answer this question

ADO Stream Write wont work

  • abupapa

    Thank
    I used the code and was able to write to a binay stream (even if it was long winded).

    But the problem i have is that it puts space h00 between each byte when you view in a hex editor.

    ie if you write "ABCD", the output when viewed in a Hex Editor is '41 00 42 00 43 00 44 00'
    i wan the output to be '41 42 43 44'

    May have to go back to trusty perl.

    Cheers


  • DRoden

    Congratualtions.

    So, if you see this post is the answer to your question please mark it as an answer to exit the queue.

    Best Regards,



  • yosonu

    Hi

    I am now using

    Open File for Binary Input,  Then putting the hex bytes directly there. 

    I have using this method in Perl and few others.  But when i first consulted the help files i couldnt find it.

    Still doesnt answer my orginal question though.  Why couldn't i use Stream.Write in the first place.

    Oh Well



  • HariAdu

    Amr

    I think i have answered my own question. I set the Charset propoerty to 'ascii' on the Writeline stream, then copied it to the binary stream and it worked. Long winded but it worked.

    Yippee



  • Amr Ouf

    Have a look at this thread http://www.codecomments.com/archive300-2006-2-791642.html

    Hope this can help.

    Best Regards



  • sticksnap

    Thanks Amr

    Yes i worked out the unicode is 2 bytes and sent single bytes, but i get the null or h00 between each character. May be there is a setting that it defaults to 2 byte unicode

    Can i turn this off

    I am going to investigate other methods.

    Cheers



  • Vladislav U.

    I see this code uses wide character WChar which allocates one character in 2 bytes.

    So, i think to resolve this issue , you would better comment the code that copies Buf to aBuf and but leave the Join line and WriteText Buf instead of WriteText aBuf

    Hope this can help.

    Best Regards,

    Amr Ouf


    If you see that this is the answer to your question please, mark it as an Answer.



  • ADO Stream Write wont work