Solved

VB6- Get counts of distinct value in MSHFlexgrid2

Posted on 2012-12-21
4
342 Views
Last Modified: 2012-12-21
Hello all

I would like to be able to get the counts of distinct value from my MSHFlexgrid2 in column 4.

ex:
In column 4, i can see values like:
20120101
20110605
20101212
20121019


I would like to have the look at the frist 4 chars from that value and then counts the number of time it shows.

Example of the msgbox:
2010 = 1 Records
2011 = 1 Records
2012 = 2 Records



How can i do that please?

Thanks again for your help
0
Comment
Question by:Wilder1626
  • 3
4 Comments
 
LVL 11

Author Comment

by:Wilder1626
Comment Utility
I did this for now but this only give me the count of different text

Dim MyCollection As New Collection
Dim k As Integer
For k = 1 To MSHFlexGrid2.Rows - 1

        If MSHFlexGrid2.TextMatrix(k, 4) <> "" Then
            On Error Resume Next
            MyCollection.Add MSHFlexGrid2.TextMatrix(k, 4), MSHFlexGrid2.TextMatrix(k, 4)
            On Error GoTo 0
        End If

    Next k
    MsgBox MyCollection.Count

Open in new window

0
 
LVL 9

Accepted Solution

by:
shorvath earned 500 total points
Comment Utility
this will work,

Dim RecordCount() As String
Dim bFound As Boolean
Dim i As Integer
Dim k As Integer
Dim rc As Integer
Dim strMsg As String

ReDim RecordCount(0 To 0)

'Get Distinct List of years
For k = 1 To MSHFlexGrid2.Rows - 1
   If MSHFlexGrid2.TextMatrix(k, 4) <> "" Then
      On Error Resume Next
         bFound = False
         For i = 0 To UBound(RecordCount())
            If Left(RecordCount(i), 4) = Left(MSHFlexGrid2.TextMatrix(k, 4), 4) Then
               bFound = True
            End If
         Next
         If bFound = False Then
            RecordCount(UBound(RecordCount())) = Left(MSHFlexGrid2.TextMatrix(k, 4), 4) & " = 0 Records"
            ReDim Preserve RecordCount(0 To UBound(RecordCount()) + 1)
         End If
      On Error GoTo 0
   End If
Next k

   
''set Count for each Distinct Year
For i = 0 To UBound(RecordCount()) - 1
   For k = 1 To MSHFlexGrid2.Rows - 1
      If Left(RecordCount(i), 4) = Left(MSHFlexGrid2.TextMatrix(k, 4), 4) Then
         rc = CInt(Replace(Right(RecordCount(i), Len(RecordCount(i)) - InStr(1, RecordCount(i), "= ") - 1), " Records", ""))
         RecordCount(i) = Left(RecordCount(i), 4) & " = " & CStr(rc + 1) & " Records"
      End If
   Next k
Next

For i = 0 To UBound(RecordCount())
   strMsg = strMsg & RecordCount(i) & vbCrLf
Next i

MsgBox strMsg

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
Comment Utility
Hello

I just tried but i have about 70 1 = 0 records
0
 
LVL 11

Author Closing Comment

by:Wilder1626
Comment Utility
Sorry i did something wrong.

it work very good.

Thanks again
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now