Results 1 to 4 of 4

Thread: [RESOLVED] [2008] Array.IndexOf always returns -1

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Location
    UK
    Posts
    123

    [RESOLVED] [2008] Array.IndexOf always returns -1

    I am having trouble with the following piece of code, the searchIndex always returns -1. If I put a breakpoint after 'searchIndex = Array.IndexOf(buffer, &H90)' and look in the buffer array I can see 90h so it should return the index but it doesn't.

    This code is in my serialport DataReceived sub

    Any help would be great!

    Thanks


    Code:
    Dim searchIndex As Integer
            Dim buffer() As Byte = New Byte() {}
            Dim bytesRead As Integer
            bytesRead = SerialPort.BytesToRead ' Get how many bytes available.
            Array.Resize(buffer, bytesRead) ' Set the buffer to the number of bytes available.
            bytesRead = SerialPort.Read(buffer, 0, bytesRead) ' Read the bytes
            If bytesRead > 0 Then
                searchIndex = Array.IndexOf(buffer, &H90)
                If searchIndex <> -1 AndAlso buffer(searchIndex + 1) = &H90 Then
                    If (searchIndex + 18) <= buffer.Length Then
                        For x As Integer = searchIndex To (searchIndex + 18)
                            Debug.WriteLine(buffer(x).ToString)
                        Next
                    End If
                End If
            End If
    Last edited by Adrian26; Jul 8th, 2008 at 05:57 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