If, else_if statement.

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

  • If, else_if statement.

    I am trying to do pn verification based on a selected input for the operator and it always results in the last else_if statement being assigned. if i hover over the PN at the end of the code it's 111E1111G0006-10. I expected if i put in the first part number it'd reassign it and jump to the end. Here is the code....

    $$ NO,
    ------------------------------
    Verify PN is set correctly
    ------------------------------
    SELECT/PN
    IF/ LEFT(PN,13)=="111E1111G0003"
    ASSIGN/PN="111E1111G0003-10"
    END_IF/
    ELSE_IF/ LEFT(PN,13)=="111E1111G0004"
    ASSIGN/PN="111E1111G0004-10"
    END_ELSEIF/
    ELSE_IF/ LEFT(PN,13)=="111E1111G0005"
    ASSIGN/PN="111E1111G0005-10"
    END_ELSEIF/
    ELSE_IF/ LEFT(PN,13)=="111E1111G0006"
    ASSIGN/PN="111E1111G0006-10"
    END_ELSEIF/
    ELSE/
    COMMENT/OPER,NO,FULL SCREEN=YES,AUTO-CONTINUE=NO,
    "============================================= ="
    "Part Number "+PN+" is not a valid choice for this inspection."
    "Please select a different part number."
    "Press OK to end program and re-select part number."
    "============================================= ="
    GOTO/ASKSPC
    END_ELSE/
    END_SELECT/
    PN_VERIFIED=LABEL/
    $$ NO,
    PN

  • #2
    good Day

    please use case in an Select-Statement, instead of If-else:


    Code:
    SELECT/C1.INPUT
    
        CASE/1
    
        ...
    
        END_CASE
    
        CASE/2
    
        ...
    
        END_CASE
    
        DEFAULT CASE
    
        ...
    
        END_DEFAULT CASE
    
    END_SELECT

    Code:
    SELECT/LEFT(PN,13)
    
        CASE/"111E1111G0003"
          ASSIGN/PN="111E1111G0003-10"
        END_CASE
    
        CASE/"111E1111G0004"
          ASSIGN/PN="111E1111G0004-10"
        END_CASE
    
    END_SELECT

    by the way, thats the same:
    Code:
       ASSIGN/PN2=LEFT(PN,13)+"-10"
    i dont understand what exactly you want to archiv :/
    Last edited by Henniger123; 03-18-2021, 01:40 AM.

    Comment


    • #3
      I had added the select statements after i thought it wasn't working. it turns out it was working fine I was just hovering over the variable expecting it to show the current value. In the end i put an operator comment with the variable in the comment and it output the correct value. As Far as it purpose it is so when the operator chooses a value from a drop down menu or scans the paperwork or types something in that it forces the assign value. The data get ingested into a database based off the part number. Basically it will verify the part number and continue or kick them back until they input the correct number. The paperwork may not contain the -10 and the drop down list will have a friendly name after the part number that we don't care about but helps them to quickly identify if they choose not to use the scanner to input the part number.

      I like the select, end_select, case, end_case, default_case, end_defaultcase method as it looks cleaner and easier to understand. Thank you for explaining that.
      Last edited by MrMatt68; 03-18-2021, 08:49 AM. Reason: added info

      Comment


      • Henniger123
        Henniger123 commented
        Editing a comment
        It seems like you have to put a lot of Commands in every program that uses this feature.
        You only want to check if the number-input is correct? hmm maybe a Script is a think for this, if you use a script at least you must only inside one Command that execute this script.
        Anyway, glad it worked

    Related Topics

    Collapse

    Working...
    X