Arraylist searching troubles

CaJack

New member
Joined
Jan 2, 2008
Messages
3
Programming Experience
Beginner
I’m having some trouble with my array list. I’m using my array list to store numbers in it. Adding stuff to it works fine. But searching the array list to see if it already contains a number is proving more difficult. Here’s what I’ve got:
VB.NET:
Public Sub TestNum()
        Dim p As String
        Dim q As String = frm_EnterInfo.TextBox1.Text
        For Each p In c_TestArrayClass.NumArray

            If p = q Then

                frm_enterInfo.Label3.Text = "Found in Array"
                Exit For
            Else

                frm_enterInfo.Label3.Text = "Not Found"

            End If
        Next
   
    End Sub

I get this error when I run it "Conversion from type 'EnterInfoClass' to type 'String' is not valid" and it points to this part:
VB.NET:
For Each p In c_TestArrayClass.NumArray

Could anyone help me?
Sorry If I've posted in the wrong area.
 
If you're storing strings use a List(Of String), if you're storing integers use a List(Of Integer). ArrayList is Object type and used for storing more than one type object. These lists all have a Contains method, that will tell if something is there or not, you don't need to loop all elements yourself.
As for your other problem it's hard to tell, the error message indicates that NumArray property/field is a collection of type EnterInfoClass and not String as required.
 
Back
Top