Question Delete an item from a structure

elianeasmar

Well-known member
Joined
Oct 3, 2013
Messages
76
Programming Experience
Beginner
Untitled.png
Hello.
I have a question. Is deleting an item from an array is similar to deleting an item from a structure?
i have this structure:
Public Structure _schoolinfo
    Public Code As String
    Public Name As String
    Public PhoneNumber As String
    Public Address As String
    Public Sex As String
    Public Title As String
    Public Position As String
End Structure



And i am saving it like this:


Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        _info = New _schoolinfo
        With _info
            .Code = txtCode.Text
            .Name = txtName.Text
            .PhoneNumber = txtPhoneNumber.Text
            .Address = txtAddress.Text
            .Title = cmbTitle.Text
            .Position = cmbPosition.Text


            If RDFemale.Checked Then
                .Sex = "Female"
                If RDMale.Checked Then
                    .Sex = "Male"
                End If
            End If
        End With
        If _infoschool = "I" Then
            index = _collection.Count + 1
            _icollection.Add(New _schoolinfo With {.Code = txtCode.Text, .Name = txtName.Text, .PhoneNumber = txtPhoneNumber.Text, .Address = txtAddress.Text, .Title = cmbTitle.Text})
            _collection.Add(_info, getkey(index))
        Else
            '_info = New _schoolinfo
            If _collection Is Nothing Then _collection = New Collection
            If _collection.Count > 0 Then _collection.Remove(getkey(index))
            _collection.Add(_info, getkey(index))
        End If
        _inf = Nothing
        PrepareTextBox(False)
        RefreshControls("L")
    End Sub



if i want to delete an item from the structure, how am i suppose to delete it?
I am stuck. i tried 'nothing'. but i think this should empty the whole structure.

and i need to clear the item displayed on my screen :/

Any help?

Thank you :)
 
Last edited by a moderator:
Is deleting an item from an array is similar to deleting an item from a structure?
No they're not because there is no such thing as deleting an item from a structure. What you're asking for doesn't really make sense so we had better clear up exactly what it is that you need. Are you actually saying that you want to remove an instance of that structure from a collection? Are you actually saying that you want to clear the TextBoxes and ComboBoxes that the user entered the data into? Are you actually saying something else?

By the way, you should NEVER use that Collection class. We're not using VB6 here. If you want a collection of schoolInfo objects then you should be using a List(Of schoolInfo) Furthermore, your structure should probably be a class and it should be named SchoolInfo.
 
Back
Top