Is second token odd

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vjp2.at@at.BioStrategist.dot.dot.com

    Is second token odd

    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

  • Steve

    #2
    Re: Is second token odd

    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

    <vjp2.at@at.Bio Strategist.dot. dot.comwrote in message
    news:gb66de$r33 $2@reader1.pani x.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
    >

    Comment

    • Tom van Stiphout

      #3
      Re: Is second token odd

      On Sun, 21 Sep 2008 19:13:50 +0000 (UTC),
      vjp2.at@at.BioS trategist.dot.d ot.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

      Comment

      • John Marshall, MVP

        #4
        Re: Is second token odd

        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(originalstr ing, 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" <nonsense@nomse nse.comwrote in message
        news:TqKdnZCkef VAPUvVnZ2dnUVZ_ s7inZ2d@earthli nk.com...
        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
        >
        <vjp2.at@at.Bio Strategist.dot. dot.comwrote in message
        news:gb66de$r33 $2@reader1.pani x.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
        >>
        >
        >

        Comment

        • vjp2.at@at.BioStrategist.dot.dot.com

          #5
          Re: Is second token odd

          *+-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

          ---{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]

          Comment

          • John Marshall, MVP

            #6
            Re: Is second token odd

            <vjp2.at@at.Bio Strategist.dot. dot.comwrote in message
            news:gb73fq$h72 $1@reader1.pani x.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

            ---{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

            Comment

            • Tony Toews [MVP]

              #7
              Re: Is second token odd

              vjp2.at@at.BioS trategist.dot.d ot.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

              Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/

              Comment

              Working...