PC Review


Reply
Thread Tools Rate Thread

InStr right to left

 
 
=?Utf-8?B?QnJhZA==?=
Guest
Posts: n/a
 
      13th May 2005
Thanks for taking the time to read my question.

How can I search for a character in a string from right to left. InStr goes
left to right.

Brad
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RGVubmlz?=
Guest
Posts: n/a
 
      13th May 2005
Use the InstrRev function but note that the paramaters are not in the same
position as the Instr function.
InStrRev(string1,string2,start,textcompare)
(Start equalling 1 means start from the first character at the back)
Check the help on InStrRev if you need more info.

"Brad" wrote:

> Thanks for taking the time to read my question.
>
> How can I search for a character in a string from right to left. InStr goes
> left to right.
>
> Brad

 
Reply With Quote
 
 
 
 
Alex Dybenko
Guest
Posts: n/a
 
      13th May 2005
There is a InStrRev() function
Returns the position of an occurrence of one string within another, from the
end of string.

--
Alex Dybenko (MVP)
http://Alex.Dybenko.com
http://www.PointLtd.com


"Brad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks for taking the time to read my question.
>
> How can I search for a character in a string from right to left. InStr
> goes
> left to right.
>
> Brad



 
Reply With Quote
 
=?Utf-8?B?QnJhZA==?=
Guest
Posts: n/a
 
      13th May 2005
Thanks Dennis!

I tried searching the help for anything like that, and it didn't come up!

Oh well, I know how to do it now thanks to you.

Have a great weekend,

Brad

"Dennis" wrote:

> Use the InstrRev function but note that the paramaters are not in the same
> position as the Instr function.
> InStrRev(string1,string2,start,textcompare)
> (Start equalling 1 means start from the first character at the back)
> Check the help on InStrRev if you need more info.
>
> "Brad" wrote:
>
> > Thanks for taking the time to read my question.
> >
> > How can I search for a character in a string from right to left. InStr goes
> > left to right.
> >
> > Brad

 
Reply With Quote
 
=?Utf-8?B?QnJhZA==?=
Guest
Posts: n/a
 
      13th May 2005
Hi Dennis,

I tried it... is that available in Access 97?

Brad

"Dennis" wrote:

> Use the InstrRev function but note that the paramaters are not in the same
> position as the Instr function.
> InStrRev(string1,string2,start,textcompare)
> (Start equalling 1 means start from the first character at the back)
> Check the help on InStrRev if you need more info.
>
> "Brad" wrote:
>
> > Thanks for taking the time to read my question.
> >
> > How can I search for a character in a string from right to left. InStr goes
> > left to right.
> >
> > Brad

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      13th May 2005
"Brad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> Hi Dennis,
>
> I tried it... is that available in Access 97?
>
> Brad
>
> "Dennis" wrote:
>
>> Use the InstrRev function but note that the paramaters are not in
>> the same position as the Instr function.
>> InStrRev(string1,string2,start,textcompare)
>> (Start equalling 1 means start from the first character at the back)
>> Check the help on InStrRev if you need more info.


No, InStrRev was introduced in Access 2000. Here's a lookalike function
that you can paste into a standard module and use in Access 97:

'----- start of code -----
Public Function InStrRev( _
StringCheck As String, _
StringMatch As String, _
Optional Start As Long = -1, _
Optional Compare As Integer = 2) _
As Long
'-----------------------------------------------------------
' Inputs: String to check,
' match string,
' optional starting position (default = -1),
' optional string compare value (default vbDatabaseCompare)
' Outputs: Position of match string, starting from the end
' Original code by: John L. Viescas 15-Nov-2001
' Revised by: Dirk Goldgar 21-Jan-2002
' Last Revision: Dirk Goldgar 21-Jan-2002
' ** Duplicates the functionality of the VB 6 INSTRREV function.
'-----------------------------------------------------------
Dim lngS As Long, lngI As Long
Dim lngLenC As Long, lngLenM As Long

' Do some initial checks
If (Compare < 0) Or (Compare > 2) Then
Err.Raise 5
Exit Function
End If
If Len(StringCheck) = 0 Then
InStrRev = 0
Exit Function
End If
If Len(StringMatch) = 0 Then
InStrRev = Start
Exit Function
End If
If Start > Len(StringCheck) Then
InStrRev = 0
Exit Function
End If
If Len(StringMatch) > Len(StringCheck) Then
InStrRev = 0
Exit Function
End If

' OK, have some work to do!
lngS = Start
lngLenC = Len(StringCheck)
lngLenM = Len(StringMatch)
If lngS = -1 Then lngS = lngLenC
lngS = (lngS - lngLenM) + 1
' Set default not found
InStrRev = 0
' Now loop to see if we can find it
For lngI = lngS To 1 Step -1
If StrComp(Mid$(StringCheck, lngI, lngLenM), _
StringMatch, _
Compare) _
= 0 _
Then
InStrRev = lngI
Exit For
End If
Next lngI

End Function
'----- end of code -----

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
=?Utf-8?B?QnJhZA==?=
Guest
Posts: n/a
 
      13th May 2005
Thanks Dirk,

Does this do the same thing?

x = 1
Do Until TheChar = "\"
If x = 1 Then
TheChar = Right(strInputFileName, x)
Else
TheChar = Left(Right(strInputFileName, x), 1)
End If
x = x + 1
Loop

Me.FileName = Right(strInputFileName, x - 2)

Brad

"Dirk Goldgar" wrote:

> "Brad" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)
> > Hi Dennis,
> >
> > I tried it... is that available in Access 97?
> >
> > Brad
> >
> > "Dennis" wrote:
> >
> >> Use the InstrRev function but note that the paramaters are not in
> >> the same position as the Instr function.
> >> InStrRev(string1,string2,start,textcompare)
> >> (Start equalling 1 means start from the first character at the back)
> >> Check the help on InStrRev if you need more info.

>
> No, InStrRev was introduced in Access 2000. Here's a lookalike function
> that you can paste into a standard module and use in Access 97:
>
> '----- start of code -----
> Public Function InStrRev( _
> StringCheck As String, _
> StringMatch As String, _
> Optional Start As Long = -1, _
> Optional Compare As Integer = 2) _
> As Long
> '-----------------------------------------------------------
> ' Inputs: String to check,
> ' match string,
> ' optional starting position (default = -1),
> ' optional string compare value (default vbDatabaseCompare)
> ' Outputs: Position of match string, starting from the end
> ' Original code by: John L. Viescas 15-Nov-2001
> ' Revised by: Dirk Goldgar 21-Jan-2002
> ' Last Revision: Dirk Goldgar 21-Jan-2002
> ' ** Duplicates the functionality of the VB 6 INSTRREV function.
> '-----------------------------------------------------------
> Dim lngS As Long, lngI As Long
> Dim lngLenC As Long, lngLenM As Long
>
> ' Do some initial checks
> If (Compare < 0) Or (Compare > 2) Then
> Err.Raise 5
> Exit Function
> End If
> If Len(StringCheck) = 0 Then
> InStrRev = 0
> Exit Function
> End If
> If Len(StringMatch) = 0 Then
> InStrRev = Start
> Exit Function
> End If
> If Start > Len(StringCheck) Then
> InStrRev = 0
> Exit Function
> End If
> If Len(StringMatch) > Len(StringCheck) Then
> InStrRev = 0
> Exit Function
> End If
>
> ' OK, have some work to do!
> lngS = Start
> lngLenC = Len(StringCheck)
> lngLenM = Len(StringMatch)
> If lngS = -1 Then lngS = lngLenC
> lngS = (lngS - lngLenM) + 1
> ' Set default not found
> InStrRev = 0
> ' Now loop to see if we can find it
> For lngI = lngS To 1 Step -1
> If StrComp(Mid$(StringCheck, lngI, lngLenM), _
> StringMatch, _
> Compare) _
> = 0 _
> Then
> InStrRev = lngI
> Exit For
> End If
> Next lngI
>
> End Function
> '----- end of code -----
>
> --
> Dirk Goldgar, MS Access MVP
> www.datagnostics.com
>
> (please reply to the newsgroup)
>
>
>

 
Reply With Quote
 
Dirk Goldgar
Guest
Posts: n/a
 
      13th May 2005
"Brad" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> Thanks Dirk,
>
> Does this do the same thing?
>
> x = 1
> Do Until TheChar = "\"
> If x = 1 Then
> TheChar = Right(strInputFileName, x)
> Else
> TheChar = Left(Right(strInputFileName, x), 1)
> End If
> x = x + 1
> Loop
>
> Me.FileName = Right(strInputFileName, x - 2)


No. What is it supposed to do? At the very least, that code runs the
risk of an infinite loop if there is no "\" character in
strInputFileName. If your purpose is to get the filename alone out of a
path specification, then *if* you can be sure that the path
specification contains a "\" character, you can use the InStrRev
function I posted as follows:

Me.FileName = _
Mid(strInputFileName, InStrRev(strInputFileName, "\") + 1)

An alternative, if you know the file exists, is to use the Dir()
function:

Me.FileName = Dir(strInputFileName)

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change the right-to-left worksheet to left-to-right workshe =?Utf-8?B?UkFNQQ==?= Microsoft Excel Misc 1 4th Jul 2005 01:57 PM
Mouse knob thinks left is right and right is left! Sameer Windows XP Hardware 1 30th Mar 2004 06:22 PM
Re: right right$ left left$ mid mid$ Phobos Microsoft Excel Programming 1 29th Jul 2003 12:07 AM
Re: right right$ left left$ mid mid$ Bill Lunney Microsoft Excel Programming 0 21st Jul 2003 10:39 PM
Re: right right$ left left$ mid mid$ Charles Williams Microsoft Excel Programming 0 21st Jul 2003 09:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:20 AM.