Q. Implement a program for the demonstration of Array in Visual Basic 2010 where sorting and
reversing of array can be performed by the user.
Source Code:
Public Class Form1
Dim i As Integer
Dim ary(5) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For Me.i = 0 To ListBox1.Items.Count - 1
ary(i) = ListBox1.Items(i)
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Array.Sort(ary)
For Me.i = 1 To 5
ListBox2.Items.Add(ary(i))
Next
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Array.Reverse(ary)
For Me.i = 0 To 4
ListBox3.Items.Add(ary(i))
Next
End Sub
End Class
reversing of array can be performed by the user.
Source Code:
Public Class Form1
Dim i As Integer
Dim ary(5) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For Me.i = 0 To ListBox1.Items.Count - 1
ary(i) = ListBox1.Items(i)
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Array.Sort(ary)
For Me.i = 1 To 5
ListBox2.Items.Add(ary(i))
Next
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Array.Reverse(ary)
For Me.i = 0 To 4
ListBox3.Items.Add(ary(i))
Next
End Sub
End Class
Comments
Post a Comment