Home | Web Design | Programming | Fairlight CMI | Soap Box | Downloads | Links | Biography | About... | Site Map |
Initializing Arrays |
CA-Clipper | Opportunities | Tips and Tricks | Networking | Internal Errors | Source Code | CA-VO |
BACK TO CA-CLIPPER TIPS & TRICKS |
The array is a very powerful tool in CA-Clipper. It can be used to store
many different values. It is commonly used to store a collection of
related values that will be presented to the user in a picklist. Sometimes you know ahead of time (that is, when you are writing the source code) how large an array is. At other times the size of the array is not known until run-time. If array size is known If the array size is known at the time the program is written, there are several ways to implement the code.
aX
variable, but it would also work if the aY or aZ
variables were used. The point of this sample is to show three ways of
creating an array if the size is known at the time of writing
the code. On line 1 the array is created using aX[10] . This causes
CA-Clipper to allocate space for 10 elements. The square brackets
[ and ] are used to indicate the size
required. Line 2 uses the array() function with a parameter of 10 to
create the array, then the return value of the function is assigned to the
aY variable. Line 3 does what I like to call "painting a picture of the array". As you can see, there are ten 0's in the list surrounded by braces (sometimes called "squiggley brackets" or "curley braces"). Clearly, you would not use this method to create an array containing 1000 elements! The third method differs from the first two because it initializes the array with actual values. In the first two methods, each element of the array contains a value of NIL, which is an empty placeholder. Line 6 shows that a value can be assigned to an already existing array element by specifying the index, or "slot number", using the square brackets. If array size is unknown If the array size is not known until run-time, there are several ways to create an array and then add elements to it. The sample below illustrates the idea of creating an empty array (one with no elements) and adding to it dynamically.
Line 2 calls the array() function which creates an array
with no elements. Line 3 is my choice for representing an empty array in source code. Once again, it uses the curley braces to paint a picture of the array. Note that {} is an empty array (the array has a length of 0), whereas
{NIL} is an array with one empty element (the array has a
length of 1). Because each of these arrays start with no elements, line 6 uses the aadd() function to add elements successively to the end of
the array.
|
Home | Web Design | Programming | Fairlight CMI | Soap Box | Downloads | Links | Biography | About... | Site Map |
Send comments about this site to Greg at
gregh@ghservices.com All pages copyright © 1996-1999 GH Services Created 1997/06/06 Last updated 1999/09/30 All trademarks contained herein are the property of their respective owners |