Results 1 to 3 of 3

Thread: deleting element from structure - VB.NET

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    5

    Question deleting element from structure - VB.NET

    Hello my friends.
    I'm running into deep trouble with this structure variable!

    this is the structure
    Code:
     Structure StuRec
            Dim strName As String
            Dim strMNum As String
            Dim ArrScores() As Decimal
            Dim decAvg As Decimal
            Dim strLetter As String
        End Structure
    
    
    dim gBook(20) as StuRec
    
    '
    ' ## handling and filling gBook() with 14 records let's say!
    '
    
    ' By now gBook() has 14 records!
    
    ' I need to delete one record of gBook(). Say I need to delete gBook(3) for example!
    
    ' I did this
    dim Temp() as StuRec
    
    For i as integer = 0 To 14
          if i = 3 then continue For
          temp(i).strName = gBook(i).strName
          'strMNum as well and the others
          'ArrScore(0) is number of scores that student got!
          temp(i).ArrScore(0) = gBook(i).ArrScore(0)
          For c as integer = 1 To gBook(i).ArrScore(0)
          
          temp(i).ArrScore(c) = gBook(i).ArrScore(c)
          
          Next c
    Next i
    the ArrScores() has maximum elements of 10 subscripts

    so i need to delete one recored of them. but it doesn't really seems to be working :S

    Your help is much much appreciated !

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: deleting element from structure - VB.NET

    You might consider using a List(Of StuRec) instead of an array, because it's much easier to add and delete items. You could also turn the array temporarily into a list and delete gBook(3) like this:
    Code:
         Dim gBookList As List(Of StuRec) = gBook.ToList
         gBookList.RemoveAt(3)
         gBook = gBookList.ToArray
    BB

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    5

    Re: deleting element from structure - VB.NET

    Thank you very much BB!
    That was helpful
    I really appreciate it.

    Thumbs UP! ++

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width