In operator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • voroojak
    New Member
    • Feb 2007
    • 92

    #1

    In operator

    Hi
    If i want to use IN operator in VB , then how can i use it?

    i mean i want to something like this

    If Mid(WholeLine, 22, 3) In ("JAN" ,"FEB") then

    but it gives me error.

    i would appreciate any help.
    thanks
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by voroojak
    Hi
    If i want to use IN operator in VB , then how can i use it?

    i mean i want to something like this

    If Mid(WholeLine, 22, 3) In ("JAN" ,"FEB") then

    but it gives me error.

    i would appreciate any help.
    thanks
    You can use inStr() function Like

    [CODE=vb]If inStr(1,Mid(Who leLine, 22, 3), ("JAN" ,"FEB") ) > 0 then[/CODE]

    Comment

    • voroojak
      New Member
      • Feb 2007
      • 92

      #3
      thanks
      i tried but still gives me error
      thanks alot for quick answer

      Comment

      • hariharanmca
        Top Contributor
        • Dec 2006
        • 1977

        #4
        Originally posted by voroojak
        thanks
        i tried but still gives me error
        thanks alot for quick answer
        can you post what you had tried and what is the error you are getting?

        Comment

        • voroojak
          New Member
          • Feb 2007
          • 92

          #5
          elseif inStr(1,Mid(Who leLine,22,3),(" JAN,"FEB","MAR" ,"APR"))>0 then

          and it said
          expected :)

          thanks

          Comment

          • hariharanmca
            Top Contributor
            • Dec 2006
            • 1977

            #6
            Originally posted by voroojak
            elseif inStr(1,Mid(Who leLine,22,3),(" JAN,"FEB","MAR" ,"APR"))>0 then

            and it said
            expected :)

            thanks
            I am not getting what you mean!

            What expected?

            Comment

            • voroojak
              New Member
              • Feb 2007
              • 92

              #7
              the error message is

              Expected:)

              this is my error message
              do u want me to take printscreen?

              Comment

              • mahesh123
                New Member
                • Oct 2007
                • 64

                #8
                Hi,

                Try this code. It may suitable to you.

                Switch(Mid("Sam pleTestingXXXXX XXXJAN", 22, 3) = "JAN", "JANUARY", _
                Mid("SampleTest ingXXXXXXXXJAN" , 22, 3) = "FEB", "FEBRUARY")


                Regards
                ------------
                Mahesh

                Comment

                • hariharanmca
                  Top Contributor
                  • Dec 2006
                  • 1977

                  #9
                  [CODE=vb]elseif inStr(1,Mid(Who leLine,22,3),(" JAN,"FEB","MAR" ,"APR"))>0 then[/CODE]
                  Use like this


                  [CODE=vb]elseif inStr(1,("JAN FEB MAR APR"),Mid(Whole Line,22,3))>0 then[/CODE]
                  Last edited by hariharanmca; Oct 3 '07, 05:47 AM. Reason: Code Changed To inStr(1,("JAN FEB MAR APR"),Mid(WholeLine,22,3))

                  Comment

                  • voroojak
                    New Member
                    • Feb 2007
                    • 92

                    #10
                    i will try now
                    but may i ask what is usage of that 1

                    what i want to do that if Mid(WholeLine, 22, 3) is equal to jan, feb,... dec,
                    then i be able to read that fiels and then do something
                    but i have no idead waht is the role of that 1 and why i have to say >0

                    thanks alot

                    Comment

                    • hariharanmca
                      Top Contributor
                      • Dec 2006
                      • 1977

                      #11
                      Originally posted by voroojak
                      i will try now
                      but may i ask what is usage of that 1

                      what i want to do that if Mid(WholeLine, 22, 3) is equal to jan, feb,... dec,
                      then i be able to read that fiels and then do something
                      but i have no idead waht is the role of that 1 and why i have to say >0

                      thanks alot
                      Just consider your
                      [CODE=vb]Mid(WholeLine, 22, 3) = "JAN"
                      'Then the inStr will look like
                      If InStr(1, ("JAN FEB MAR APR"), "JAN") > 0 Then
                      [/code]

                      which means
                      inStr(<Start from Char 1>,<String content As String 1>, <Search String as string 2>) > 0

                      this > 0 meant string is available else not available
                      Note : this inStr will return the possition of string 2 in string 1

                      Comment

                      • voroojak
                        New Member
                        • Feb 2007
                        • 92

                        #12
                        thanks alot for your explanation. so i shouldnt put any comma between jan and feb?
                        if i put coma then it wont work

                        thankssssssssss ssssss

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #13
                          Originally posted by voroojak
                          ... so i shouldnt put any comma between jan and feb?
                          if i put coma then it wont work
                          Actually, in this case it probably would. The Instr() function just tells you where inside a string it finds another string. If "JAN" is in there, it probably won't care whether there are commas, spaces or anything else around it.

                          Comment

                          • hariharanmca
                            Top Contributor
                            • Dec 2006
                            • 1977

                            #14
                            No, Actully he/she mean "JAN", "FEB",..... etc

                            Comment

                            • Killer42
                              Recognized Expert Expert
                              • Oct 2006
                              • 8429

                              #15
                              Originally posted by hariharanmca
                              No, Actully he/she mean "JAN", "FEB",..... etc
                              Good point. Instr() is only designed to search one string, not a bunch of them. Of course, you could easily create a function to accept an array and do a search of it like Instr() if you wanted to. It could be a useful thing to have in one's toolkit.

                              Comment

                              Working...