Click here to Skip to main content
16,008,490 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralDatagrid Refresh Problem Pin
jzwiers5-May-05 6:18
jzwiers5-May-05 6:18 
GeneralRe: Datagrid Refresh Problem Pin
Het21095-May-05 18:22
Het21095-May-05 18:22 
GeneralBrowsing and opening files Pin
NRayman5-May-05 5:53
NRayman5-May-05 5:53 
GeneralRe: VB.NET help required Pin
NRayman5-May-05 9:16
NRayman5-May-05 9:16 
GeneralRe: VB.NET help required Pin
Anonymous5-May-05 12:35
Anonymous5-May-05 12:35 
GeneralRe: VB.NET help required Pin
NRayman10-May-05 6:04
NRayman10-May-05 6:04 
GeneralSearch ArrayList on Custom Object Pin
fm_6685-May-05 5:37
fm_6685-May-05 5:37 
GeneralRe: Search ArrayList on Custom Object Pin
Fernando Soto5-May-05 16:08
Fernando Soto5-May-05 16:08 
Hi;

This is not as big of a problem as you may think. This is what is needed to be done.

Create you structure as follows:

Structure MyStru
Implements IComparable

Public UserID As String
Public Name As String
Public StuClass As String

Public Function CompareTo(ByVal obj As Object) _
As Integer Implements System.IComparable.CompareTo

Dim tmpObj As MyStru

tmpObj = CType(obj, MyStru)
Return Me.UserID.CompareTo(tmpObj.UserID)

End Function

End Structure

Dim MyStuClass As New ArrayList
Dim MyStudent As New MyStru

By defining “Implements IComparable” and implementing the function CompareTo in your structure, when you now call ArrayList.Sort and ArrayList.BinarySearch, your CompareTo function will be called. Because you know the structure and know how you want to sort and search the objects you pass those items to the system which knows how to compare the strings. The Me.UserID in the return statement above is the first string to compare to the tempObj.UserID the other string which ArrayList.Sort or ArrayList.BinarySearch sent to compare.

Before you can call ArrayList.BinarySearch the object must be sorted, the ArrayList.Sort will do that for you.

And now the rest of the code:

‘ Call sort before calling MyStuClass.BinarySearch
MyStuClass.Sort()

' The index into the ArrayList where it
‘ found the record you wanted.
Dim index As Integer
‘ Holds the item you are searching for.
Dim tmpStru As New MyStru

tmpStru.UserID = txtFind.Text.ToString()
index = MyStuClass.BinarySearch(tmpStru)

The value of index will be a negative number meaning it was not found or a positive number meaning the zero based index of the value you were looking for in your arraylist.

Hope this was of some help.

GeneralRe: Search ArrayList on Custom Object Pin
fm_6685-May-05 23:06
fm_6685-May-05 23:06 
Generalchange the border of textbox Pin
Rizwan Bashir5-May-05 4:43
Rizwan Bashir5-May-05 4:43 
GeneralRe: change the border of textbox Pin
Joey Picerno5-May-05 6:48
Joey Picerno5-May-05 6:48 
GeneralPrint DOC, PDF, XLS files wth header Pin
d44735-May-05 4:22
d44735-May-05 4:22 
GeneralRe: Print DOC, PDF, XLS files wth header Pin
Anonymous5-May-05 12:48
Anonymous5-May-05 12:48 
GeneralSQL logon with crystal reports Pin
Joey Picerno5-May-05 4:08
Joey Picerno5-May-05 4:08 
GeneralReport quering Pin
Waheire5-May-05 3:51
Waheire5-May-05 3:51 
GeneralRe: Report quering Pin
Joey Picerno5-May-05 6:51
Joey Picerno5-May-05 6:51 
GeneralTimer event Pin
Ben_115_net5-May-05 3:37
Ben_115_net5-May-05 3:37 
GeneralRe: Timer event Pin
Dave Kreskowiak5-May-05 4:22
mveDave Kreskowiak5-May-05 4:22 
GeneralFast pixel drawing on .net COMPACT Framework Pin
CarlosMMartins5-May-05 0:32
CarlosMMartins5-May-05 0:32 
GeneralRe: Fast pixel drawing on .net COMPACT Framework Pin
Dave Kreskowiak5-May-05 4:26
mveDave Kreskowiak5-May-05 4:26 
GeneralRe: Fast pixel drawing on .net COMPACT Framework Pin
CarlosMMartins5-May-05 5:21
CarlosMMartins5-May-05 5:21 
QuestionHow to set pixel color on paint event Pin
meghadwivedi4-May-05 21:37
meghadwivedi4-May-05 21:37 
AnswerRe: How to set pixel color on paint event Pin
Dave Kreskowiak5-May-05 4:25
mveDave Kreskowiak5-May-05 4:25 
GeneralCannot Create ActiveX Component 429 Pin
Rizwan Bashir4-May-05 21:15
Rizwan Bashir4-May-05 21:15 
Generalsms to mobiles from Web application Pin
din butt4-May-05 20:05
din butt4-May-05 20:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.