Public Class Form1


    'Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    '    'Add sample names to ListBox1
    '    ListBox1.Items.Add("John")
    '    ListBox1.Items.Add("Mary")
    '    ListBox1.Items.Add("David")
    '    ListBox1.Items.Add("John")
    '    ListBox1.Items.Add("Mary")
    '    ListBox1.Items.Add("Sarah")
    '    ListBox1.Items.Add("alaa")
    '    ListBox1.Items.Add("John")
    '    ListBox1.Items.Add("Sarah")

    '    'Create list to hold duplicates
    '    Dim duplicates As New List(Of String)

    '    'Iterate through ListBox1 items
    '    For i As Integer = 0 To ListBox1.Items.Count - 1
    '        'Get current item
    '        Dim currentItem As String = ListBox1.Items(i).ToString()

    '        'Check if item appears more than once in ListBox1
    '        Dim count As Integer = 0
    '        For j As Integer = 0 To ListBox1.Items.Count - 1
    '            If ListBox1.Items(j).ToString() = currentItem Then
    '                count += 1
    '            End If
    '        Next

    '        'If item appears more than once and is not already in duplicates list, add to ListBox2
    '        If count > 1 AndAlso Not duplicates.Contains(currentItem) Then
    '            ListBox2.Items.Add(currentItem)
    '            duplicates.Add(currentItem)
    '        End If
    '        Dim uniqueNames As New List(Of String)
    '        'If item is not already in uniqueNames list, add to ListBox3 and uniqueNames list
    '        If Not uniqueNames.Contains(currentItem) Then
    '            ListBox3.Items.Add(currentItem)
    '            uniqueNames.Add(currentItem)
    '        End If
    '    Next
    'End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'Add sample names to ListBox1
        ListBox1.Items.Add("John")
        ListBox1.Items.Add("Mary")
        ListBox1.Items.Add("David")
        ListBox1.Items.Add("John")
        ListBox1.Items.Add("Mary")
        ListBox1.Items.Add("Sarah")
        ListBox1.Items.Add("Emily")
        ListBox1.Items.Add("John")

        'Count the frequency of each name in ListBox1
        'Dim counts As New Dictionary(Of String, Integer)
        'For Each name As String In ListBox1.Items
        '    If counts.ContainsKey(name) Then
        '        counts(name) += 1
        '    Else
        '        counts(name) = 1
        '    End If
        'Next

        ''Add duplicate names to ListBox2
        'For Each name As String In counts.Keys
        '    If counts(name) > 1 Then
        '        ListBox2.Items.Add(name)
        '    End If
        'Next

        ''Add unique names to ListBox3
        'For Each name As String In counts.Keys
        '    If counts(name) = 1 Then
        '        ListBox3.Items.Add(name)
        '    End If
        'Next


        'For i As Integer = 0 To ListBox1.Items.Count - 1
        '    Dim currentItem As String = ListBox1.Items(i).ToString()

        '    ' Check if the current item is a duplicate
        '    Dim isDuplicate As Boolean = False
        '    For j As Integer = 0 To i - 1
        '        If currentItem = ListBox1.Items(j).ToString() Then
        '            isDuplicate = True
        '            Exit For
        '        End If
        '    Next

        '    ' Add the current item to the appropriate listbox
        '    If isDuplicate Then
        '        ListBox2.Items.Add(currentItem)
        '    Else
        '        ListBox3.Items.Add(currentItem)
        '    End If
        'Next

        'Create a ListBox to store unique names
        Dim uniqueNamesListBox As New ListBox()

        'Create a ListBox to store duplicate names
        Dim duplicateNamesListBox As New ListBox()

        'Loop through each name in the original ListBox (ListBox1)
        For Each name As String In ListBox1.Items
            'If the name is not already in the uniqueNames ListBox, add it
            If Not uniqueNamesListBox.Items.Contains(name) Then
                uniqueNamesListBox.Items.Add(name)
            Else 'Otherwise, add it to the duplicateNames ListBox
                duplicateNamesListBox.Items.Add(name)
            End If
        Next

        'Copy the contents of the uniqueNames ListBox to ListBox3
        For Each name As String In uniqueNamesListBox.Items
            ListBox3.Items.Add(name)
        Next

        'Copy the contents of the duplicateNames ListBox to ListBox2
        For Each name As String In duplicateNamesListBox.Items
            ListBox2.Items.Add(name)
        Next
    End Sub
End Class
 

Visual basic (VB.net) Online Compiler

Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net. OneCompiler also has reference programs, where you can look for the sample code to get started with.

Read input from STDIN in VB.net

OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.

Public Module Program
	Public Sub Main(args() As string)
	 Dim name as String = Console.ReadLine()    ' Reading input from STDIN
   Console.WriteLine("Hello " & name)           ' Writing output to STDOUT
	End Sub
End Module

About VB.net

Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.

Key Features

  • Beginner's friendly language.
  • Simple and object oriented programming language.
  • User friendly language and easy to develop GUI based applications.

Syntax help

Variables

Variable is a name given to the storage area in order to identify them in our programs.

Simple syntax of Variable declaration is as follows

Dim variableName [ As [ New ] dataType ] [ = initializer ]

Variable initialization

variableName = value

Conditional Statements

1. If

If condition-expression Then 
    'code
End If

2. If-else

If(conditional-expression)Then
   'code if the conditional-expression is true 
Else
  'code if the conditional-expression is false 
End If

3. If-else-if ladder

If(conditional-expression)Then
   'code if the above conditional-expression is true 
Else If(conditional-expression) Then
        'code if the above conditional-expression is true 
    Else
        'code if the above conditional-expression is false 
End If

4. Nested-If

If(conditional-expression)Then
   'code if the above conditional-expression is true
   If(conditional-expression)Then
         'code if the above conditional-expression is true 
   End If
End If

5. Select Case

Select [ Case ] expression
   [ Case expressionlist
      'code ]
   [ Case Else
      'code ]
End Select

Loops

1. For..Next

For counter [ As datatype ] = begin To end [ Step step ]
   'code
   [ Continue For ]
   'code
   [ Exit For ]
   'code
Next [ counter ]

2. For..Each

For Each element [ As datatype ] In group
   'code
   [ Continue For ]
   'code
   [ Exit For ]
   'code
Next [ element ]

3. While

While conditional-expression
   'Code 
   [ Continue While ]
   'Code
   [ Exit While ]
   'Code
End While

4. Do-while

Do { While | Until } conditional-expression
   'Code
   [ Continue Do ]
   'Code
   [ Exit Do ]
   'Code
Loop
Do
   'Code
   [ Continue Do ]
   'Code
   [ Exit Do ]
   'Code
Loop { While | Until } conditional-expression

Procedures

Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.

Procedures are of two types.

1. Functions

Functions return a value when they are called.

[accessModifiers] Function functionName [(parameterList)] As returnType
   'code
End Function

2. Sub-Procedures

Sub-procedures are similar to functions but they don't return any value.

Sub ProcedureName (parameterList)
'Code
End Sub