Results 1 to 9 of 9

Thread: [RESOLVED] Clearing a Structure

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    10

    Resolved [RESOLVED] Clearing a Structure

    Hi trying to check I have cleared this correctly. Seems to have worked byt I seem to get anomolies somethimes that might have nothing to do with the clear part.

    I declare the structure. Dimension it, then when I need to clear call the Sub to clear it.

    1) Will this clear it all, including the array within the structure?

    2) Incidentally I dimension it after as it is here in the example. Is there a way of doing it when actually needed so I have a better idea of how many items to allocate as opposed to an arbitrary number as here in the example of 30?

    Code:
        Structure TestList
            Dim TL_name As String
            Dim TL_total As Integer
            Dim TL_Sub_total_Array() As Integer
            Dim TL_reference As Integer
        End Structure
    
        Dim TotalList(30) As TestList
    
        Private Sub Clear_Rows_Display()
            Dim count1 As Integer
            For count1 = 0 To TestList.GetUpperBound(0)
                Array.Clear(TestList, 0, count1)
            Next
        End Sub
    Thanks in advance.
    Last edited by Writers Block; Jul 2nd, 2007 at 05:04 AM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Clearing a Structure

    Use an array list instead. Then just .Add to it as you need to.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    10

    Re: Clearing a Structure

    Quote Originally Posted by techgnome
    Use an array list instead. Then just .Add to it as you need to.

    -tg
    Array list?

  4. #4
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: Clearing a Structure

    Quote Originally Posted by Writers Block
    Array list?
    http://msdn2.microsoft.com/en-us/lib...st(vs.80).aspx



    EDIT: Changed to Framework 2.0 link.
    Last edited by nmadd; Jun 30th, 2007 at 02:27 PM. Reason: changed link

  5. #5
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Clearing a Structure

    i always erased my arrays with a ReDim but you have to declare it as dynamic to do that.
    That page states that the information on it is for .net 3.0
    that distributable is currently Beta. some people have it but it won't even be available on all OS.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  6. #6
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Clearing a Structure

    if you don't know how, here's an example of redimming
    Code:
     Structure TestList
            Dim TL_name As String
            Dim TL_total As Integer
            Dim TL_Sub_total_Array() As Integer
            Dim TL_reference As Integer
        End Structure
        dim TotalList() as Testlist 'dims it dynamic
        ReDim TotalList(30) As TestList'sets it to size
    
        Private Sub Clear_Rows_Display()
        redim TotalList(30) as testlist 'erases it
        '  Redim preserve totallist(3) as testlist 'Doesn't erase it
        End Sub
    Last edited by Lord Orwell; Jun 30th, 2007 at 02:38 PM. Reason: forgot code brackets
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  7. #7
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: Clearing a Structure

    Quote Originally Posted by Lord Orwell
    i always erased my arrays with a ReDim but you have to declare it as dynamic to do that.
    That page states that the information on it is for .net 3.0
    that distributable is currently Beta. some people have it but it won't even be available on all OS.
    You're right. The MSDN search turns up articles for all versions and I clicked on the 3.0 version. Changed.

  8. #8
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Clearing a Structure

    If you are using .NET 2.0 then use a List(Of TestList) instead.

  9. #9

    Thread Starter
    New Member
    Join Date
    Jun 2007
    Posts
    10

    Re: Clearing a Structure

    Thank you for your replies.

    Got it sorted now(i think).

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