Solved

VB6 - Compare MSHFlexgrid row 0 with TEXTbox no 2

Posted on 2013-01-05
4
764 Views
Last Modified: 2013-01-05
Hello all

I need to update this code based on the previous post:
VB6 - Compare MSHFlexgrid row 0 with TEXTbox

This bellow macro is validation that the MSHFlexgrid1 row ZERO will have the column header name the same as the textbox : rates1.Text

But the issue i have now is that if in the grid i have 5 column and it match the same 5 Split(rates1.Text, vbCrLf), it will say that it is good but it needs to validate if the grid header match all text from the textbox. So if i have 10 multiline in the textbox, then i need to have 10 columns in the MSHFlexgrid with the same names in the same sequence.

How can i fix this?

I tried like this but it does not validate all columns:
If MSHFlexGrid1.TextMatrix(0, lngCol) = strParts(lngIndex) Or strParts(lngIndex) = MSHFlexGrid1.TextMatrix(0, lngCol) Then

Open in new window


Thanks again

 Dim lngCol As Long
    Dim lngIndex As Long
    Dim strParts() As String
    Dim bFound As Boolean
    
    strParts = Split(rates1.Text, vbCrLf)
    For lngCol = 0 To MSHFlexGrid1.Cols - 1
        bFound = False
        For lngIndex = 0 To UBound(strParts)
            If MSHFlexGrid1.TextMatrix(0, lngCol) = strParts(lngIndex) Or strParts(lngIndex) = MSHFlexGrid1.TextMatrix(0, lngCol) Then
                bFound = True
                Exit For
               End If
        Next
        If Not bFound Then
            MsgBox "Rate header doesn't match on " & MSHFlexGrid1.TextMatrix(0, lngCol) & ". Please validate.", vbExclamation, "Header Validation"
            Exit Sub
        End If
    Next
    
     MsgBox "Rate header match.", vbMsgBoxRight, "Header Validation"

Open in new window

0
Comment
Question by:Wilder1626
  • 2
  • 2
4 Comments
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
Try this.


Private Sub rate999_Click()
    Dim lngCol As Long
    Dim lngIndex As Long
    Dim strParts() As String
    Dim bFound As Boolean
    
    strParts = Split(Text1.Text, vbCrLf)
    If UBound(strParts) + 1 <> MSHFlexGrid1.Cols Then
        MsgBox "Header doesn't match. Please validate.", vbExclamation, "Header Validation"
        Exit Sub
    End If
    For lngCol = 0 To MSHFlexGrid1.Cols - 1
        bFound = False
        For lngIndex = 0 To UBound(strParts)
            If MSHFlexGrid1.TextMatrix(0, lngCol) = strParts(lngIndex) Then
                bFound = True
                Exit For
            End If
        Next
        If Not bFound Then
            MsgBox "Header doesn't match. Please validate.", vbExclamation, "Header Validation"
            Exit Sub
        End If
    Next
End Sub

Open in new window

0
 
LVL 11

Author Comment

by:Wilder1626
Comment Utility
Hi again

I did a small update on the code.

I will just do 2 other test.

Update on code
    Dim lngCol As Long
    Dim lngIndex As Long
    Dim strParts() As String
    Dim bFound As Boolean

    strParts = Split(rates1.Text, vbCrLf)
    If UBound(strParts) <> MSHFlexGrid1.Cols Then
        MsgBox "Header doesn't match. Please validate.", vbExclamation, "Header Validation"
        Exit Sub
    End If
    For lngCol = 0 To MSHFlexGrid1.Cols - 1
        bFound = False
        For lngIndex = 0 To UBound(strParts)
            If MSHFlexGrid1.TextMatrix(0, lngCol) = strParts(lngIndex) Then
                bFound = True
                Exit For
            End If
        Next

        If Not bFound Then
            MsgBox "Header doesn't match on " & MSHFlexGrid1.TextMatrix(0, lngCol) & " column. Please validate.", vbExclamation, "Header Validation"
            Exit Sub
        End If
    Next
    Command1.Enabled = True
    MsgBox "Good match"

Open in new window

0
 
LVL 11

Author Closing Comment

by:Wilder1626
Comment Utility
Everything looks good with the update i did with your code

Thanks again for your help
always appreciated
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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 2012
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

728 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

9 Experts available now in Live!

Get 1:1 Help Now