Been struggling with this thread: http://www.vbforums.com/showthread.p...ding-This-Code
The code in question uses the MidB function to concatinate two Arrays together. One happens to be a Variant the other a Byte Array.
However, this works:
The net result is that the Array bytC ends up containing all the elements of bytA and bytB (exactly what you'd expect if they all were string variables, rather than Byte Arrays, and Mid$ was used)Code:Private Sub Command1_Click() Dim bytA(9) As Byte Dim bytB(9) As Byte Dim bytC() As Byte Dim intI As Integer For intI = 0 To 9 bytA(intI) = CByte(intI + &H10) Next intI For intI = 0 To 9 bytB(intI) = CByte(intI + &H20) Next intI bytC = MidB(bytA, 1) & MidB(bytB, 1) For intI = 0 To UBound(bytC) Debug.Print Hex(bytC(intI)); " "; Next intI End Sub
What I don't understand is why it works. The MidB documentation suggests that the first Argument should be a String and here we are giving it a byte Array.
I would have expected a Type Mismatch error. I'd have thought it would have required a BSTR pointer rather than a 'direct' pointer to the string argument.
I understand that MidB returns bytes rather than characters and is primarily used in DBCS Applications.
Are there any 'gotchas' to using this technique. In the thread I referenced above it's used to buffer incoming binary data without the need for loads of loops going through arrays to manually append data. Will it plant the odd '?' in the stream if it comes upon an invalid DBCS pair ?




Reply With Quote