Export (0) Print
Expand All

Ports.SerialPortNames Property

Gets a collection of the names of the serial ports on the computer.

Namespace: Microsoft.VisualBasic.Devices
Assembly: Microsoft.VisualBasic (in microsoft.visualbasic.dll)

public ReadOnlyCollection<string> SerialPortNames { get; }
/** @property */
public ReadOnlyCollection<String> get_SerialPortNames ()

public function get SerialPortNames () : ReadOnlyCollection<String>

Not applicable.

Property Value

A collection of the names of the serial ports on the computer.

For more detailed information, see the Visual Basic topic My.Computer.Ports.SerialPortNames Property.

The My.Computer.Ports.SerialPortNames property gets a collection of the names of the serial ports on the computer.


The port names returned by My.Computer.Ports.SerialPortNames may be incorrect when run on Windows 98. To prevent application errors, use exception handling, such as the Try...Catch...Finally statement or the Using statement, when using the port names to open ports.

The following table lists an example of a task involving the My.Computer.Ports.SerialPortNames property.



Show available serial ports

How to: Show Available Serial Ports in Visual Basic

This example loops over all the strings that the My.Computer.Ports.SerialPortNames property returns. These strings are the names of the available serial ports on the computer.

Typically, a user selects which serial port the application should use from the list of available ports. In this example, the serial port names are stored in a ListBox control. For more information, see ListBox Control (Windows Forms).

Sub GetSerialPortNames()
    ' Show all available COM ports.
    For Each sp As String In My.Computer.Ports.SerialPortNames
End Sub

This example requires:

  • A reference to the System namespace.

  • That your form have a ListBox control named ListBox1.

For more information, see How to: Show Available Serial Ports in Visual Basic.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

© 2015 Microsoft