Search code examples
intersystems-cachemumps

MUMPS Address Validation


I am working on prerequisite questions for a class I am trying to attend. I am working on revisions to two pieces of code. I have completed one and I am stuck on this one. I am trying to read an abbreviated address line. In this case FL33606. I am able to read the address. But I am receiving an undefined error for the Quit command "Q: done". Would someone be able to assist me in identifying what is wrong?

N prompt,val, done
    S prompt="Enter State and Zip (StateZip): "
    F  W !,prompt R val Q:val=""  D  Q:done  
    . I val'="?2A5N" W !,"Invalid entry" Q
    . S done=1
    I val="" q
    W !,"Valid Entry: ",val
    Q

Solution

  • I have two errors

    • done variable should be defined before the first read
    • the pattern should not be in quotes, where ? is the operator not =
      S prompt="Enter State and Zip (StateZip): "
      S done=0
      F  W !,prompt R val Q:val=""  D  Q:done  
      . I val'?2A5N W !,"Invalid entry" Q
      . S done=1
      I val="" q
      W !,"Valid Entry: ",val
      Q
    

    Why do you use short commands, and dots?

    Is not this much better readable?

      Set prompt = "Enter State and Zip (StateZip): "
      For {
        Write !,prompt 
        Read val 
        Quit:val=""  
        Quit:val?2A5N
        Write !,"Invalid entry" 
      } 
      If val="" Quit 
      Write !,"Valid Entry: ",val
      Quit