Back | Next Lesson

Need Input!

We now have variables to put stuff in.  In our 2x4 stud program, it will draw a 2x4 stud correctly every single time.  Only problem is, it draws the stud at absolute zero (line #007) every single time.  We call this hardcoding, where there is no flexibility.

001     //stud
002     level 1u
003     
004     width  = 1.5"
005     height = 3.5"
006     
007     plowleft  = A(0,0,0)
008     pupright  = A(width,height,0)
009     pupleft   = A(0,height,0)
010     plowright = A(width,0,0)
011     
012     ::pen;=2
013     ::box;=plowleft;=pupright;:
014     ::pen;=1
015     ::sal;=plowleft;=pupright;=plowright;=pupleft;:
016     exit

Lines #012-015 call other sigmacs (future lesson).  Everything else, we have discussed and you should be well versed on.

User Input

We need a way to add flexibility - to conform this sterile program in to something useful.  Lets begin by changing line #007 to accept input from the user:

007     plowleft = $inp(#point,'Lower Left Corner of Stud')

The $utility, $inp() pauses the program to retrieve input from the keyboard or mouse (e.g. user). Now that our start point could be anywhere, we need to adjust the 3 remaining corner points to be relative to the new start point.  We can do this by adding the 3 corner points to the start point with the width and height dimensions.  Rewrite lines #008-010 as follows:

008     pupright  = A(plowleft + (width,height,0))
009     pupleft   = A(plowleft + (0,height,0))
010     plowright = A(plowleft + (width,0,0))

? Input

When calling another Sigmac, you must provide all expected input, therefore the following will execute the "pen" command, ask for the "Logical Pen", and
not return control to your sigmac to finish execution of lines #013-016.

012     ::pen

To maintain control, we can either supply the input expected via a variable or constant (as in our original sigmac at the top of this lesson) or use a question mark (?) as a place holder.  This will pause the execution of your program and prompt the user for input utilizing the 'called' sigmac's prompt string.  Once the user answers the prompt, the execution control will return to your sigmac.  To illustrate, we could rewrite lines #012 (and #014) to:

012     ::pen;?

Hint:   Notice no equal symbol (=) used with the "?", as in assigning a variable. The down side is that this method does not offer you a chance to perform error checking (.  You have to depend on the sigmac to perform adequate error checking.


More Input

Our sigmac would be even more useful with even less hardcoding.  Let's do some redesigning and make our program draw more 2x studs.

001     //stud
002     level 1u
003     
004     width  = 1.5"
005     
006     
007     stud  = $inpc(#strn,'Draw Which Stud',1,'2x4','2x6','2x8')
008     if stud == '2x4'
009             height = 3.5"
010     elseif stud == '2x6'
011             height = 5.5"
012     elseif stud == '2x8'
013             height = 7.5"
014     endif
015     
016     plowleft  = $inp(#point,'Lower Left Corner of Stud')
017     pupright  = A(plowleft + (width,height,0))
018     pupleft   = A(plowleft + (0,height,0))
019     plowright = A(plowleft + (width,0,0))
020     
021     ::pen;?
022     ::box;=plowleft;=pupright;:
023     ::pen;?
024     ::sal;=plowleft;=pupright;=plowright;=pupleft;:
025     exit

Line #007 adds flexibility by introducing $inpc(), which takes the $inp() to the next level by adding choices to select from in a pull-up menu on the prompt line. Lines #008-014 processes the user's choice via if/elseif/endif conditional statements (future lesson).

Displaying Additional Information

As discussed earlier in our "hello.ff" sigmac, we can use the exclamation symbol (
!) to display a string below the ARRIS prompt line.  Let's change line #015 in the above example to:

015     !'Drawing A '+stud+' Stud'
016     plowleft  = $inp(#point,'Lower Left Corner of Stud')

This allows us to give the user more information when answering your prompts.  Other $utility options that display additional information include $prmess(), $error(), $ierror(), and $ferror().  These will be discussed in a later lesson.

Tip:    Once we open out sterile program to the outside world, we invite errors entered from the outside world (eg users, text files, etc.).  Imediately following any input statements, you should follow with if/else/endif statements to verify the data entered by the user is within the valid range of values expected by your program.  More on error checking later when discuss conditional statements.


That's all for now,
Steve


This lesson was brought to you by SCG consulting. All written materials related to these Sigmac lessons are copyrighted by SCG and intended for personal use only. Any commercial or non-commercial reproduction for public use is prohibited without written consent from SCG.

Back | Next Lesson