Log in

View Full Version : Unable to use large buffer / convert array of strings



yeahbuddeh
06-02-2022, 08:46 PM
I have a function that basically takes an Array of Variant type. My Array is in this format



buf = Array(70, 90, 42, 76...)


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?



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

arnelgp
06-05-2022, 05:50 PM
can you not write the Array individually:

Set coll=CreateObject("System.Collection.ArrayList")
coll.Add "70"
coll.Add "90"
coll.Add "42"
...
...
etc.

yeahbuddeh
06-05-2022, 11:52 PM
I tried that but it crashes Word. there are simply too many. The method with strings I tried fits all the data without crashing but I don't know a why to get each element out separately with this language. If it was C or C++ i would have.