hexagon logo

Testing Operator input for special characters or wild cards

Anyone have an idea how to test and stop operators inputting \/:*?<>| in comments? If it contains those then it will comment back and tell them to try again? im trying to use an if_goto statements.

[C1 =COMMENT/INPUT,NO,FULL SCREEN=NO,
ENTER SERIAL NUMBER
ASSIGN/NEWSN=C1.INPUT
IF_GOTO/NEWSN=="/" ,GOTO = DEATH
IF_GOTO/NEWSN==":" ,GOTO = DEATH
IF_GOTO/NEWSN=="*" ,GOTO = DEATH
IF_GOTO/NEWSN=="?" ,GOTO = DEATH
IF_GOTO/NEWSN=="<" ,GOTO = DEATH
IF_GOTO/NEWSN==">" ,GOTO = DEATH
IF_GOTO/NEWSN=="|" ,GOTO = DEATH
IF_GOTO/NEWSN=="0" ,GOTO = DEATH
GOTO/LIVE
DEATH =LABEL/
IF/1
COMMENT/OPER,NO,FULL SCREEN=YES,AUTO-CONTINUE=YES,TIME DELAY=10,
DO NOT USE SPECIAL CHARACTERS FOR THE INPUT.
TRY AGAIN!
GOTO/C1
END_IF/
LIVE =LABEL/​]
  • Download and open the lib_reporting.PRG file there's a nice example of what you're trying to achieve (only to add to the good examples already shared here)

    https://github.com/Kp61dude/cmm_libs
  • This seems to do the trick!! Thank you for the input!


    C1 =comment/input,no,full screen=no,
    enter serial number
    assign/newsn=c1.input
    if_goto/index(newsn,"")>0,goto = death
    if_goto/index(newsn,"/")>0,goto = death
    if_goto/index(newsn,":")>0,goto = death
    if_goto/index(newsn,"*")>0,goto = death
    if_goto/index(newsn,"<")>0,goto = death
    if_goto/index(newsn,">")>0,goto = death
    if_goto/index(newsn,"?")>0,goto = death
    if_goto/index(newsn,"|")>0,goto = death
    if_goto/len(newsn)>17,goto = death
    goto/live
    death =label/
    if/1
    comment/oper,no,full screen=yes,auto-continue=yes,time delay=10,
    "do not use more than 17 and/or special characters for the input."

    try again!

    Newsn
    "is an invaild input"
    goto/c1
    end_if/
    goto/live
    live =label/​


    The following command will not work as you want it to:

    if_goto/index(newsn,"\")>0,goto = death




    if_goto/index(newsn,"\\")>0,goto = death Should work
  • yes i got that the chat msg keeps erasing it on me for some reason.. thx i got the \ to work
  • Probably same reason PCDMIS does it. I had to also put additional \\\\\ for the proper amount to show up lol
  • And don't forget quotation mark. CHR(34).

    so your list should look like:
    if_goto/index(newsn,"\")>0,goto = death
    if_goto/index(newsn,"/")>0,goto = death
    if_goto/index(newsn,":")>0,goto = death
    if_goto/index(newsn,"*")>0,goto = death
    if_goto/index(newsn,"<")>0,goto = death
    if_goto/index(newsn,">")>0,goto = death
    if_goto/index(newsn,"?")>0,goto = death
    if_goto/index(newsn,"|")>0,goto = death
    if_goto/index(newsn,CHR(34))>0,goto = death

    approach is probably best but I get "Line too long error" (maybe cos I'm using v2012) so split it over 2 lines:

    ASSIGN/V20=ELEMENT(1,"/",NEWSN)<>NEWSN OR ELEMENT(1,"\",NEWSN)<>NEWSN OR ELEMENT(1,"*",NEWSN)<>NEWSN OR ELEMENT(1,":",NEWSN)<>NEWSN OR ELEMENT(1,"?",NEWSN)<>NEWSN
    ASSIGN/V21=ELEMENT(1,">",NEWSN)<>NEWSN OR ELEMENT(1,"|",NEWSN)<>NEWSN OR ELEMENT(1,CHR(34),NEWSN)<>NEWSN OR ELEMENT(1,"<",NEWSN)<>NEWSN

    As I understand it, there are 9 special characters:


    Hope this helps.​​
  • C1 =COMMENT/INPUT,NO,FULL SCREEN=NO,
    ENTER SERIAL NUMBER
    ASSIGN/NEWSN=C1.INPUT
    IF_GOTO/INDEX(NEWSN,"\")>0,GOTO = DEATH
    IF_GOTO/INDEX(NEWSN,"/")>0,GOTO = DEATH
    IF_GOTO/INDEX(NEWSN,":")>0,GOTO = DEATH
    IF_GOTO/INDEX(NEWSN,"*")>0,GOTO = DEATH
    IF_GOTO/INDEX(NEWSN,"<")>0,GOTO = DEATH
    IF_GOTO/INDEX(NEWSN,">")>0,GOTO = DEATH
    IF_GOTO/INDEX(NEWSN,"?")>0,GOTO = DEATH
    IF_GOTO/INDEX(NEWSN,"|")>0,GOTO = DEATH
    IF_GOTO/LEN(NEWSN)>17,GOTO = DEATH
    GOTO/LIVE
    DEATH =LABEL/
    IF/1
    COMMENT/OPER,NO,FULL SCREEN=YES,AUTO-CONTINUE=YES,TIME DELAY=10,
    "DO NOT USE MORE THAN 17 AND/OR SPECIAL CHARACTERS FOR THE INPUT."

    TRY AGAIN!

    NEWSN
    "IS AN INVAILD INPUT"
    GOTO/C1
    END_IF/
    GOTO/LIVE
    LIVE =LABEL/





    This works, its hasn't failed me yet.
  • Yes, I had to split this up into 2 variables and check them together as you stated otherwise the line was too long.
    I'll still advocate for custom forms all day.
  • So my next question is if i have a user input comment like this "p123456; s00024058; v433356" and only want the s00024058 string, how do I filter out or ignore the p numbers, ; , & v numbers? I want only the s numbers collected and input into a tracefield or variable.

  • Once this data is input is the format always exactly the same?

    P123456; s00024058; v433356

    7 characters, 9 characters, 7 characters

    If this is 100% repeatable in this format, something I threw together quickly without thought for more controlled filtering.

    C1         =COMMENT/INPUT,NO,FULL SCREEN=NO,
                Scan Barcode
                ASSIGN/V1=RIGHT(LEFT(C1.INPUT, 18),9)
                TRACEFIELD/DISPLAY=NO,REPORT=NO,DISPLAY MESSAGE=New Trace ; New Trace : V1