undefine a variable

Posted by Admin on 17-Oct-2007 14:49

I define a variable:

DEF VAR myvar AS INT.

How to undefine this varable ?

-tt.

Message was edited by:

Tomasz Toczyski

All Replies

Posted by Thomas Mercer-Hursh on 17-Oct-2007 15:21

You can't, but tell us why you want to and maybe we can suggest something. E.g., it could be put in a sub-procedure and would be scoped to that subprocedure.

Posted by Admin on 17-Oct-2007 15:43

I have "DEF VAR myvar AS INT" statement in my .i file.

In case I call this file once - it is OK.

But when I try to call it once more I get an error because I can't define the same variable more than once. So I wanted to undefine the variable before calling this file for the second time.

-tt.

Posted by Thomas Mercer-Hursh on 17-Oct-2007 16:00

AH, different problem.

The right solution is to change the structure. A fairly simple way to do this and generally a better approach than using include files anyway, is to encapsulate the code into a separate procedure to which you pass parameters.

If the code is small and specific to a single program, you can even make it an internal procedure where you can get away with (but shouldn't) interacting with the context of the program (but, if you are doing things right, everything will get passed in or out as a parameter). Since you can define variables local to the internal procedure, no problem.

If it is used in multiple programs, then put it in its own .p. If it is called repeatedly from the same procedure, then run it persistent and run an internal procedure in it as needed.

Now, since someone else will probably mention it if I don't, you can also use the preprocessor to handle this situation and stick with includes. The basic idea is that you check with the preprocessor to see whether something has been previously defined and only execute the define statement when it has not been defined.

But, do yourself a favor and don't go that route. It may seem faster right now, but it is really not the right way to solve the problem.

Posted by Admin on 18-Oct-2007 14:16

Thomas, thank you very much for your answer.

This thread is closed