Solved

VB6 - Compare MSHFlexgrid row 0 with TEXTbox no 2

Posted on 2013-01-05
4
774 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

Independent Software Vendors: 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!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

707 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