VB6- Validate 4 fields between 2 grid

Hi all

I would like to validate by clicking on the command button 4 fields from MSHFlexgrid1 with my other grid called IB_GRID following this logic:

If Combo1 = IB_GRID column 0
and MSHFlexgrid1 column 13 = IB_GRID column 1
and MSHFlexgrid1 column 2 >= IB_GRID column 2 and <= IB_GRID column3 then

If MSHFlexgrid1 column 14 <> IB_GRID column 4 then issue.text = MSHFlexgrid1. column 3 & MSHFlexgrid1. column 14 and IB_GRID column 4.

How can i do this ?

Thanks again
Form1.zip
LVL 11
Wilder1626Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Will all the entries in IB_Grid column 0 always be the same as the value of Combo1? In other words when Combo1 = "ONTARIO" will all the entries in column 0 of IB_Grid be "ONTARIO"?
0
Martin LissOlder than dirtCommented:
Anyhow try this:


Private Sub Command1_Click()

Dim lngIB_Row As Long
Dim lngMSH_Row As Long

' This assumes that row 0 in IB_GRID is reserved for headings
For lngIB_Row = 1 To IB_GRID.Rows - 1
    If Combo1.Text = IB_GRID.TextMatrix(lngIB_Row, 0) Then
        For lngMSH_Row = 1 To MSHFlexGrid1.Rows - 1
            If MSHFlexGrid1.TextMatrix(lngMSH_Row, 13) = IB_GRID.TextMatrix(lngIB_Row, 1) And _
               MSHFlexGrid1.TextMatrix(lngMSH_Row, 2) >= IB_GRID.TextMatrix(lngIB_Row, 2) And _
               MSHFlexGrid1.TextMatrix(lngMSH_Row, 2) <= IB_GRID.TextMatrix(lngIB_Row, 3) Then
                If MSHFlexGrid1.TextMatrix(lngMSH_Row, 14) <> IB_GRID.TextMatrix(lngIB_Row, 4) Then
                    issue.Text = MSHFlexGrid1.TextMatrix(lngMSH_Row, 3) & " " & MSHFlexGrid1.TextMatrix(lngMSH_Row, 14) & " " & IB_GRID.TextMatrix(lngIB_Row, 0)
                    Exit Sub
                End If
            End If
        Next
    End If
Next
End Sub

Open in new window

0
Wilder1626Author Commented:
Hi MartinLiss,

In combo1, i have 4 values in my combo to be : WEST, ONTARIO, QUEBEC, ATLANTIC.

Those 4 values will also be the values in grid IB_GRID column 0.

It looks like it's working great.

Let me do some more test and i will let you know shortly.

Thanks again
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Wilder1626Author Commented:
Ok, i see one small issue. when it hit Exit Sub, it should still validate all the other rows from MSHFlexgrid1. Now, what it does is that as soon it found an mismatch, it stop there and dont continue to validate the other rows.



Dim lngIB_Row As Long
Dim lngMSH_Row As Long

' This assumes that row 0 in IB_GRID is reserved for headings
For lngIB_Row = 1 To IB_GRID.Rows - 1
    If Combo1.Text = IB_GRID.TextMatrix(lngIB_Row, 0) Then
        For lngMSH_Row = 1 To MSHFlexGrid1.Rows - 1
            If MSHFlexGrid1.TextMatrix(lngMSH_Row, 13) = IB_GRID.TextMatrix(lngIB_Row, 1) And _
               MSHFlexGrid1.TextMatrix(lngMSH_Row, 2) >= IB_GRID.TextMatrix(lngIB_Row, 2) And _
               MSHFlexGrid1.TextMatrix(lngMSH_Row, 2) <= IB_GRID.TextMatrix(lngIB_Row, 3) Then
                If MSHFlexGrid1.TextMatrix(lngMSH_Row, 14) <> IB_GRID.TextMatrix(lngIB_Row, 4) Then
                   issue.Text = issue.Text & vbCrLf & "Bol: " & MSHFlexGrid1.TextMatrix(lngMSH_Row, 3) & " requested with rate group: " & MSHFlexGrid1.TextMatrix(lngMSH_Row, 15) & " when it should be: " & IB_GRID.TextMatrix(lngIB_Row, 4)
                    Exit Sub
                End If
            End If
        Next
    End If
Next

Open in new window

0
Martin LissOlder than dirtCommented:
This corrects that problem


Private Sub Command1_Click()

Dim lngIB_Row As Long
Dim lngMSH_Row As Long

issue.Text = ""
' This was done in the IDE
'issue.MultiLine = True

' This assumes that row 0 in IB_GRID is reserved for headings
For lngIB_Row = 1 To IB_GRID.Rows - 1
    If Combo1.Text = IB_GRID.TextMatrix(lngIB_Row, 0) Then
        For lngMSH_Row = 1 To MSHFlexGrid1.Rows - 1
            If MSHFlexGrid1.TextMatrix(lngMSH_Row, 13) = IB_GRID.TextMatrix(lngIB_Row, 1) And _
               MSHFlexGrid1.TextMatrix(lngMSH_Row, 2) >= IB_GRID.TextMatrix(lngIB_Row, 2) And _
               MSHFlexGrid1.TextMatrix(lngMSH_Row, 2) <= IB_GRID.TextMatrix(lngIB_Row, 3) Then
                If MSHFlexGrid1.TextMatrix(lngMSH_Row, 14) <> IB_GRID.TextMatrix(lngIB_Row, 4) Then
                    issue.Text = issue.Text & _
                    MSHFlexGrid1.TextMatrix(lngMSH_Row, 3) & " " & _
                    MSHFlexGrid1.TextMatrix(lngMSH_Row, 14) & " " & _
                    IB_GRID.TextMatrix(lngIB_Row, 0) & vbCrLf
                End If
            End If
        Next
    End If
Next
End Sub

Open in new window

0
Martin LissOlder than dirtCommented:
You may like this better. It replaces the issues textbox with a 3rd grid. The two advantages of that are better formatting and the user can't change the text.
Q-28256515.vbp
0
Wilder1626Author Commented:
Hi again

sorry to ask the question but how can i open the vbp in attachment?
0
Martin LissOlder than dirtCommented:
Just double-click on it like your other VB6 projects. (I assume this is for VB6). If you have a problem here's the code. Just replace the issues textbox with another MSHFlexgrid control called mahIssues. The changes are marked with 'new


Private Sub Command1_Click()

Dim lngIB_Row As Long
Dim lngMSH_Row As Long
'new
Dim intRow As Integer

' This assumes that row 0 in IB_GRID is reserved for headings
For lngIB_Row = 1 To IB_GRID.Rows - 1
    If Combo1.Text = IB_GRID.TextMatrix(lngIB_Row, 0) Then
        For lngMSH_Row = 1 To MSHFlexGrid1.Rows - 1
            If MSHFlexGrid1.TextMatrix(lngMSH_Row, 13) = IB_GRID.TextMatrix(lngIB_Row, 1) And _
               MSHFlexGrid1.TextMatrix(lngMSH_Row, 2) >= IB_GRID.TextMatrix(lngIB_Row, 2) And _
               MSHFlexGrid1.TextMatrix(lngMSH_Row, 2) <= IB_GRID.TextMatrix(lngIB_Row, 3) Then
                If MSHFlexGrid1.TextMatrix(lngMSH_Row, 14) <> IB_GRID.TextMatrix(lngIB_Row, 4) Then
                    'new
                    intRow = intRow + 1
                    mshIssues.Rows = intRow + 1
                    mshIssues.TextMatrix(intRow, 0) = MSHFlexGrid1.TextMatrix(lngMSH_Row, 3)
                    mshIssues.TextMatrix(intRow, 1) = MSHFlexGrid1.TextMatrix(lngMSH_Row, 14)
                    mshIssues.TextMatrix(intRow, 2) = IB_GRID.TextMatrix(lngIB_Row, 0)

                End If
            End If
        Next
    End If
Next
End Sub

Private Sub Form_Load()

MSHFlexGrid1.TextMatrix(0, 0) = "Type of load"
MSHFlexGrid1.TextMatrix(0, 1) = "PO(s) / Order #"
MSHFlexGrid1.TextMatrix(0, 2) = "Miles"
MSHFlexGrid1.TextMatrix(0, 3) = "BOL"
MSHFlexGrid1.TextMatrix(0, 4) = "Pickup Date"
MSHFlexGrid1.TextMatrix(0, 5) = "Delivery Date and Time"
MSHFlexGrid1.TextMatrix(0, 6) = "Load Origin ID"
MSHFlexGrid1.TextMatrix(0, 7) = "Load Origin city"
MSHFlexGrid1.TextMatrix(0, 8) = "Load Destination ID"
MSHFlexGrid1.TextMatrix(0, 9) = "Load Destination postal 7"
MSHFlexGrid1.TextMatrix(0, 10) = "TMS Carrier ID"
MSHFlexGrid1.TextMatrix(0, 11) = "Rate without fuel"
MSHFlexGrid1.TextMatrix(0, 12) = "Equipment ID"
MSHFlexGrid1.TextMatrix(0, 13) = "Commodity classes"
MSHFlexGrid1.TextMatrix(0, 14) = "Rate Group"
MSHFlexGrid1.TextMatrix(0, 15) = "Number of stop included in rate"


MSHFlexGrid1.TextMatrix(1, 0) = "INBOUND_DRY"
MSHFlexGrid1.TextMatrix(1, 1) = "123456"
MSHFlexGrid1.TextMatrix(1, 2) = "105"
MSHFlexGrid1.TextMatrix(1, 3) = "00015493266M"
MSHFlexGrid1.TextMatrix(1, 4) = "9/30/2013"
MSHFlexGrid1.TextMatrix(1, 5) = "1/10/2013"
MSHFlexGrid1.TextMatrix(1, 6) = "AFFILIATED"
MSHFlexGrid1.TextMatrix(1, 7) = "LAVAL"
MSHFlexGrid1.TextMatrix(1, 8) = "28"
MSHFlexGrid1.TextMatrix(1, 9) = "L1W 4C1"
MSHFlexGrid1.TextMatrix(1, 10) = "TRNSTAT"
MSHFlexGrid1.TextMatrix(1, 11) = "525"
MSHFlexGrid1.TextMatrix(1, 12) = "TL2X_53DRX"
MSHFlexGrid1.TextMatrix(1, 13) = "DRY"
MSHFlexGrid1.TextMatrix(1, 14) = "004-20-2081:-IB-Ont -Shorthaul Dry (101-599 miles)"
MSHFlexGrid1.TextMatrix(1, 15) = ""

MSHFlexGrid1.TextMatrix(2, 0) = "INBOUND_DRY"
MSHFlexGrid1.TextMatrix(2, 1) = "123456"
MSHFlexGrid1.TextMatrix(2, 2) = "99"
MSHFlexGrid1.TextMatrix(2, 3) = "00015493266M"
MSHFlexGrid1.TextMatrix(2, 4) = "9/30/2013"
MSHFlexGrid1.TextMatrix(2, 5) = "1/10/2013"
MSHFlexGrid1.TextMatrix(2, 6) = "AFFILIATED"
MSHFlexGrid1.TextMatrix(2, 7) = "LAVAL"
MSHFlexGrid1.TextMatrix(2, 8) = "28"
MSHFlexGrid1.TextMatrix(2, 9) = "L1W 4C1"
MSHFlexGrid1.TextMatrix(2, 10) = "TRNSTAT"
MSHFlexGrid1.TextMatrix(2, 11) = "525"
MSHFlexGrid1.TextMatrix(2, 12) = "TL2X_53DRX"
MSHFlexGrid1.TextMatrix(2, 13) = "DRY"
MSHFlexGrid1.TextMatrix(2, 14) = "004-20-2088:-IB-ONT -LONGHAUL DRY (+ 600 MILES)"
MSHFlexGrid1.TextMatrix(2, 15) = ""

'Auto column fit
Dim c As Long
Dim r As Long
    For c = 0 To MSHFlexGrid1.Cols - 1
        col_wid = 0
        For r = 0 To MSHFlexGrid1.Rows - 1
            cell_wid = TextWidth(MSHFlexGrid1.TextMatrix(r, c))
            If col_wid < cell_wid Then col_wid = cell_wid
        Next r
        MSHFlexGrid1.ColWidth(c) = col_wid + 120
    Next c
    
    
IB_GRID.TextMatrix(1, 0) = "ONTARIO"
IB_GRID.TextMatrix(1, 1) = "DRY"
IB_GRID.TextMatrix(1, 2) = "0"
IB_GRID.TextMatrix(1, 3) = "100"
IB_GRID.TextMatrix(1, 4) = "004-20-2080:-IB-ONT -LOCAL DRY (0-100 MILES)"
IB_GRID.TextMatrix(2, 0) = "ONTARIO"
IB_GRID.TextMatrix(2, 1) = "DRY"
IB_GRID.TextMatrix(2, 2) = "101"
IB_GRID.TextMatrix(2, 3) = "599"
IB_GRID.TextMatrix(2, 4) = "004-20-2081:-IB-ONT -SHORTHAUL DRY (101-599 MILES)"
IB_GRID.TextMatrix(3, 0) = "ONTARIO"
IB_GRID.TextMatrix(3, 1) = "DRY"
IB_GRID.TextMatrix(3, 2) = "600"
IB_GRID.TextMatrix(3, 3) = "10000"
IB_GRID.TextMatrix(3, 4) = "004-20-2088:-IB-ONT -LONGHAUL DRY (+ 600 MILES)"
'new
IB_GRID.TextMatrix(0, 0) = "Location" ' I didn't know what to call this column

 For c = 0 To IB_GRID.Cols - 1
        col_wid = 0
        For r = 0 To IB_GRID.Rows - 1
            cell_wid = TextWidth(IB_GRID.TextMatrix(r, c))
            If col_wid < cell_wid Then col_wid = cell_wid
        Next r
        IB_GRID.ColWidth(c) = col_wid + 120
    Next c
    
'new
mshIssues.ColWidth(0) = MSHFlexGrid1.ColWidth(3)
mshIssues.TextMatrix(0, 0) = MSHFlexGrid1.TextMatrix(0, 3)
mshIssues.ColWidth(1) = MSHFlexGrid1.ColWidth(14)
mshIssues.TextMatrix(0, 1) = MSHFlexGrid1.TextMatrix(0, 14)
mshIssues.ColWidth(2) = IB_GRID.ColWidth(0)
mshIssues.TextMatrix(0, 2) = IB_GRID.TextMatrix(0, 0)
' Remove the highlighting from column 0
mshIssues.FixedCols = 0
' Adjust the grid total width to be the sum of the column widths plus the bevel width
mshIssues.Width = mshIssues.ColWidth(0) + mshIssues.ColWidth(1) + mshIssues.ColWidth(2) + 90
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Wilder1626Author Commented:
Thanks, i'm seeing that with firefox, the link don't work.

OK let me take a look at this now and i will let you know.
0
Martin LissOlder than dirtCommented:
If you click here you can download a copy of my vbp file.
0
Wilder1626Author Commented:
Thanks a lot for your help. again, this is working great.
0
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.