Link to home
Create AccountLog in
Avatar of Wilder1626
Wilder1626Flag for Canada

asked on

VB6 - Count records based on 2 column issue

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

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Is that all the code in the procedure? I ask because that shouldn't even take 1 second with just 14 records.
Avatar of Wilder1626

ASKER

Hi MartinLiss

Yes, just that code.

That's what is strange.
Is this new code or a new problem? By that I mean did it ever run faster? If it did then try rebooting.
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.
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?
So weird

Just removed LockWindowUpdate Me.hWnd and it takes a second to run.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Yes!!!
This is good now.

It take a second to run

Thanks again for your help
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