Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#DEFINE an array

Status
Not open for further replies.

aaiqbal

Programmer
Sep 15, 2003
26
US
Hi,
I was wondering if it's possible to #Define an array and its' elements. If so, what is the syntax. An example would be great. Thanks.
 
This is from the help screen in procomm

Defines a macro name and the text to substitute for it during compilation. There are two forms of macros in ASPECT.

Simple text substitution:

#define name text

name The macro name to be defined.
text The text to be substituted for the macro name when processed by the ASPECT Compiler.

Argument/text substitution:

#define name([name[,name]...]) text

name The macro name to be defined.
([name[,name]...]) Zero or more arguments to be processed by the compiler with the substitution text.
text The text to be substituted for the macro name when processed by the ASPECT Compiler.

Example

#define TRUE 1 ; Constant to use in place of TRUE.
#define FALSE 0 ; Constant to use in place of FALSE.
proc main
integer Error ; Integer to contain Error.

Error = TRUE ; Set error to true, or 1.
if Error == TRUE ; Check to see if error is true
usermsg "True" ; or false and display message.
elseif Error == FALSE
usermsg "False"
endif
endproc

; #define macro(arglist)
; The statement below declares a macro that calls the internal

; SDLGMSGBOX function to display the specified message.
; Each operand, "a", "b", "c" corresponds to a parameter in the
; SDLGMSGBOX function.
#define PutMsg( a,b,c ) sdlgmsgbox a b STOP OK c 1
proc main
string Title, BoxText ; Strings for title and text.
integer Choice ; Integer for button selection.

Title = "Macro Example" ; Assign value to title and text.
BoxText = "This is an example of Macro Expansion."
; Call internal SDLGMSGBOX function using macro.

PutMsg( Title, BoxText, Choice )
endproc

Comments

Similar to macros in the "C" programming language, #define allows for textual substitution within a source program.

If the argument/text substitution macro form is used, any arguments specified must follow the standard ASPECT naming convention in the #define statement.

 
I don't believe you can declare the array itself, but you could declare each element in the array. Here's an example:

proc main
string array[5]

#define foo array[0]
foo = "testing!"
usermsg "%s" array[0]
endproc

In this case, I've assigned the element array[0] the label foo. I then set foo to be "testing!", then print the value of array[0] (i.e. what foo points to), and get the expected value.


aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top