gispe -4 Junior Poster in Training

Hi!
im startin programmin in vb.net.
in the program im doin now, im workin with a global variable 'public library as new biblioteca' that has should be a list of books that user wants to load.
thing is that when i try to delete a book, i have to check if the code entered in textbox1 maches with the codes that the library has.
to search in the library im using: "library.Contenido.Item" but its givin me this error: "'Argument not specified for parameter 'index' of Public Default Property Item(index as Integer as T)", but dont know how to correct it :(
here is the class to delete the book:

Public Class Bajas

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

        Dim i As Int32
        Dim total As Int32

        If (TextBox1.Text < 1000) Or (TextBox1.Text > 32000) Then 'valida q se ingrese codigo bien
            MessageBox.Show(" Ingresar codigo correcto. de 1000 a 32000")
        Else
            For i = library.Contenido.Count To 0 Step -1 'esto recorre todo lo que haya cargado en el list of 
                If (library.Contenido.Item = TextBox1.Text) Then
                    'Argument not specified for parameter 'index' of Public Default Property Item(index as Integer as T) 
                End If
            Next
        End If
    End Sub
End Class

thanks!!

Dani AI

Generated

— the compiler message means you tried to use the list's default Item without supplying an index, and you also need to treat the TextBox value as a number before comparing or removing. Two safe, common fixes are: parse and validate the input first, then either remove matching elements with a predicate (RemoveAll) or iterate the list backwards and call RemoveAt when a match is found. Iterating forward while removing will invalidate the enumerator and skip items.

Example steps to apply immediately:

  • Parse the textbox with Integer.TryParse and enforce the 1000..32000 range.
  • If your list stores book codes as integers, compare against that integer. If codes are strings, compare the trimmed string.
  • To remove matches use RemoveAll(Function(item) item.Codigo = code) for a one-line change, or a backward For loop using Count - 1 down to 0 with RemoveAt if you need to do extra work per removed item.
  • If the collection is data-bound to UI controls, either rebind or use a BindingList(Of T) so removals update the UI automatically.

Cautions: enable Option Strict On to catch implicit conversions early, and prefer TryParse over direct CInt to avoid exceptions. If multiple books can share a code, RemoveAll will delete them all; use the backward loop if you only want the first match.

For reference, see the .NET docs on how List(Of T) indexing and removals work: List(Of T) overview and Integer.TryParse.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.