none
No default member found for type 'Byte' error in VB 2015 RRS feed

  • Question

  • Hello All,

    I'am using VS Community 2015 with VB as coding language along with .NET framework 4.6

    I'am trying to read my serial port data in a queue with element size of 30. However when I'am trying to dequeue the elements , It is giving me error "No default member found for type 'Byte' error ". Below is the code part of my application.

     Private Sub myPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles myPort.DataReceived
    
            Dim inData1 As Integer = myPort.ReadByte()
    
            Do While analogDataQueue.Count <= 30
                analogDataQueue.Enqueue(CByte(inData1))
                inData1 = myPort.ReadByte()
    
            Loop
            printx()
    end sub
    
    Private Sub printx()
            Dim xvalue1 As Byte
            Dim plotValue As Integer
    
            x_start = 1
            y_start = graph.Height
            mygraphics = graph.CreateGraphics
            mygraphics.PageUnit = GraphicsUnit.Pixel
            mygraphics.PageScale = 1
            mygraphics.DrawLine(p1, 0, CInt(graph.Height), CInt(graph.Width), CInt(graph.Height))
            mygraphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
            mygraphics.ScaleTransform(1, 1)
    
            
            While analogDataQueue.Dequeue(xvalue1) 'GIVING ERROR AT THIS LINE
    
                'Xvalue1 = (Xvalue1 * 2)
                plotValue = xvalue1
                mygraphics.DrawLine(p2, x_start + k, y_start - temp_ahead1, x_start + (k + 1), y_start - plotValue)
    
                temp_ahead1 = plotValue
                DataEnter = False
               
    
                k = k + 1
    
                If k = graph.Width Then
                    k = 0
                    mygraphics.Clear(Color.White)
    
                End If
            End While
            If recordflag = True Then
                    
    
                    sqlcmd = sqlconn.CreateCommand()
    
                    
                    
                    
                   
    
    
    
    
                    sqlcmd.CommandText = "INSERT  INTO datarecord (RecordTime, DATA,ID)  VALUES (Time('now'),@DAT,@ID)"
    
                    sqlcmd.Parameters.Clear()
    
    
                    sqlcmd.Parameters.AddWithValue("@DAT", buffer)
                    sqlcmd.Parameters.AddWithValue("@ID", IDstring)
                    sqlcmd.ExecuteNonQueryAsync()
    
                    
                End If
    
    
    
           
        End Sub

    Tuesday, July 25, 2017 8:40 AM

All replies

  • If you write where the error appears in your code you have a higher chance on a solution. 

    Success
    Cor

    Tuesday, July 25, 2017 8:47 AM
  • I've written it as comment

    Getting error at this line

      While analogDataQueue.Dequeue(xvalue1)

    Tuesday, July 25, 2017 8:49 AM
  • Hello,

    Are you coding with Option Strict On ? If not you should as this may indicate the reason for the error.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, July 25, 2017 8:52 AM
    Moderator
  • If I include Option Strict on , It give error of "Option Strict on disallows late binding" on same line
    Tuesday, July 25, 2017 8:56 AM
  • If I include Option Strict on , It give error of "Option Strict on disallows late binding" on same line
    Late binding in this case is unwise as at runtime it will slow down processing of your code and is more prone (as you have learned) to errors such as the current one. So best to set Option Strict On to fix the current issue.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, July 25, 2017 8:58 AM
    Moderator
  • But using option strict on doesn't fix the issue!!
    Tuesday, July 25, 2017 9:27 AM
  • Yea now I see it, but maybe if you write it in your text and somebody has not first to read a the whole code.

    I don't know your overloaded version of Dequeue and also could not find it. 

    However, I assume you want to to do this, because I could not find it in MSDN

    I made this sample for you how you could use it to make it more clear what I mean. 

    Module Module1
        Sub Main()
            Dim numbers As New Queue(Of Byte)
            numbers.Enqueue(1)
            numbers.Enqueue(2)
            numbers.Enqueue(3)
            numbers.Enqueue(4)
            numbers.Enqueue(5)
            Dim field As Byte
            For i = numbers.Count - 1 To 0 Step -1
                field = numbers.Dequeue
                Console.WriteLine($"Quenumber {i} content {CStr(field)}")
            Next
            Console.ReadLine()
        End Sub
    End Module

    Try to improve your way of coding a little bit by using more modern style of VB Conventions.

    Start a member name (Constructor, Method, Property), a Global field and a parameter with an uppercase and a internal field with a lowercase. 


    Success
    Cor


    Tuesday, July 25, 2017 9:32 AM
  • But using option strict on doesn't fix the issue!!
    It's not meant to fix the problem, instead using Option Strict On is to assist you with learning about the issue so you can better assess it and fix it. Also, the code shown is using variable declared outside the scope of the code shown which makes it harder to assist not knowing what they are.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, July 25, 2017 9:49 AM
    Moderator