Announcement

Collapse
No announcement yet.

Need help using Or in an If Statement

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help using Or in an If Statement

    Need some help guy's.

    I have created a script that inserts a string into an array and depending on the first letter of that string will insert the correct folder name into another string value.

    Code:
    If strCustomerName = "CUSTOMER" then 
    	strfolderName = strYear & "_" & "CUSTOMER"
    elseif arrCustName(0) = "A" Or "B" Or "C" Or "D" Or "E" then 
    	strfolderName = strYear & "_" & "A-E"
    elseif arrCustName(0) = "F" Or "G" Or "H" Or "I" Or "J" then 
    	strfolderName = strYear & "_" & "F-J"
    elseif arrCustName(0) = "K" Or "L" Or "M" Or "N" Or "O" then 
    	strfolderName = strYear & "_" & "K-O"
    elseif arrCustName(0) = "P" Or "Q" Or "R" Or "S" Or "T" then 
    	strfolderName = strYear & "_" & "P-T"
    elseif arrCustName(0) = "U" Or "V" Or "W" Or "X" Or "Y" Or "Z" then 
    	strfolderName = strYear & "_" & "U-Z"
    end if
    All of my code works if i comment out from the Or after "A" and use a customer name beginning with "A".

    What i want to do is check to see if the value stored in arrCusName(0) is equal to A or B or C or D or E to be put into the folder marked A-E however when i run the above code i get a type mismatch: '[string: "B"]' code 800A000D.

    Any help will be appreciated.

  • #2
    Re: Need help using Or in an If Statement

    I wish i would take my stoopid hat off at times.

    Code:
    If strCustomerName = "Customer" then 
    	strfolderName = strYear & "_" & "Customer"
    elseif arrCustName(0) = "A" Or arrCustName(0) = "B" Or arrCustName(0) = "C" Or arrCustName(0) = "D" Or arrCustName(0) = "E" then 
    	strfolderName = strYear & "_" & "A-E"
    elseif arrCustName(0) = "F" Or arrCustName(0) = "G" Or arrCustName(0) = "H" Or arrCustName(0) = "I" Or arrCustName(0) = "J" then 
    	strfolderName = strYear & "_" & "F-J"
    elseif arrCustName(0) = "K" Or arrCustName(0) = "L" Or arrCustName(0) = "M" Or arrCustName(0) = "N" Or arrCustName(0) = "O" then 
    	strfolderName = strYear & "_" & "K-O"
    elseif arrCustName(0) = "P" Or arrCustName(0) = "Q" Or arrCustName(0) = "R" Or arrCustName(0) = "S" Or arrCustName(0) = "T" then 
    	strfolderName = strYear & "_" & "P-T"
    elseif arrCustName(0) = "U" Or arrCustName(0) = "V" Or arrCustName(0) = "W" Or arrCustName(0) = "X" Or arrCustName(0) = "Y" Or arrCustName(0) = "Z" then 
    	strfolderName = strYear & "_" & "U-Z"
    end if
    This is how it should be.

    Damn fool!!!!!!!!!

    Comment


    • #3
      Re: Need help using Or in an If Statement

      How about something like:

      Code:
      select case arrCustName(0)
         case "A", "B", "C", "D", "E"
               .....
         case "F", "G", 
      
         ...you get the idea....
      
         case Else
      
      
      end select

      http://www.devguru.com/Technologies/...electcase.html
      Tom Jones
      MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
      PhD, MSc, FIAP, MIITT
      IT Trainer / Consultant
      Ossian Ltd
      Scotland

      ** Remember to give credit where credit is due and leave reputation points where appropriate **

      Comment


      • #4
        Re: Need help using Or in an If Statement

        Originally posted by Ossian View Post
        How about something like:

        Code:
        select case arrCustName(0)
           case "A", "B", "C", "D", "E"
                 .....
           case "F", "G", 
        
           ...you get the idea....
        
           case Else
        
        
        end select

        http://www.devguru.com/Technologies/...electcase.html
        Now there's a man with a plan.

        I'll get changing it just now.

        Cheers Tom.

        Comment


        • #5
          Re: Need help using Or in an If Statement

          I wish i would take my stoopid hat off at times.
          Script happens, welcome to the club.


          I was wondering why spending extra lines to create an array of all the characters in the string if you only use the first character?

          Wouldn't it be easier then to use:
          select case UCase(Left(strCustomerName,1))
          case "A", "B", "C", "D", "E"
          .....


          I can imagine that people reading your script snippet are curious how you managed to created that array from a string. Is there a secret trick?
          I can only come up with two methods;

          - Using a loop to fill an array:
          Do until intSize = Len(strCustomerName)
          ReDim Preserve arrCustName(intSize)
          arrCustName(intSize) = Mid(strCustomerName,intSize+1 ,1)
          intSize = intSize + 1
          Loop
          select case UCase(arrCustName(0))
          case "A", "B", "C", "D", "E"
          .....


          - Using a regular expression pattern
          Set oRE = New Regexp
          oRE.Pattern = "." : oRE.Global = True
          Set colCustName = oRE.Execute(strCustomerName)
          select case UCase(colCustName(0))
          case "A", "B", "C", "D", "E"
          .....



          BTW
          Your code in the second post starts with a string comparison. String comparison is always case-sensitive that is why it is better to forse to all upper-case or all lower-case characters in these cases.
          If UCase(strCustomerName) = "CUSTOMER" then

          \Rems
          Last edited by Rems; 31st August 2007, 21:01.

          This posting is provided "AS IS" with no warranties, and confers no rights.

          __________________

          ** Remember to give credit where credit's due **
          and leave Reputation Points for meaningful posts

          Comment


          • #6
            Re: Need help using Or in an If Statement

            Originally posted by Rems View Post
            Script happens, welcome to the club.


            I was wondering why spending extra lines to create an array of all the characters in the string if you only use the first character?

            Wouldn't it be easier then to use:
            select case UCase(Left(strCustomerName,1))
            case "A", "B", "C", "D", "E"
            .....


            I can imagine that people reading your script snippet are curious how you managed to created that array from a string. Is there a secret trick?
            I can only come up with two methods;

            - Using a loop to fill an array:
            Do until intSize = Len(strCustomerName)
            ReDim Preserve arrCustName(intSize)
            arrCustName(intSize) = Mid(strCustomerName,intSize+1 ,1)
            intSize = intSize + 1
            Loop
            select case UCase(arrCustName(0))
            case "A", "B", "C", "D", "E"
            .....


            - Using a regular expression pattern
            Set oRE = New Regexp
            oRE.Pattern = "." : oRE.Global = True
            Set colCustName = oRE.Execute(strCustomerName)
            select case UCase(colCustName(0))
            case "A", "B", "C", "D", "E"
            .....



            BTW
            Your code in the second post starts with a string comparison. String comparison is always case-sensitive that is why it is better to forse to all upper-case or all lower-case characters in these cases.
            If UCase(strCustomerName) = "CUSTOMER" then

            \Rems
            Ahh why is it the scripting guru always pops up when you think you've finished just to scupper your plans. Only joking.

            Code:
            strlen = Len(strCustomerName)
            ReDim arrCustName(strlen - 1)
            Dim strCustName
            
            strCustName = strCustomerName
            
            For i = 0 to strlen - 1
                arrCustName(i) = Left(strCustName,1)
                strCustName = Right(strCustName, Len(strCustName) - 1)
            Next
            This is how i get the first character.

            Would this

            Code:
            select case UCase(Left(strCustomerName,1))
            case "A", "B", "C", "D", "E"
            Do the same job??

            Comment


            • #7
              Re: Need help using Or in an If Statement

              Yes!

              I assumed the array was required elsewhere so left it alone
              Tom Jones
              MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
              PhD, MSc, FIAP, MIITT
              IT Trainer / Consultant
              Ossian Ltd
              Scotland

              ** Remember to give credit where credit is due and leave reputation points where appropriate **

              Comment


              • #8
                Re: Need help using Or in an If Statement

                Originally posted by Ossian View Post
                Yes!

                I assumed the array was required elsewhere so left it alone
                Ahh.

                As they say "Every day is a school day."

                I wish i could script.........

                Comment


                • #9
                  Re: Need help using Or in an If Statement

                  You're doing fine
                  Tom Jones
                  MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
                  PhD, MSc, FIAP, MIITT
                  IT Trainer / Consultant
                  Ossian Ltd
                  Scotland

                  ** Remember to give credit where credit is due and leave reputation points where appropriate **

                  Comment


                  • #10
                    Re: Need help using Or in an If Statement

                    Just replaced the command with

                    Code:
                    Select Case (Left(strCustomerName,1)
                    Works perfectly.

                    I have previously used UCASE to convert the string to uppercase so i missed that bit out.

                    Comment


                    • #11
                      Re: Need help using Or in an If Statement

                      Originally posted by Ossian View Post
                      You're doing fine
                      I've managed to do the entire script i needed to get it to a working point, no error trapping done yet though, in less than 2 days.

                      This is from a non scripter who can just about manage to do simple tasks.

                      Thanks again Tom and Rems. Your input is appreciated.

                      Comment

                      Working...
                      X