Why my custom VB.Net class file is giving an "Expected :Identifier" Error? What's wrong?

Thread Starter

Shafty

Joined Apr 25, 2023
327
Code:
Imports System.IO.Ports
Imports System.IO
Public Class Scale
    Private WithEvents SerialPort As New SerialPort()
    Private Const COM_PORT As String = "COM5" ' Change this to your COM port
    Public Sub New()
        ' Constructor logic here if needed
        With SerialPort
            .PortName = COM_PORT
            .BaudRate = 9600
            .ReadTimeout = 1000
            .Parity = Parity.None
            .DataBits = 8
            .StopBits = StopBits.One
        End With
    End Sub
    Public Function ReadScale() As String
        Dim _scaleValue As String
        SerialPort.Open()
        _scaleValue = SerialPort.ReadLine
        SerialPort.Close()
        Return _scaleValue
    End Function
End Class
Code:
Public Sub mac()
dim myScale as New Scale
End Sub
I am getting "Expected Identifier" Error. What's wrong?
 

panic mode

Joined Oct 10, 2011
4,864
how is your project setup?
i created new Winforms project for .NET and got no complaints until i tried accessing it. and since i have no COM5 port of course it got stuck...
1746564562007.png
1746564362120.png
 

Futurist

Joined Apr 8, 2025
721
Code:
Imports System.IO.Ports
Imports System.IO
Public Class Scale
    Private WithEvents SerialPort As New SerialPort()
    Private Const COM_PORT As String = "COM5" ' Change this to your COM port
    Public Sub New()
        ' Constructor logic here if needed
        With SerialPort
            .PortName = COM_PORT
            .BaudRate = 9600
            .ReadTimeout = 1000
            .Parity = Parity.None
            .DataBits = 8
            .StopBits = StopBits.One
        End With
    End Sub
    Public Function ReadScale() As String
        Dim _scaleValue As String
        SerialPort.Open()
        _scaleValue = SerialPort.ReadLine
        SerialPort.Close()
        Return _scaleValue
    End Function
End Class
Code:
Public Sub mac()
dim myScale as New Scale
End Sub
I am getting "Expected Identifier" Error. What's wrong?
Show a screenshot of the error, I guess this is Visual Studio, so show me the error, its a syntax error so what line etc? you won't get much help asking a question like this and not giving details.
 

Thread Starter

Shafty

Joined Apr 25, 2023
327
Code:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe C:\Users\arrow\source\repos\Gowtham\Scale_Project\bin\Debug\Scale_Project.dll /tlb /codebase
did the Magic
 
Top