Solved

VB6 - Compare MSHFlexgrid row 0 with TEXTbox no 2

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

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 46

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…

809 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