Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB6- Get counts of distinct value in MSHFlexgrid2

Posted on 2012-12-21
4
Medium Priority
?
353 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
ID: 38713370
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 2000 total points
ID: 38714033
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
ID: 38714120
Hello

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

Author Closing Comment

by:Wilder1626
ID: 38714403
Sorry i did something wrong.

it work very good.

Thanks again
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

877 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