I have a function that basically takes an Array of Variant type. My Array is in this format
However, i can't use a large array so I decided to use a method that allows me to add to an Array. However, each "string" is an element and I need a way to individualize each byte (the numbers between the commas) as single elements instead of the entire string being an element. This way I can pass off my Array to my WriteBinary function. Unless there is a way to modify the function itself?buf = Array(70, 90, 42, 76...)
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 Sub Main() Dim coll As Object Set coll = CreateObject("System.Collections.ArrayList") coll.Add "70, 90, 42, 76, 0, 0, 65, 112, 114, 105," coll.Add "255, 255, 104, 76, 43, 32, 23, 56, 77," 'so on and so forth Dim arr As Variant buf = coll.ToArray WriteBinary "C:\file.bin", buf End Sub



Reply With Quote