Results 1 to 8 of 8

Thread: [RESOLVED] Byte Array Concatination

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Resolved [RESOLVED] Byte Array Concatination

    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:
    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
    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)

    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 ?
    Last edited by Doogle; Jun 9th, 2013 at 03:52 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width