By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

Is second token odd

P: n/a
Suppose I have a string "12-34 56th Loway" and I want to know if 4 is odd.

Is there someway to do it with STR$ and MID$ &al

Sep 21 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Assuming the 4 is always in the 5th position, you can use:
If Left([MyString],5) Mod 2 <0 Then
MsgBox "The Fifth Character Of MyString Is Odd"
End If

Steve

<vj*****@at.BioStrategist.dot.dot.comwrote in message
news:gb**********@reader1.panix.com...
Suppose I have a string "12-34 56th Loway" and I want to know if 4 is odd.

Is there someway to do it with STR$ and MID$ &al

Sep 21 '08 #2

P: n/a
On Sun, 21 Sep 2008 19:13:50 +0000 (UTC),
vj*****@at.BioStrategist.dot.dot.com wrote:

If you want to know if 4 is odd:
debug.print (4 mod 2 = 1)

You probably didn't mean to ask that question. What did you want to
ask? What would you consider a token in your example?

-Tom.
Microsoft Access MVP

>Suppose I have a string "12-34 56th Loway" and I want to know if 4 is odd.

Is there someway to do it with STR$ and MID$ &al
Sep 21 '08 #3

P: n/a
Stevie; you really do not know anything about programming.

Your Left command will create a string that includes a dash and you should
get a type error when you try to use that string in a numeric expression.

txt = Mid(originalstring, 5, 1)

' There should be a test her to make sure that txt is a numeric

If txt Mod 2 <0 Then
Debug.Print "The Fifth Character Of MyString Is Odd"
End If

John... Visio MVP

"Steve" <no******@nomsense.comwrote in message
news:Tq******************************@earthlink.co m...
Assuming the 4 is always in the 5th position, you can use:
If Left([MyString],5) Mod 2 <0 Then
MsgBox "The Fifth Character Of MyString Is Odd"
End If

Steve

<vj*****@at.BioStrategist.dot.dot.comwrote in message
news:gb**********@reader1.panix.com...
>Suppose I have a string "12-34 56th Loway" and I want to know if 4 is
odd.

Is there someway to do it with STR$ and MID$ &al


Sep 22 '08 #4

P: n/a
*+-If Left([MyString],5) Mod 2 <0 Then

Well, no, that's why I wanted to parse the second token
(ie, the first token end with a hyphen, the second with a space)

More generally, what are the functions Left, Mid & al "called"?
I remember them from GWBasic, and I know they are MicroSoft specific
but not SQL specific.

- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for Bimbos]
Sep 22 '08 #5

P: n/a
<vj*****@at.BioStrategist.dot.dot.comwrote in message
news:gb**********@reader1.panix.com...
*+-If Left([MyString],5) Mod 2 <0 Then

Well, no, that's why I wanted to parse the second token
(ie, the first token end with a hyphen, the second with a space)

More generally, what are the functions Left, Mid & al "called"?
I remember them from GWBasic, and I know they are MicroSoft specific
but not SQL specific.

- = -
Vasos Panagiotopoulos, Columbia'81+, Reagan, Mozart, Pindus, BioStrategist
http://ourworld.compuserve.com/homepages/vjp2/vasos.htm
---{Nothing herein constitutes advice. Everything fully disclaimed.}---
[Homeland Security means private firearms not lazy obstructive guards]
[Urb sprawl confounds terror] [Remorse begets zeal] [Windows is for
Bimbos]

Are you trying to work out which houses are on the left and which on the
right side of the street?

Left(str,3) will give you the three characters on the left of the string
Right(str,3) will give you the three characters on the right of the string
Mid(str,4,2) will give you two characters starting at position 4
Mid(str,4) will give you all the characters starting at position 4 to the
end of the string
INSTR(str," ") will give you the position of a string in another string

So to answer your original question you may want something like:
Txt = "12-34 fred"
i = InStr(Txt, " ")
Tmpstr = Mid(Txt, i - 1, 1)
if Tmpstr Mod 2 then

Though you could combine the formulas into one, it is safer to keep them
seperate so you could do some error checking.
What if there is no space in the string?
What if the first character is a string?
What if Tmpstr is not numeric?

John... Visio MVP

Sep 22 '08 #6

P: n/a
vj*****@at.BioStrategist.dot.dot.com wrote:
>Suppose I have a string "12-34 56th Loway" and I want to know if 4 is odd.

Is there someway to do it with STR$ and MID$ &al
The problem is about about "314-1376 51st Avenue" which is a made up address in
Alberta. Then there is "1436 51st Avenue" Then there is "313 134 Grove Ave"
Then there is "313B Grove Ave" for the bsmt suite. Then "1446 51B Street" And so
forth.

There are a lot of permutations on this. And no matter how complex there will always
be typos.

Best thing to do is to work on the number of spaces and separate out the components
and then have a person review these especially the oddballs.

Also there is a surprisingly good idea of how complex it can get at the Canada Post
website. http://canadapost.ca/Personal/Tools/Pcl/Advanced.aspx Likely your
governments post office website has similar information.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Sep 23 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.