Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Functions...
#1
Sorry i wasnt logged in. This is probably a simple question. I was wondering how to get the function to work with the code. is there certain thing i have to do. I looked in the help. I uaually find what im looking for. I looked up functions. But i cant find anything in there that explains how to get the function to work with the code. Do i have to name the function after the code if so. Can you give me a small example please.
#2
Assume you have a macro with the following code:

aaa
bbb
ccc
ddd

and other macro with the following code:

eee
bbb
ccc
fff

You see that both macros use common code - bbb ccc, and it would be more rational to place the code into a function. Create new function (use menu File -> New -> New Function) and give it some meaningful name, lets say BiSi. Place the common code in it:

bbb
ccc

Now in macros you can use just BiSi instead of all the common code.

aaa
BiSi
ddd

and

eee
BiSi
fff



This was simplest example. If the function needs some information from the caller macro, use arguments. Arguments are local variables declared using "function" keyword. Functions don't recognize caller's local variables. Assume, the function needs one integer and one string value. At the beginning of the function, insert something like this:

function int'i str's

Here i and s are local variables that receive copies of values that the caller passes to the function. Now the caller macro may look like this:

aaa
BiSi 10 "xyz"
ddd

In this case, variables i and s in BiSi will be populated with 10 and "xyz".



Often functions are used to get some value. Assume, the function returns (passes to the caller) 1, and the caller assigns the return value to a variable. In the function, insert ret 1:

bbb
ccc
ret 1

This will end the function, and causes it to return 1. The macro now may look like this:

aaa
int variable
variable=BiSi(10 "xyz")
ddd

In this case, arguments must be enclosed in parentheses, which is not necessary when the line begins with BiSi.

To return a value, or several values, also can be used reference arguments. It is recommended way to return strings and arrays.


Forum Jump:


Users browsing this thread: 1 Guest(s)