Get and Display all Computer Ports in VB.NET

In this tutorial, we will going to create a program that will get and display all the computer ports in vb.net. COM Ports are serial communications port on a PC. Now, let's start this tutorial! 1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application. 2. Next, add only one Button named Button1 and labeled it as "Get Computer Ports". Insert a ListBox named ListBox1 for displaying all the COM Ports. You must design your interface like this: design 3. Put this code in your Button1_Click. This will trigger to get and display all the available COM Port in the ListBox.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         For Each portName As String In My.Computer.Ports.SerialPortNames
  3.             ListBox1.Items.Add(portName)
  4.         Next
  5.     End Sub
We have created a For Each loop statement that has the variable portName as String that has all the value of the Serial Port names. This For Each...Next Statement repeats this group of serial ports to be displayed in ListBox1 as we have the Add function of this control.

Output:

output Download the source code below and try it! :) For more inquiries just contact my number or e-mail below. Best Regards, Engr. Lyndon R. Bermoy IT Instructor/System Developer/Android Developer Mobile: 09488225971 Telephone: 826-9296 E-mail:[email protected] Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky Visit my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment