[RESOLVED] MSFlexGrid Search is easy, Next match is needed
Below is what I use to search MSFlexGrid for a string using Regular Expressions. Dont forget to add a reference to Microsoft VBScript Regular Expressions 5.5 to your project.
on form:
VB Code:
Private Sub Command1_Click()
'search button
On Error Resume Next
If Text1.Text <> "" Then
Dim myRow
For myRow = 0 To MSFlexGrid1.rows
If RegExTF(MSFlexGrid1.TextMatrix(myRow, 0), Text1.Text) = True Then
MSFlexGrid1.TopRow = myRow
MSFlexGrid1.Row = myRow
Exit Sub
End If
Next myRow
End If
End Sub
in module:
VB Code:
Function RegExTF(SearchThis As String, Search4This As String)
Dim ssnvar, re
ssnvar = SearchThis
Set re = New RegExp
re.Pattern = Search4This
re.Global = True
re.IgnoreCase = True
If re.Test(ssnvar) = True Then RegExTF = True Else RegExTF = False
End Function
What I need is to go to the Next match on Command1_Click if more than one match was found. Something like "Find Next" in most text editors. Is it possible?
Thank you in advance!
Re: MSFlexGrid Search is easy, Next match is needed
Works like a "Find Next" button:
VB Code:
Dim LastMatch
Private Sub Command1_Click()
'search button
On Error Resume Next
If Text1.Text <> "" Then
Dim myRow
For myRow = LastMatch To MSFlexGrid1.rows
If RegExTF(MSFlexGrid1.TextMatrix(myRow, 0), Text1.Text) = True Then
MSFlexGrid1.TopRow = myRow
MSFlexGrid1.Row = myRow
LastMatch = myRow + 1
Exit Sub
End If
Next myRow
End If
End Sub
[RESOLVED]