Results 1 to 9 of 9

Thread: [RESOLVED] clear an array between calls

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [RESOLVED] clear an array between calls

    I have sub that loops the columns in a mshflexgrid and loads unique items
    into 7 comboboxes. I need to clear the array between calls as the array seems to be holding values between calls. How can i do this ?
    Code:
    Private Type Report
     RefName As String * 25 
     RefCnt As Long 'the count for each entry
    End Type
    
    
       'fill the combos with unique values
        CountUniqueValues Region, cboRegion, "< All Regions >"
        CountUniqueValues Referrer, cboReferer, "< All Referrers >"
        CountUniqueValues Material_Style, cboMaterialStyle, "< All Material Styles >"
        CountUniqueValues Material_Type, cboMaterialType, "< All Material Types >"
        CountUniqueValues Material_Color, cboMaterialColor, "< All Material Colors >"
        CountUniqueValues Job_Type, cboJobType, "< All Job Types >"
        CountUniqueValues Entered_By, cboEnteredBy, "< All Entered By >"
        CountUniqueValues Estimator, CboEstimater, "< All Estimators/Salesman >"
    
    
    Sub CountUniqueValues(c As Integer, cbo As ComboBox, cboText As String)
      Dim r As Long
      Dim CurRef, LastRef As String
      ReDim Refs(0) As Report
      Dim i As Long
      Dim RName As String
      Dim RCount As Long
    
    
    
        GridMisc.Col = c
        GridMisc.Sort = 5 'text ascending sort
    
      For r = 1 To GridMisc.Rows - 1
        If GridMisc.TextMatrix(r, c) <> "" Then
          CurRef = GridMisc.TextMatrix(r, c)
        End If
         
        If LastRef = CurRef Then
          Refs(UBound(Refs)).RefCnt = Refs(UBound(Refs)).RefCnt + 1
        Else
    
             ReDim Preserve Refs(UBound(Refs) + 1)
             Refs(UBound(Refs)).RefName = CurRef
             Refs(UBound(Refs)).RefCnt = 1
             LastRef = CurRef
        End If
    Next r
    
    
    For i = 1 To UBound(Refs)
        RName = Trim(Refs(i).RefName)
        RCount = Refs(i).RefCnt
        GridRecap.AddItem vbTab & RName & vbTab & CStr(RCount)    
       'Debug.Print RName & vbTab & CStr(RCount)
    Next i
      
     
    End Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: clear an array between calls

    If you mean Refs(), it is already reset at the very start of the routine.

    Give us details of what the issue actually is, rather than your assumption of the cause.


    By the way, I don't see why you have the cbo and cboText parameters - you aren't using them.

  3. #3

  4. #4
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: clear an array between calls

    If you want to clear a dynamic array then you can use ERASE.

    Code:
    ERASE Refs
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  5. #5

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: clear an array between calls

    I thought that the array was the problem, because when i changed the order of loading the cbo's the first cbo was always correct and the cbo's that followed
    have items from the first cbo and items from the other cbo's. Basically i am loading a mshflexgrid with 40 columns from a file and using it to create reports, like a database. I scan the columns-rows and use the results in 2 other flexgrids, recap and detail. I know what everyone is thinking "Why not just use a database" I have my reasons, Listing the reasons would create a bunch of email buddies. Should know better than to think just erasing an array would fix a simple problem. Better get to debugging. Thanks guys
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  6. #6

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: clear an array between calls

    Quote Originally Posted by si_the_geek View Post
    If you mean Refs(), it is already reset at the very start of the routine.

    Give us details of what the issue actually is, rather than your assumption of the cause.


    By the way, I don't see why you have the cbo and cboText parameters - you aren't using them.
    I just left out that part it is before the end sub
    cbo.AddItem cboText
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7

  8. #8

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: clear an array between calls

    Quote Originally Posted by MartinLiss View Post
    Here's a nit. In the following CurRef is a Variant and not a String.

    Dim CurRef, LastRef As String
    Thanks fixed that
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  9. #9

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: clear an array between calls

    thanks everybody, fixed it like it should have been to begin with eg:
    Adding directly to the cbo's from the array rather to a grid then the cbo's
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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