helpeachother
Programmer
Hi, Everyone:
Thank you so much for your help with my debug question posted yesterday. I am sorry that I need your help again.
The following is a function a wrote in VB.NET to use the regular expression to get a few numbers from a block of text I grabed from a table on our intranet. It supposes to grab the 1st, 4th, 8th and 9th number on the row of the table that matches the searchDate. (see the code below.)
However, when I test the code, it does not go through the " If num.Count > 1 Then" loop. It seems that the regExp of numPattern does not get a match, but it should. Can anyone help mw with this?
Thanks,
KHWright
Function getMemoryData(ByVal block As String, ByVal searchDate As String) As String()
Dim matches, num As System.Text.RegularExpressions.MatchCollection
Dim regExp As Regex
Dim datePattern, numPattern, temp, mData(3) As String
datePattern = "<td[^>]*>(\d\d\d\d)(\d\d)(\d\d) \d\d:\d\d:\d\d</td>"
numPattern = "<td align=middle>(\d+)\s*</td>\s*<td align=middle>\d+\s*</td>\s*<td align=middle>\d+\s*</td>" + _
"\s*<td align=middle>(\d+)\s*</td>\s*<td align=middle>\d+\s*</td>\s*<td align=middle>\d+\s+</td>" + _
"\s*<td align=middle>\d+\s*</td>\s*<td align=middle>(\d+)\s*</td>\s*<td align=middle>(\d+)\s*</td>"
mData(0) = "" : mData(1) = "" : mData(2) = "" : mData(3) = ""
regExp = New Regex(datePattern)
matches = regExp.Matches(block)
regExp = Nothing
'Only do this if there was a result from MTX Memory page
For Each m As Match In matches 'process matches
temp = m.Value
If InStr(1, temp, searchDate, CompareMethod.Text) > 0 Then
regExp = New Regex(numPattern) 'establish a regular expression
num = regExp.Matches(temp) 'get your matches
'Grab the last two numbers. these should be your Max & Avg
If num.Count > 1 Then
'DS = 1 PS = 4 : Spare = 7 : Provision = 8
mData(0) = num(num.Count - 3).Value
mData(1) = num(num.Count - 2).Value
mData(2) = num(num.Count - 1).Value
mData(3) = num(num.Count - 0).Value
End If
End If
Next
Return (mData)
End Function
Thank you so much for your help with my debug question posted yesterday. I am sorry that I need your help again.
The following is a function a wrote in VB.NET to use the regular expression to get a few numbers from a block of text I grabed from a table on our intranet. It supposes to grab the 1st, 4th, 8th and 9th number on the row of the table that matches the searchDate. (see the code below.)
However, when I test the code, it does not go through the " If num.Count > 1 Then" loop. It seems that the regExp of numPattern does not get a match, but it should. Can anyone help mw with this?
Thanks,
KHWright
Function getMemoryData(ByVal block As String, ByVal searchDate As String) As String()
Dim matches, num As System.Text.RegularExpressions.MatchCollection
Dim regExp As Regex
Dim datePattern, numPattern, temp, mData(3) As String
datePattern = "<td[^>]*>(\d\d\d\d)(\d\d)(\d\d) \d\d:\d\d:\d\d</td>"
numPattern = "<td align=middle>(\d+)\s*</td>\s*<td align=middle>\d+\s*</td>\s*<td align=middle>\d+\s*</td>" + _
"\s*<td align=middle>(\d+)\s*</td>\s*<td align=middle>\d+\s*</td>\s*<td align=middle>\d+\s+</td>" + _
"\s*<td align=middle>\d+\s*</td>\s*<td align=middle>(\d+)\s*</td>\s*<td align=middle>(\d+)\s*</td>"
mData(0) = "" : mData(1) = "" : mData(2) = "" : mData(3) = ""
regExp = New Regex(datePattern)
matches = regExp.Matches(block)
regExp = Nothing
'Only do this if there was a result from MTX Memory page
For Each m As Match In matches 'process matches
temp = m.Value
If InStr(1, temp, searchDate, CompareMethod.Text) > 0 Then
regExp = New Regex(numPattern) 'establish a regular expression
num = regExp.Matches(temp) 'get your matches
'Grab the last two numbers. these should be your Max & Avg
If num.Count > 1 Then
'DS = 1 PS = 4 : Spare = 7 : Provision = 8
mData(0) = num(num.Count - 3).Value
mData(1) = num(num.Count - 2).Value
mData(2) = num(num.Count - 1).Value
mData(3) = num(num.Count - 0).Value
End If
End If
Next
Return (mData)
End Function