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
|
|
0
|
|
|
|
Reply
|
Utf
|
12/23/2009 5:08:01 PM |
|
On Wed, 23 Dec 2009 09:08:01 -0800, ZigZagZak wrote:
> 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
|
|
0
|
|
|
|
Reply
|
fredg
|
12/23/2009 5:31:06 PM
|
|
ZigZagZak wrote:
> 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))
|
|
0
|
|
|
|
Reply
|
Mike
|
12/23/2009 8:45:27 PM
|
|
ZigZagZak wrote:
> 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))
|
|
0
|
|
|
|
Reply
|
Mike
|
12/23/2009 8:45:27 PM
|
|
I think you need --
Me.ReducerBushing =
Mid(Me.[ReducerSheave],InStrRev(Me.[ReducerSheave], " ")-1)
--
Build a little, test a little.
"fredg" wrote:
> On Wed, 23 Dec 2009 09:08:01 -0800, ZigZagZak wrote:
>
> > 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
> .
>
|
|
0
|
|
|
|
Reply
|
Utf
|
12/23/2009 10:47:01 PM
|
|
Read it again -- I am wrong - you are correct.
--
Build a little, test a little.
"KARL DEWEY" wrote:
> I think you need --
> Me.ReducerBushing =
> Mid(Me.[ReducerSheave],InStrRev(Me.[ReducerSheave], " ")-1)
>
>
> --
> Build a little, test a little.
>
>
> "fredg" wrote:
>
> > On Wed, 23 Dec 2009 09:08:01 -0800, ZigZagZak wrote:
> >
> > > 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
> > .
> >
|
|
0
|
|
|
|
Reply
|
Utf
|
12/24/2009 12:02:01 AM
|
|
|
5 Replies
260 Views
(page loaded in 0.298 seconds)
|