如何在VbScript中创建BinaryArray? [英] How to create BinaryArray in VbScript?

查看:71
本文介绍了如何在VbScript中创建BinaryArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想手动创建一个二进制脚本,然后将其另存为二进制文件.

I want to manually create a binary script and then save it as binary file.

我想附加以下所有字节,并从中创建一个二进制文件.

I want to append all of the following bytes and create a binary file out of them.

&HF0
&HF1
&HF2

我希望能够做这样的事情:

I want to able to do something like this :

Dim generateData(3) As Byte
generateData(0) = &HFF
generateData(1) = &HFE
generateData(2) = &HFC

但是很明显,按字节在Vbscript上不起作用.我确实使用以下函数将二进制数组写入磁盘(至少当我能够创建二进制数组时会用到

But obviously As Byte doesn't work on Vbscript. I do use the following function to write binary array to disk (at least I'll when I able to create a binary array)

Function SaveBinaryData(FileName, ByteArray)
  Const adTypeBinary = 1
  Const adSaveCreateOverWrite = 2

  'Create Stream object
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")

  'Specify stream type - we want To save binary data.
  BinaryStream.Type = adTypeBinary

  'Open the stream And write binary data To the object
  BinaryStream.Open
  BinaryStream.Write ByteArray

  'Save binary data To disk
  BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function

推荐答案

我已经看到一些类似的用法:

I have seen something along these lines used:

Sub WriteBinary(FileName, Buf)  

    Dim I, aBuf, Size, bStream  

    Size = UBound(Buf): ReDim aBuf(Size \ 2)  

    For I = 0 To Size - 1 Step 2  

        aBuf(I \ 2) = ChrW(Buf(I + 1) * 256 + Buf(I))  

    Next  

    If I = Size Then aBuf(I \ 2) = ChrW(Buf(I))  

    aBuf=Join(aBuf, "")  

    Set bStream = CreateObject("ADODB.Stream")  

    bStream.Type = 1: bStream.Open  

    With CreateObject("ADODB.Stream")  

        .Type = 2 : .Open: .WriteText aBuf  

        .Position = 2: .CopyTo bStream: .Close  

    End With  

    bStream.SaveToFile FileName, 2: bStream.Close  

    Set bStream = Nothing  

End Sub

这篇关于如何在VbScript中创建BinaryArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆