• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

How to use FIND() in an IF() statement

Scheduled Pinned Locked Moved Dynamic Components
sketchup
6 Posts 3 Posters 7.5k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    hank
    last edited by 11 Dec 2016, 20:39

    I'd like to be able to hide a group within a component based on the value of a text list variable (OPENING!TYPE) users select.

    Here is the IF clause I am using for the groups "Hidden" attribute:

    =IF(find("SINGLE",OPENING!TYPE),FALSE,TRUE)
    

    Which says "If the string "SINGLE" is found in the attribute value for "OPENING!TYPE", return FALSE making the group not hidden, otherwise return TRUE making the group hidden.

    The problem is that FIND() returns a number for where it found the search string. That is fine for when it successfully finds the search string because any positive number evaluates to true. BUT when it does not find it, it returns something like

    Not found; SINGLE
    

    Which does not evaluate to FALSE.

    So, how can I use FIND() to return TRUE or 1 if it finds the search string and FALSE or 0 when it does not?

    Thank you.

    1 Reply Last reply Reply Quote 0
    • J Offline
      Jim
      last edited by 12 Dec 2016, 09:00

      Not tested, but maybe:

      =IF(find("SINGLE",OPENING!TYPE)>0,FALSE,TRUE)
      

      Hi

      1 Reply Last reply Reply Quote 0
      • P Offline
        pcmoor
        last edited by 12 Dec 2016, 09:54

        find needs to return a value, a position. so if if there is no match it fails. Since there is no error catch procedure, it is not possible to
        IF(find("SINGLE",OPENING!TYPE)>0,FALSE,TRUE) unless "SINGLE" exists, can only be true or an error

        1 Reply Last reply Reply Quote 0
        • H Offline
          hank
          last edited by 13 Dec 2016, 00:54

          Well that stinks. Is there any way to test for an error. Will Jim's solution work?

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by 13 Dec 2016, 01:22

            @hank said:

            Well that stinks. Is there any way to test for an error. Will Jim's solution work?

            You could use LEFT and EXACT.

            =EXACT(LEFT(OPENING!TYPE, 6), "SINGLE")
            

            or a simple IF

            =IF(LEFT(OPENING!TYPE, 6) = "SINGLE", TRUE, FALSE)
            

            or maybe even

            =IF(OPENING!TYPE = "SINGLE", TRUE, FALSE)
            

            Hi

            1 Reply Last reply Reply Quote 0
            • H Offline
              hank
              last edited by 13 Jun 2017, 03:48

              Thank You Jim!

              So how about if I wanted to find out if the string "SINGLE" exists anywhere in the string?

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement