variable array example
centering output:
PARM count=5 “Center” scriptsetvar cnt 0while setvar(cnt,cnt+1) <= !count do setvar string!cnt,input("Enter string !cnt: ")endwhilesetvar cnt 0while setvar(cnt,cnt+1) <= !count do echo ![rpt(" ",39-len(string!cnt))]!"string!cnt”endwhile
Enter string 1: The great thing about Open SourceEnter string 2: software is that you canEnter string 3: have any color Enter string 4: "screen of death”Enter string 5: that you want.
The great thing about Open Source software is that you can have any color "screen of death” that you want.
Notes:
- The “center” script shows generically the following:
- how to create a CI variable “array”
- how to access a variable “array”
- the !”literal!name1” construct, which allows compound variable names to be referenced. If literal = FOO, name1 = FUM and FOOFUM = 23 then !”literal!name1” = !”FOO!name1” = !”FOOFUM” = !FOOFUM = 23
- ![rpt(“ “, fieldWidth - lenOfVar)] puts the correct number of blanks before echoing the field’s value.
- Specifically, the “count” parameter is the number of elements in the “array”.
- string!cnt, where cnt is from 1..5, defines each element in the “array”.
- !”string!cnt” references the value of each element in the “array”.
- The rpt() function places the correct number of spaces before each line is echoed.
(The Open Source quote comes from Gavin Scott, Allegro Consultants, June ‘01 from the HP3000-L list.)