天天看點

vb.net中的一個組合函數

Function GetDirect(ByVal lCurrPos As Long, ByVal sSource As String, ByVal sFind As String, ByVal bPre As Boolean) As Integer

    '往前查找字元串

    Dim iLoop As Integer

    Dim iLength As Integer

    iLength = Len(sFind)

    Dim sTemp As String

    sTemp = ""

    While sFind <> sTemp

        sTemp = Mid(sSource, lCurrPos, iLength)

        If bPre = True Then

            lCurrPos = lCurrPos - 1

        Else

            lCurrPos = lCurrPos + 1

        End If

    End While

    GetDirect = lCurrPos

End Function

Function SubStringCount(ByVal sSource As String, ByVal sFind As String) As Integer

    SubStringCount = 0

    Dim iLenFind As Integer, iStart As Integer

    iLenFind = Len(sFind)

    iStart = 1

    Dim iPtr As Integer

    iPtr = 0

    Dim iPos As Integer

    iPos = InStr(iStart, sSource, sFind, CompareMethod.Text)

    If iPos > 1 Then

        SubStringCount = 1

        While (iPos)

            iPos = InStr(iPos + iLenFind, sSource, sFind, CompareMethod.Text)

            If iPos > 0 Then

                SubStringCount = SubStringCount + 1

            End If

        End While

    End If

End Function

Function GetTableValue(ByVal sTable As String, ByVal iRow As Integer, ByVal iCol As Integer) As String

    Dim iLoop As Integer

    Dim iPtr As Integer

    Dim iRowLeft As Integer

    Dim iRowRight As Integer

    Dim sRow As String

    Dim sCell As String

    iPtr = 1

    For iLoop = 1 To iRow

        iPtr = InStr(iPtr, sTable, "<tr", CompareMethod.Text)

        iPtr = iPtr + 3

    Next

    iRowLeft = iPtr - 3

    iRowRight = GetDirect(iRowLeft, sTable, "</tr>", False)

    sRow = Mid(sTable, iRowLeft, iRowRight - iRowLeft + 5 - 1)

    iPtr = 1

    For iLoop = 1 To iCol

        iPtr = InStr(iPtr, sRow, "<td", CompareMethod.Text)

        iPtr = iPtr + 3

    Next

    iRowLeft = iPtr - 3

    iRowRight = GetDirect(iRowLeft, sRow, "</td>", False)

    sCell = Mid(sRow, iRowLeft, iRowRight - iRowLeft + 5)

    iRowLeft = InStr(1, sCell, ">", CompareMethod.Text)

    iRowRight = InStr(iRowLeft, sCell, "</td>", CompareMethod.Text)

    sCell = Trim(Mid(sCell, iRowLeft + 1, iRowRight - iRowLeft - 1))

    GetTableValue = sCell

End Function