hexagon logo

Testing commend input for numbers

Hello, I'm rather new to using logical operations in PCDMIS, so please bear with me.

I have a dialog box pop up when starting my program to ask the operator what fixture number the part came from. This can be 1 - 48. I am passing this number through a Tracefield to Excel output to WinSPC. I cannot handle this Fixture_Number variable in anything else but a strict numerical input like "23" when WinSPC is processing this data. How can I test if this input is strictly a number between 1 & 48, with no other characters? I think I'd be ok if it was just a number test, but would be nice if it also caught numbers that are more than 2 digits. Any ideas?

Snippet:


Thanks
  • Here is a quick bit of code that will do that. If the input is not between 1 and 48 an operator message will pop up. If the operator clicks 'OK' the program will jump back to the input comment and allow them to input a correct value. If the operator clicks 'CANCEL' the measuring routine stops. Either way it keeps bad data out of your database.

    C1 =COMMENT/INPUT,YES,FULL SCREEN=NO,
    FIXTURE NUMBER
    ASSIGN/FIXTURE_NUMBER=INT(C1.INPUT)
    IF/FIXTURE_NUMBER<1 OR FIXTURE_NUMBER>48

    [INDENT=2] COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
    PLEASE ENTER A NUMBER BETWEEN 1 AND 48
    GOTO/C1
    [/INDENT]
    END_IF/
    TRACEFIELD/DISPLAY=NO,REPORT=NO,....



    The purpose of using the INT function on line 3 is to remove any letters, decimal values, or special characters. It makes it so the FIXTURE_NUMBER variable will always be a whole number. Anything that is not a number will return a zero. The odd case where it wouldn't work quite right is if someone enters an alphanumeric code starting with a number. Something like "22B1123" will return 22 (the first number before a non-numeric character is found).
  • Cris_C, Thanks! That worked well. Now to complicate matters, I want to make sure that the numbers entered are integers... This is my attempt, but it's not working...



    Any thoughts?
  • Cris_C, Thanks! That worked well. Now to complicate matters, I want to make sure that the numbers entered are integers... This is my attempt, but it's not working...

    {"alt":"Click image for larger version Name:\timage.png Views:\t7 Size:\t5.4 KB ID:\t518919","data-align":"none","data-attachmentid":"518919","data-size":"full","title":"image.png"}

    Any thoughts?


    The INT() function will turn the input into an integer. So, you can adjust your assignment to be:
    ASSIGN/FIXTURE_NUMBER=INT(C2.INPUT)

    INT(“12”)=12
    INT(“Cat”)=0
    INT(“$52”)=0
    INT(“22B123”)=22
    INT(“13.6234”)=13

    Notice how anything that does not start with a number will equal Zero. That works well as zero will cause the first IF statement to be true and prompt the user to try again. The second IF statement becomes unnecessary.
  • IF/ROUND(C2.INPUT)<>C2.INPUT comment (...)
    GOTO /C2
    END IF

    I'm not at the cmm, I thought GOTO needed a label...
  • IF/ROUND(C2.INPUT)<>C2.INPUT comment (...)
    GOTO /C2
    END IF

    I'm not at the cmm, I thought GOTO needed a label...


    Oooo, I like that conditional statement. I thought there must have been a better way!

    Nope. The GOTO statement works with feature names too. At least, it has worked all the times I have tried it. Though, I admit, it might not be best practice.