Using Local Variables in the Program
Refer to the gp:getPointInput function you created in Lesson 1:
(defun gp:getPointInput () (alert "Function gp:getPointInput will get user drawing input" ) ;; For now, return T, as if the function worked correctly. T )
So far, the function does not do much work. You will now begin to build on it by adding
functions to get input from the user, which will define the start point, endpoint,
and width of the path.
It is a good practice when creating AutoLISP programs to emulate the behavior of
AutoCAD. For this reason, instead of asking the user to indicate the width by selecting
a point in the drawing in respect to the centerline of a linear shape, your program
should ask for a selection of the half-width.
Once the gp:getPointInput function is complete, the variables, as well as the values assigned to them, will
no longer exist. Therefore, you will store user-supplied values in local variables.
Here’s what the function might look like:
(defun gp:getPointInput (/ StartPt EndPt HalfWidth) (if (setq StartPt (getpoint " Start point of path: ")) (if (setq EndPt (getpoint StartPt " Endpoint of path: ")) (if (setq HalfWidth (getdist EndPt " half-width of path: ")) T ) ) ) )
The local variables are declared following the slash character, in the defun statement that begins the function. The first call to getpoint prompts the user to indicate a start point. The endpoint is then acquired in relation
to the chosen start point. While selecting the endpoint, the user will observe a rubber-band
line extending from the start point. Similarly, while setting the half-width value,
the user will view another rubber-band line, this time representing distance, emanating
from the endpoint.
To see how gp:getPointInput works
- Type the gp:getPointInput code into the Visual LISP Console window.
- With the Console window cursor following the last parenthesis of the block of code
(or on the next line below it), press Enter and you will replace any previously loaded
version of the gp:getPointInput function.
- Execute the function from the Console window by entering (gp:getPointInput) at the Console prompt.
- Pick points when prompted, and enter a half-width value.
sp you declare a global variable it will continue to use memory whilst a program is running even if you no longer need/use it. Local variable – declared within …… How can I use a local variable on the TI-89 family, TI-92 Plus, or Voyage 200? A local variable is a temporary variable that exists only while a …local variable is a variable that is given local scope. Local variable references in the function or block in which it is declared override the same variable name in the larger scope. In programming languages with only two levels of visibility, local variables … if a variable name's scope is a certain block, then its scope is the program …local variable is a variable which is either a variable declared within the … in your programming, if we declare variables in a function then we can only use … w is a global variable which is in scope in all three functions in this program: Z(), Q() …variables are declared outside any function, and they can be accessed (used) on any function in the program. Local variables are declared inside a function, and can be used only inside that function. It is possible to have local variables with the same name in different functions.programs into named sections. You have already been using a …use it, the program waits for the user to 1) type in information and 2) …. Constants, global variables, class variables, instance variables, and local …program you can use that variable; get its current value or set its value to something else. Global variables are created …variable is available for use throughout your entire program after its declaration. Following is the example using global and local variables:with examples – Learn C programming language covering basic C, literals, data types,C … Example program for local variable in C:.