Re: Searching from right - code mod please!
- From: "Douglas J. Steele" <NOSPAM_djsteele@xxxxxxxxxxxxxxxx>
- Date: Tue, 21 Apr 2009 17:32:32 -0400
Not sure that helps with the issue of no third forward slash.
I haven't tested the following very thoroughly, but I think it does what's
wanted:
Function RAT(strSearchIn As String, _
strDelimiter As String, _
occurences As Long _
) As Integer
Dim varInput As Variant
varInput = Split(strSearchIn, strDelimiter)
If occurences >= 0 And _
UBound(varInput) >= occurences Then
RAT = varInput(occurences)
End If
End Function
?Rat("1/2345/6/78", "/", 3)
78
?Rat("1/2345/6", "/", 3)
0
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)
"KARL DEWEY" <KARLDEWEY@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:97E9CBCD-E2FC-4DFD-ADA5-00A17A07C3D8@xxxxxxxxxxxxxxxx
Without the code you can do it this way --
Mid([YourField], InstrRev([YourField], "/")+1)
InstrRev starts looking from right for the character and returns the
position from the left.
"andy.bayley@xxxxxxxxx" wrote:
Hi
I'm using this bit of code (thanks to Lyle Fairfield) to help me find
the text after the third forward slash in a field.
An example field may be 1/2345/6/78 - and I wish to return 78.
Please could someone let me know hot to amend this code so that if
there is no third forward slash, the function will return a zero?
Currently it returns some other number!
Function RAT(strSearchIn As String, strSearchFor As String, occurences
As Long)
As Integer
Dim aSearchIn() As Byte, intCounter As Integer, bytSearchFor As
Byte
Dim occurence As Long
For occurence = 1 To occurences
aSearchIn = StrConv(strSearchIn, vbFromUnicode)
bytSearchFor = Asc(strSearchFor)
For intCounter = UBound(aSearchIn) To LBound(aSearchIn) Step -1
If aSearchIn(intCounter) = bytSearchFor Then
RAT = intCounter + 1
Exit For
End If
Next intCounter
Next
End Function
Thanks!
Andy.
.
- Follow-Ups:
- Re: Searching from right - code mod please!
- From: andy . bayley
- Re: Searching from right - code mod please!
- References:
- Searching from right - code mod please!
- From: andy . bayley
- RE: Searching from right - code mod please!
- From: KARL DEWEY
- Searching from right - code mod please!
- Prev by Date: RE: Searching from right - code mod please!
- Next by Date: form field update from time fields
- Previous by thread: RE: Searching from right - code mod please!
- Next by thread: Re: Searching from right - code mod please!
- Index(es):
Relevant Pages
|