none
Operator '+' is not defined for types '1-dimensional array of Byte' and 'Byte'._

    Question

  • Operator '+' is not defined for types '1-dimensional array of Byte' and 'Byte'. 

    How would I change the assignment statement in the code below so that each indexed byte position gets assigned the converted integer value in the for loop? Thank you.

    Dim byteArray As Byte()
    Property Data_Out() As Integer()
      Get
        Data_Out = mData_Out
      End Get
      Set(ByVal Value As Integer())
       End Set
    End Property
    
    
    For i = 0 To 10
      byteArray = byteArray + CByte(Data_Out(i))
    next i
    
    
    Wednesday, September 22, 2010 1:48 PM

Answers

  • Try it:

    For i = 0 To 10
     For j As Integer = 0 To byteArray.GetUpperBound(0)
      byteArray(j) = byteArray(j) + CByte(Data_Out(i))
     Next j
    next i
    
    

    []s.

    Alan Cossari.

    Twitter Facebook
    • Marked as answer by hazz Wednesday, September 22, 2010 7:59 PM
    Wednesday, September 22, 2010 2:36 PM
  • You have left off the index on byteArray, which is an array. Without the indexing, VB thinks you mean the array. Look at this code...

        Dim byteArray() As Byte = {1, 2, 3, 4}
        Dim Data_Out() As Integer = {3}
        Dim i As Integer
    
        For i = 0 To byteArray.Count - 1
          byteArray(i) = CByte(Data_Out(0))
        Next i
    
        Dim testit As String = String.Empty
    
        For i = 0 To byteArray.Count - 1
          testit &= byteArray(i).ToString
          If i < byteArray.Count - 1 Then
            testit &= ", "
          End If
        Next
        MessageBox.Show(testit)
    
    
    • Marked as answer by hazz Wednesday, September 22, 2010 7:59 PM
    Wednesday, September 22, 2010 2:39 PM
  •     Dim byteList As New List(Of Byte)
        For i = 0 To 10
          byteList.Add(CByte(i))
        Next
    


    Success
    Cor
    • Proposed as answer by jinzai Wednesday, September 22, 2010 2:53 PM
    • Marked as answer by hazz Thursday, September 23, 2010 2:04 PM
    Wednesday, September 22, 2010 2:41 PM

All replies

  • Try it:

    For i = 0 To 10
     For j As Integer = 0 To byteArray.GetUpperBound(0)
      byteArray(j) = byteArray(j) + CByte(Data_Out(i))
     Next j
    next i
    
    

    []s.

    Alan Cossari.

    Twitter Facebook
    • Marked as answer by hazz Wednesday, September 22, 2010 7:59 PM
    Wednesday, September 22, 2010 2:36 PM
  • You have left off the index on byteArray, which is an array. Without the indexing, VB thinks you mean the array. Look at this code...

        Dim byteArray() As Byte = {1, 2, 3, 4}
        Dim Data_Out() As Integer = {3}
        Dim i As Integer
    
        For i = 0 To byteArray.Count - 1
          byteArray(i) = CByte(Data_Out(0))
        Next i
    
        Dim testit As String = String.Empty
    
        For i = 0 To byteArray.Count - 1
          testit &= byteArray(i).ToString
          If i < byteArray.Count - 1 Then
            testit &= ", "
          End If
        Next
        MessageBox.Show(testit)
    
    
    • Marked as answer by hazz Wednesday, September 22, 2010 7:59 PM
    Wednesday, September 22, 2010 2:39 PM
  •     Dim byteList As New List(Of Byte)
        For i = 0 To 10
          byteList.Add(CByte(i))
        Next
    


    Success
    Cor
    • Proposed as answer by jinzai Wednesday, September 22, 2010 2:53 PM
    • Marked as answer by hazz Thursday, September 23, 2010 2:04 PM
    Wednesday, September 22, 2010 2:41 PM
  • Thank you all !  And I like the idea Cor of the List.
    Thursday, September 23, 2010 3:25 AM