Solved

VB6 - Count records based on 2 column issue

Posted on 2013-05-12
9
345 Views
Last Modified: 2013-05-12
Hello all

I have this code bellow that looks at 2 columns in my grid and based on 3 criteria, it counts the number of records.

But my problem is that it takes about 5 minutes to count when i only have 14 rows in my grid.
That should take seconds to count.

Would you know why?

Can i improve that code to run faster?

Thanks again



 Dim lngRow1 As Long
    Dim lngRow2 As Long

    ' MSHFlexGrid1.WordWrap = True
    LockWindowUpdate Me.hWnd


    For lngRow1 = 1 To MSHFlexGrid1.Rows - 1
        'PO planned without a personnal rate
        If MSHFlexGrid1.TextMatrix(lngRow1, 7) = "S" And MSHFlexGrid1.TextMatrix(lngRow1, 20) = "0" Then
            po_plan_without_rate = po_plan_without_rate + 1
        End If

        'PO not planned with rate
        If MSHFlexGrid1.TextMatrix(lngRow1, 7) <> "S" And MSHFlexGrid1.TextMatrix(lngRow1, 20) <> "0" Then
            Text3 = po_plan_without_rate + 1
        End If

        'PO not planned with no rates
        If MSHFlexGrid1.TextMatrix(lngRow1, 7) <> "S" And MSHFlexGrid1.TextMatrix(lngRow1, 20) = "0" Then
            Text4 = po_plan_without_rate + 1
        End If
    Next

Open in new window

0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39159996
Is that all the code in the procedure? I ask because that shouldn't even take 1 second with just 14 records.
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39159997
Hi MartinLiss

Yes, just that code.

That's what is strange.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39159999
Is this new code or a new problem? By that I mean did it ever run faster? If it did then try rebooting.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:Wilder1626
ID: 39160003
no, this is a new code. I have other code, bigger and it run faster that the one that cause me issue.

Pretty weird i would say.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39160009
Yes I agree. Can you attach your project and tell me how to trigger that code?

Also I assume that po_plan_without_rate is a variable and not a Function or Private Property, right?
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 39160015
So weird

Just removed LockWindowUpdate Me.hWnd and it takes a second to run.
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39160020
That's good. Try this which should be faster.

    Dim lngRow1 As Long
    Dim lngRow2 As Long

    ' MSHFlexGrid1.WordWrap = True
    LockWindowUpdate Me.hWnd


    For lngRow1 = 1 To MSHFlexGrid1.Rows - 1
        Select Case True
            'PO planned without a personnal rate
            Case MSHFlexGrid1.TextMatrix(lngRow1, 7) = "S" And MSHFlexGrid1.TextMatrix(lngRow1, 20) = "0"
                po_plan_without_rate = po_plan_without_rate + 1
            'PO not planned with rate
            Case MSHFlexGrid1.TextMatrix(lngRow1, 7) <> "S" And MSHFlexGrid1.TextMatrix(lngRow1, 20) <> "0"
                Text3 = po_plan_without_rate + 1
            'PO not planned with no rates
            Case MSHFlexGrid1.TextMatrix(lngRow1, 7) <> "S" And MSHFlexGrid1.TextMatrix(lngRow1, 20) = "0"
                Text4 = po_plan_without_rate + 1
        End Select
    Next

Open in new window


Try putting the LockwindowUpdate back in and adding this at the end

LockWindowUpdate &0
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 39160023
Yes!!!
This is good now.

It take a second to run

Thanks again for your help
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39160024
You're welcome and I'm glad I was able to help.

Select the 'About Me' tab in my profile and you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2013
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

756 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