Part Four - SpiralI added some new lines of code to the spiral program to insure that the user enters valid data. These are simple initget function calls. I also provided some default values for the diameter, pitch, and number of coils. This makes the program easier to use. You should view the updated
version of Analyze CodeProvide Default Values... (if (not V:SPIRAL-DIAMETER) (setq V:SPIRAL-DIAMETER 1.0)) (initget 6) (setq #DIAMETER (getreal (strcat "\nDiameter <" (rtos V:SPIRAL-DIAMETER) ">: "))) (if (not #DIAMETER) (setq #DIAMETER V:SPIRAL-DIAMETER) (setq V:SPIRAL-DIAMETER #DIAMETER)) ... V:SPIRAL-DIAMETER is a variable that is going to be left as a global variables My convention it to prefix global variables with a "V:". Since they are global, they must have a unique name to make sure that another program that they were not intended for does not accidentally use them. That is why the names I used are long and descriptive. Conversely, local variables can be as short and cryptic as needed since they only apply to the function that you use them in. I will use that fact in subsequent parts of this column to shorten some of the local variable names. Since V:SPIRAL-DIAMETER will be global, it must not be included in the local variable list.
I used two other default global variables, V:SPIRAL-COILS and V:SPIRAL-PITCH. They were handled exactly the same as V:SPIRAL-DIAMETER, except that the V:SPIRAL-COILS variable was converted to a string using the itoa or "integer-to-ascii" functions. Initget for Centerpoint... (initget 1) ... It is often not very useful to have a default for point selections. So I did not give the prompt for the centerpoint a default value. But I did want to insure that the user would input a valid point. This initget function call comes just before the prompt for the centerpoint. A bit value of 1 disallows null input, so the user must input some valid point value, or correctly pick a point on the screen. In Part Five, I'll add an error handler and combine setq functions.
|