Solved

VB6 - Compare MSHFlexgrid row 0 with TEXTbox no 2

Posted on 2013-01-05
4
772 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
[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
  • 2
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 38747676
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
ID: 38747751
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
ID: 38747825
Everything looks good with the update i did with your code

Thanks again for your help
always appreciated
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 38747827
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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.
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…
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…

726 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