Instr question- leaving off a letter

Z

ZigZagZak

Hello-
I have this statment in my VB behind my form.
Me.ReducerBushing = Right(Me.ReducerSheave, InStr(Me.ReducerSheave, " ")))
My textbox "ReducerSheave" would be something like : 2 3V 690 SDS.
I am trying to isolate the "SDS". Its not always 3 characters, in fact
normally its 2. When it is 2 characters (2 3V 550 SH) It works fine. I
don't understand why it matters when my instr is supposed to give me
everything after the first space from the right. I obvoiusly don't
understand exactly what my instr() asks for specifically. Can someone help
me out??? I am going nuts.

Thanks!
Zach
 
F

fredg

Hello-
I have this statment in my VB behind my form.
Me.ReducerBushing = Right(Me.ReducerSheave, InStr(Me.ReducerSheave, " ")))
My textbox "ReducerSheave" would be something like : 2 3V 690 SDS.
I am trying to isolate the "SDS". Its not always 3 characters, in fact
normally its 2. When it is 2 characters (2 3V 550 SH) It works fine. I
don't understand why it matters when my instr is supposed to give me
everything after the first space from the right. I obvoiusly don't
understand exactly what my instr() asks for specifically. Can someone help
me out??? I am going nuts.

Thanks!
Zach

Well, I see 3 spaces in your value, plus an extra closing parenthesis.
InStr() looks for the first space in the value ... from the left.
There is a space after the "2" (in 2 3V) so your expression, using
InStr() finds that first space position, which in this case is the
second position. Right(FieldName,2) returns just the last 2 characters
of the value. That's why you get the SH correctly but miss the first S
of SDS.

Try it this way, using InStrRev() +1, which looks for the first space
in the value ... from the right ... then adds one position to get the
next character after that space, in your case the first S in SDS.

The Mid function returns everything from that point on.

Me.ReducerBushing =
Mid(Me.[ReducerSheave],InStrRev(Me.[ReducerSheave], " ")+1)
 
M

Mike Painter

ZigZagZak said:
Hello-
I have this statment in my VB behind my form.
Me.ReducerBushing = Right(Me.ReducerSheave, InStr(Me.ReducerSheave, "
"))) My textbox "ReducerSheave" would be something like : 2 3V 690
SDS.
I am trying to isolate the "SDS". Its not always 3 characters, in
fact normally its 2. When it is 2 characters (2 3V 550 SH) It works
fine. I don't understand why it matters when my instr is supposed to
give me everything after the first space from the right. I obvoiusly
don't understand exactly what my instr() asks for specifically. Can
someone help me out??? I am going nuts.

Thanks!
Zach

InStr(Me.ReducerSheave, " ") returns 2 since it finds the first occurnace
of a space.
If the string is always in teh form x xx xxx aaa you could use a starting
position for the search.

While it would require a fuction call Split is ideal for this.

YourArray = Split(Reducer, " ")gives an arrary with each section in
it.YourValue = YourArray(Ubound(yourarray))
 
M

Mike Painter

ZigZagZak said:
Hello-
I have this statment in my VB behind my form.
Me.ReducerBushing = Right(Me.ReducerSheave, InStr(Me.ReducerSheave, "
"))) My textbox "ReducerSheave" would be something like : 2 3V 690
SDS.
I am trying to isolate the "SDS". Its not always 3 characters, in
fact normally its 2. When it is 2 characters (2 3V 550 SH) It works
fine. I don't understand why it matters when my instr is supposed to
give me everything after the first space from the right. I obvoiusly
don't understand exactly what my instr() asks for specifically. Can
someone help me out??? I am going nuts.

Thanks!
Zach

InStr(Me.ReducerSheave, " ") returns 2 since it finds the first occurnace
of a space.
If the string is always in teh form x xx xxx aaa you could use a starting
position for the search.

While it would require a fuction call Split is ideal for this.

YourArray = Split(Reducer, " ")gives an arrary with each section in
it.YourValue = YourArray(Ubound(yourarray))
 
K

KARL DEWEY

I think you need --
Me.ReducerBushing =
Mid(Me.[ReducerSheave],InStrRev(Me.[ReducerSheave], " ")-1)


--
Build a little, test a little.


fredg said:
Hello-
I have this statment in my VB behind my form.
Me.ReducerBushing = Right(Me.ReducerSheave, InStr(Me.ReducerSheave, " ")))
My textbox "ReducerSheave" would be something like : 2 3V 690 SDS.
I am trying to isolate the "SDS". Its not always 3 characters, in fact
normally its 2. When it is 2 characters (2 3V 550 SH) It works fine. I
don't understand why it matters when my instr is supposed to give me
everything after the first space from the right. I obvoiusly don't
understand exactly what my instr() asks for specifically. Can someone help
me out??? I am going nuts.

Thanks!
Zach

Well, I see 3 spaces in your value, plus an extra closing parenthesis.
InStr() looks for the first space in the value ... from the left.
There is a space after the "2" (in 2 3V) so your expression, using
InStr() finds that first space position, which in this case is the
second position. Right(FieldName,2) returns just the last 2 characters
of the value. That's why you get the SH correctly but miss the first S
of SDS.

Try it this way, using InStrRev() +1, which looks for the first space
in the value ... from the right ... then adds one position to get the
next character after that space, in your case the first S in SDS.

The Mid function returns everything from that point on.

Me.ReducerBushing =
Mid(Me.[ReducerSheave],InStrRev(Me.[ReducerSheave], " ")+1)


--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
.
 
K

KARL DEWEY

Read it again -- I am wrong - you are correct.
--
Build a little, test a little.


KARL DEWEY said:
I think you need --
Me.ReducerBushing =
Mid(Me.[ReducerSheave],InStrRev(Me.[ReducerSheave], " ")-1)


--
Build a little, test a little.


fredg said:
Hello-
I have this statment in my VB behind my form.
Me.ReducerBushing = Right(Me.ReducerSheave, InStr(Me.ReducerSheave, " ")))
My textbox "ReducerSheave" would be something like : 2 3V 690 SDS.
I am trying to isolate the "SDS". Its not always 3 characters, in fact
normally its 2. When it is 2 characters (2 3V 550 SH) It works fine. I
don't understand why it matters when my instr is supposed to give me
everything after the first space from the right. I obvoiusly don't
understand exactly what my instr() asks for specifically. Can someone help
me out??? I am going nuts.

Thanks!
Zach

Well, I see 3 spaces in your value, plus an extra closing parenthesis.
InStr() looks for the first space in the value ... from the left.
There is a space after the "2" (in 2 3V) so your expression, using
InStr() finds that first space position, which in this case is the
second position. Right(FieldName,2) returns just the last 2 characters
of the value. That's why you get the SH correctly but miss the first S
of SDS.

Try it this way, using InStrRev() +1, which looks for the first space
in the value ... from the right ... then adds one position to get the
next character after that space, in your case the first S in SDS.

The Mid function returns everything from that point on.

Me.ReducerBushing =
Mid(Me.[ReducerSheave],InStrRev(Me.[ReducerSheave], " ")+1)


--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top