Bubble Sort in Visual Basic

Published on 01 October 2020 (Updated: 01 October 2020)

Welcome to the Bubble Sort in Visual Basic page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

Public Module BubbleSort
    Public Sub Main(args As String())
            ' Convert string to array of integers
            Dim listOfStringInputs As String() = args(0).Split(",")
            Dim n as Integer = UBound(listOfStringInputs)
            If n < 2
                Exit Sub
            End If
            Dim sortArray(n) As Integer
            For i As Integer = 0 To n
                sortArray(i) = Integer.Parse(listOfStringInputs(i))
            Next i

            ' Sort array
            ' Display array
            Dim first As Boolean = True
            For i As Integer = 0 To n
                If i <> 0
                    System.Console.Write(", ")
                End If
            Next i
        Catch e As FormatException
        Catch e As IndexOutOfRangeException
        End Try
    End Sub

    Public Sub Usage()
        System.Console.WriteLine("Usage: please provide a list of at least two integers to sort in the format ""1, 2, 3, 4, 5""")
    End Sub

    Public Sub BubbleSort(ByRef sortArray As Integer())
        Dim holdInt As Integer
        Dim n As Integer = UBound(sortArray)
        For i As Integer = 0 To n - 1
            For x As Integer = i + 1 To n
                If sortArray(x) < sortArray(i) Then
                    holdInt = sortArray(x)
                    sortArray(x) = sortArray(i)
                    sortArray(i) = holdInt
                End If
            Next x
        Next i
    End Sub
End Module

Bubble Sort in Visual Basic was written by:

If you see anything you'd like to change or update, please consider contributing.

Note: The solution shown above is the current solution in the Sample Programs repository as of May 16 2023 12:29:09. The solution was first committed on Oct 01 2020 15:35:27. As a result, documentation below may be outdated.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.