Android Question Byte Array within type - compare not working

Discussion in 'Android Questions' started by Arf, Mar 18, 2015.

  1. Arf

    Arf Active Member Licensed User

    I've got a type that contains some byte arrays, with MAC addresses in them:
    Code:
    Type UnitMACStruct(PCmac(12As Byte, TABLETmac(12As Byte)
    Dim UnitInfo As UnitInfoStruct
    Dim ThisMAC(12As Byte
    ThisMAC = bc.StringToBytes(serial1.Address.Replace(
    ":",""),"UTF8")
    So ThisMAC is a 12 byte array containing a MAC address with :'s removed.
    I know that the contents of UnitInfo.TABLETmac contains the same MAC address, although if I look at the one byte array in the watch window, the data is represented in a different way, I guess due to being within a type.

    Problem is, when I do this:
    Code:
    If ThisMAC <> UnitMAC.TABLETmac Then
    the test always comes out true, indicating the array contents are different.
    They are the same though - if I extract both array contents to strings, the strings are the same.

    I could just compare the strings, but in the interest of keeping things simpler an understanding whats occurring, can anyone see why the test above is not working?
     
  2. Troberg

    Troberg Well-Known Member Licensed User

    My guess: You are not comparing the contents of the arrays, you are comparing the object references to the arrays. As these are two different arrays containing the same data, the test will come out as not equal.

    Just for fun, try comparing this:

    Dim ThatMac() as byte = ThisMac
    If ThisMac=ThatMac then...

    I'll bet that it will evaluate as true, as you are then comparing the same object.

    In other words, you need to manually compare the contents.

    Also, it's a 13 byte array. Remember that it's 0-based.
     
    Arf likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice