Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Public Function Extract(Source As String, LeftExtracts As String, RightExtracts As String, Optional StartFrom As String = "1", Optional ExtractAll As Boolean = False) As String
- On Error Resume Next
- ' ################## '
- ' # Declarations # '
- ' ################## '
- Dim lngLeft As Long
- Dim lngRight As Long
- Dim strReturned As String
- Dim lngExtracts(0 To 2) As Long
- Dim TempText(0 To 2) As String
- ' ------------------------------------------------------------ '
- Select Case ExtractAll
- Case False
- If StartFrom <= 0 Then
- ' Invalid StartFrom point '
- MsgBox "Error:" & vbNewLine & vbNewLine _
- & "Invalid Start Point"
- Exit Function
- ElseIf Source = Empty Then
- ' Nothing in the source '
- MsgBox "Error:" & vbNewLine & vbNewLine _
- & "Nothing to compare with.."
- Exit Function
- End If
- ' Gets the numbering of the left string for Mid '
- lngExtracts(0) = InStr(StartFrom, Source, LeftExtracts, vbTextCompare) + Len(LeftExtracts)
- ' Gets the numbering of the right string for Mid '
- lngExtracts(1) = InStr(StartFrom, Source, RightExtracts, vbTextCompare)
- ' A Few Checks Below '
- ' Left String '
- If LeftExtracts = Empty Then
- MsgBox "Error:" & vbNewLine & vbNewLine _
- & "Left Extraction String Not Found..."
- Exit Function
- ' Right String '
- ElseIf RightExtracts = Empty Then
- MsgBox "Error:" & vbNewLine & vbNewLine _
- & "Right Extraction String Not Found..."
- End If
- ' Gets the String in the middle of both strings in LeftExtracts, and RightExtracts '
- Extract = Mid$(Source, lngExtracts(0), lngExtracts(1) - lngExtracts(0))
- ' One last check to make sure all goes well '
- If Extract = Empty Then
- Extract = "No Text could be returned..."
- End If
- Exit Function
- Case True
- 'Extract All
- MsgBox "Not coded yet.."
- End Select
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement