Author Topic: User defined procedure with parameters  (Read 3618 times)

penny56

  • Newbie
  • *
  • Posts: 7
User defined procedure with parameters
« on: June 22, 2011, 01:34:46 AM »
Let's say you want a procedure that uses 1 parameter. How inside the procedure do you reference the passed value?

A simple example I am trying:

@Define variable
Global mytext

@Set variable
Put 'hello' into mytext

@Call my procedure with 1 parameter
Call MyMessage(mytext)

...

In MyMessage what code will run the command Message with the passed parameter value?
I am familiar with other environments that use local $1, $2, etc for the passed parameters, or something similiar...
« Last Edit: June 22, 2011, 01:46:37 AM by penny56 »

Malkom

  • Administrator
  • Sr. Member
  • *****
  • Posts: 289
Re: User defined procedure with parameters
« Reply #1 on: June 22, 2011, 06:31:27 AM »
Let's say you want a procedure that uses 1 parameter. How inside the procedure do you reference the passed value?

A simple example I am trying:

@Define variable
Global mytext

@Set variable
Put 'hello' into mytext

@Call my procedure with 1 parameter
Call MyMessage(mytext)

There are some limitations with received parameter within a user defined procedure. For instance inside the called procedure that parameter cannot be passed onto a another procedure but its value can be used by another variable and so passed on. There is some explanation of this inside HAC's inbuilt help Guide - in the section Program Structure subsection Procedures and Handlers.


if you pass a variable to your own procedure as a parameter then use a Local variable eg:-
.

Calling Handler or Procedure.
.
Code: [Select]
Local mytext

Put 'hello' into mytext
Call MyMessage(mytext)

or

Call MyMessage('Hello')

and inside MyMessage(mytextparam)
Code: [Select]
Put mytextparam into field 1

Local myvar

Put mytextparam into myvar
Call MyProcedure2(myvar)


Of course you could use Global variables and just declare them in both places so not passing a variable in the call but its very hard to keep track of such globals.



In MyMessage what code will run the command Message with the passed parameter value?
I am familiar with other environments that use local $1, $2, etc for the passed parameters, or something similiar...

This is more messy because some commands can use the passed parameter directly,
such as the Message command
but others like user defined procedures cannot as explained above.

inside Procedure MyMessage(mytextparam)

Code: [Select]
Message(mytextparam)
I am sorry but I do not have time to answer questions by PM or email.
If you post your questions in this forum then it might help others.

 

anything