Array Search and Sort Methods in vb.net

Array Search and Sort Methods in vb.net

You can now have arrays search themselves or sort themselves. Here’s an example showing how to use both the sort and search methods of the Array object. The syntax for these two methods is as follows:

Array.Sort(myArray)

And

arrayIndex = Array.BinarySearch(myArray, “Name”)

To see this feature in action, put a Button and a TextBox control on a form and change the TextBox’s MultiLine property to True. Then enter the following

====================================================================

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myarray(3) As String
myarray.SetValue("zoo", 0)
myarray.SetValue("brief", 1)
myarray.SetValue("area", 2)
myarray.SetValue("trim", 3)
Dim x As String
Dim show As String
x = Chr(13) & Chr(10)

Dim i As Integer
For i = 0 To 3
show = show & myarray(i) & x
Next

TextBox1.Text = show & x & x & "Array:" & x
Array.Sort(myarray)
show = ""
For i = 0 To 3
show = show & myarray(i) & x
Next
TextBox2.Text = show & x & "SORTED:" & x
Dim anrrayIndex As Integer
anrrayIndex = Array.BinarySearch(myarray, "area")
show = CStr(anrrayIndex)
MsgBox("The word area was found at the " & show & " index within the array")



End Sub

=================================================================================================

1 comment:

Anonymous said...

I am the kind of guy who enjoys to seek unused things. Right now I'm manufacturing my private pv panels. I am doing it all alone without the assistance of my staff. I'm utilizing the internet as the only path to acheive this. I saw a really brilliant website which explains how to make photovoltaic panels and so on. The site explains all the steps needed for solar panel construction.

I am not exactly sure about how correct the info given there is. If some people over here who have xp with these works can have a peak and give your feedback in the site it would be great and I would extremely treasure it, cauze I really love solar panel construction.

Thanks for reading this. You guys are great.