Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

InStrRev Not Working....

Status
Not open for further replies.

AccessGuruCarl

Programmer
Jul 3, 2004
471
US
Hello,
Can someone tell me why this code isn't working.

Dim x, y
Dim strSpace As String
strSpace = Chr(32)
x = " Ballston Lake, New York 12019"
x = Trim(x)
y = InStrRev(x, strSpace)

Should return 5, but it's returning 24

If I use InStr it works fine.

Thanks...

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Perhaps I am missing your point, but
InStrRev Function
Description

Returns the position of an occurrence of one string within another, from the end of string.

Which would be the space between 'York' and '12019' yes no?

 
No it works as advertised.
24 is the position of the first space from the right.
It is not a backward position
How about this
y=len(x)-InStrRev(x, " ")
 
AccessGuruCarl

I think you are confusing the direction of the search and the position. Position of chars in a string is measured from the left.

THe search begins from the end of "x". That is starting at the 9 in 12019. The first space is 5 chars away, but that is position 24 in "x".

x="Ballston Lake, New York 12019"
 
Maybe this is what you want

Public Function stripFromRight(theString As String, Optional theDelimiter As String = " ") As String
theString = Trim(theString)
stripFromRight = Mid(theString, InStrRev(theString, theDelimiter) + 1)
End Function

?stripFromRight(" 123 The-String 1234"," ")
1234

?stripFromRight(" 123 The-String 1234","-")
String 1234

?stripFromRight(" 123 The-String 1234")
1234
 
Thanks For the help....

MajP & jedraw, I was thinking in reverse....

It's been while since I've played with VBA

MajP, I like the use of the Function, I have a universal one I beleive I found here at Tek-Tips. It is in use, but I posted my test code(the string in question), after I was receiving undiserable results.

I will be placing another post, if I can't locate anything regarding looping all the text files in a folder. Open it, read it into access, close it. Open the next one... If you have any idea's or links that may help. Please post...

FYI... I'm already reading one at a time, I have to manually select each file, I'd like to automate this to read each file in the folder, so I can run a batch instead.

Thanks Again...

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Use the advance search feature on this site. I have seen a lot of post about reading all the text files in a directory and then posting into access. The regular search feature does not work well on this site, but the advanced one is OK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top