VB.Net tutorial:Buble-sort (How to use listbox in vb.net)


In vb.net

we can use listbox.

listbox is same as richtextbox but by using listbox you don’t need to bother of giving space between two elements

here is the code .

please check names i have used for buttons and textboxs.

Public Class Form1

    Dim Arr(20) As Integer

Dim i As Integer = 0

Dim s As Integer

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim sflag As Integer = 0

Dim i, j As Integer

Dim arr1() As String

Dim Str As String = TextBox1.Text

If sflag = 1 Then

ListView1.Clear()

End If

arr1 = Str.Split(” “)

For i = 0 To UBound(arr1)

Arr(i) = Convert.ToInt32(arr1(i))

Next i

TextBox2.Text = i

s = i

For k = 0 To i – 1

For j = 0 To i – 2

If Arr(j + 1) <= Arr(j) Then

Dim temp As Integer

temp = Arr(j)

Arr(j) = Arr(j + 1)

Arr(j + 1) = temp

End If

Next j

Next k

For k = 0 To i – 1

Str = Convert.ToString(Arr(k))

ListView1.Items.Add(Str)

sflag = 1

‘MsgBox(Str)

Next

End Sub

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

ListView1.Clear()

End Sub

End Class

                       

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s