It is currently Sun Jun 24, 2018 10:59 pm


All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Unit 3 - Lesson 2: Create/Edit Database - Exercise 2
PostPosted: Sun Jul 10, 2011 9:57 am 
User avatar

Joined: Wed Nov 17, 2010 8:37 am
Posts: 136
Real Name: Terry L. Wiechmann
Began Programming in MUMPS: 0- 0-1971
Exercise 1 Solution

Routine: MP1PEDIT

Code:
MP1PEDIT ; Create/Edit Parts routine for the MP1 Course.
PNUM ; Part Number
    Write !,"Part Number: "
    Read X
    Set PNUM=X
    ;
PDESC ; Description
    Write !,"Description: "
    Read X
    Set PDESC=X
    ;
PQTY ; Quantity
    Write !,"Quantity: "
    Read X
    Set PQTY=X
    ;
PLVL ; Reorder Level (it's time to reorder the part if PQTY<PLVL)
    Write !,"Order Level: "
    Read X
    Set PLVL=X
    ;
PRC ; Replacement Cost
    Write !,"Manufacturing Cost: "
    Read X
    Set PRC=X
    ;
PSP ; Selling Price
    Write !,"Selling Price: "
    Read X
    Set PSP=X
    ;
    Goto PNUM

Goals
  1. Add syntax check to each query.
  2. Add Error message to each query if check is false.
  3. Add transfer logic if "^" is entered at each query.
Description
  1. Modify each read statement to check the syntax of the value entered.
  2. If the user did not type in the correct response, then simply prompt again. You should use the IF command with with pattern matching and the Not operator making sure incorrect values are processed to the right of the IF command. Processing exceptions to the right of the check keeps this code out of the normal top-down flow of a routine. Sometimes this makes the line long. If this happens, try to use block structuring.
  3. Test this code and make sure it works before moving on. Always do this before proceeding to the next step.
    Code:
    PNUM ; Part Number
        Write !,"Part Number: "
        Read X
        If X'?1.6N Quit:X=""  Goto PNUM
        Set PNUM=X
       ;
  4. If the query value is incorrect, we need to immediately check for the convention entries: "^" and null. If the "^" is entered, go to the previous query. If a null was entered, simply quit at this point. Later on, entering null will take on a different meaning. What is the "previous query" mean at the first query PNUM? Simply quit at this time.
    Code:
    PNUM ; Part Number
        Write !,"Part Number: "
        Read X
        If X'?1.6N Quit:X["^"!(X="")  Goto PNUM
        Set PNUM=X
       ;
    PDESC ; Description
        Write !,"Description: "
           Read X
        If X'?1A.29NAP Quit:X=""  Goto PNUM:X["^",PDESC
        Set PDESC=X
        ;
  5. Notice that when you enter a value that is wrong, you simply transfer back to the query for it to be asked again. There is no feedback as to what you need to enter for the value to be correct.
  6. Add the code to write out a short message describing what the syntax of the query should be.
    Code:
    PNUM ; Part Number
        Write !,"Part Number: "
        Read X
        If X'?1.6N Quit:X["^"!(X="")  Do  Goto PNUM
        . Write !?5,"Enter 1-6 numeric digits. Required."
        Set PNUM=X
        ;
    PDESC ; Description
        Write !,"Description: "
        Read X
        If X'?1A.29NAP Quit:X=""  Goto PNUM:X["^" Do  Goto PDESC
        . Write !?5,"Enter 1-30 characters starting with a letter. Required."
        Set PDESC=X
        ;
  7. Notice we used block structuring to make the lines less long and readable. Some would argue that this increases processing which is true. However, under the circumstances where this code will not be processed in the normal flow of the routine, this is quite acceptable.
  8. Also, take note of the argumentless commands Quit and Do. When a comment or command follows them, two spaces must be used. Positionally, this simply means the arguments are missing.

_________________
Terry L. Wiechmann


Top
Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net