Jump to content
Macro Express Forums

UNDEFINABLE VARIABLE


Recommended Posts

Hi there... I am chasing my tail on this one. At run time I am getting the error "Undefined variable or the variable is of the wrong type. %N72% Line 34" The line is Variable set integer %N72% to 0. This is happening in a macro called by the main macro. In order to work out what was happening I created a very simplistic macro with the same structure as the original. In the test macro I can freely add/remove/assign variables and I don't get this error. I have added the lines save variables and restore variables before and after the sub-macro. It still works although more slowly...

 

Okay, In my original problematic macro, I cannot define N72 in the main macro. I double click on Variable Set Integer, Select variables (destination), Add, (type is set to integer) Variable name: N72. I see in bold: A variable name already exists or has invalid characters. So, If I open the list of variables there's a list of a dozen or so existing variables in there, none of which are N72. Why is this happening?

Link to comment
Share on other sites

The reason you're getting this is, I suspect, that the first reference in your macro to %N72% lies in a command where ME assumes a text variable.

Now, MEP comes with some variables predefined, and I suspect you're trying to use the integer ones. Where you are trying to address a non-array variable called %N72%, what MEP predefines for you is an array variable called N with 99 "slots", as in %N[1]% thru %N[99]%. So you should be naming your variable %N[72]%, at which point all should be well. And I'll bet you have a text variable called %N72%, which you can delete.

MEP has many problems with variables, and Insight doesn't seem to fix or even recognize any longer.

Link to comment
Share on other sites

Thanks Cory and Paul. I have attached a segment of my macro which demonstrates that it fails on line 8, where I am attempting to define the initial value. I get the feeling I have missed something major, here. I had the project up and running almost, and now I'm struggling to define a variable!

I abandoned the N variables and tried to use %meaningfulnames% instead, but I still can't get it working. Thanks for your advice.

Link to comment
Share on other sites

OK, I've looked at your code. I believed you've triggered an obscure bug in MEP.

 

Part of the problem is that you have defined many of your variables twice, e.g. PIXEL and %PIXEL%

 

Delete all the duplicate variables that have %% in them. E.g. delete %PIXEL%

 

However, this doesn't solve the problem right away. You will now need to "redefine" all your variables within the code.

 

Basically, you have to delete any mention of a variable and re-pick it from the Variables box. Do NOT type in the variable name manually. E.g. for line 9, dbl-click to bring up the Variable Set Integer window. In the Destination Variable box, delete the word %PIXEL% completely. Click on the Variables box, select PIXEL and click OK. The word %PIXEL% will appear in the Destination Variable box again.

 

Yeah, I know it looks just the same, but that's how to fix this. You will need to repeat this process on every line which contains those variables. I encountered a similar problem some months ago when I accidentally defined a varible twice. Took me quite a while to find this solution.

 

-Lemming

 

Attachment...

Link to comment
Share on other sites

Thanks lemming, Yes I have discovered that it is easier to just disable the line of code, delete all offending variables, and then redefine the variables from scratch. Trying to redefine from within existing code just doesn't work. "Part of the problem is that you have defined many of your variables twice, e.g. PIXEL and %PIXEL%" Ah, I think what is happening here is that at runtime MEP is producing spurious variables. I can check the list of variables and I have not defined them twice, and then run the macro, and some extra ones appear - the ones with the same name but with %%! I think this is what's happening.. I have now successfully got the macros to work. Thanks for all your help.

Link to comment
Share on other sites

One other thing to look at is that you have spaces in the variables field. For instance, your destination for your first Variable Set Integer command (on line 9) is " %PIXEL%" (without the quotes). This is what is throwing Macro Express off.

 

I'm making a change to make it more fault tolerant of this particular situation. But, in the meantime, if you make this change, it will work much better (and only create one copy of the variables during a save).

Link to comment
Share on other sites

Chris, I examined my macro for the spurious spaces, and was surprised to find many more than perhaps could be attributed to mere carelessness. This is the reason why: The extra copies created during a save appear on the variable list as "SPACE%PIXEL%". Whilst attempting to make the macro work, I had selected some of these self-defined variables from the list and edited out the extra inverted commas, but failed to notice the space still remained after back spacing... So the variable % %PIXEL%% ended up with an extra space in front. This is probably a red herring, but I was doing fine with a large and complex macro, all of which seemed to function fine until I introduced variable save and variable restore before and after each sub-macro. May just be coincidence. I accept fully that it was my failure to read the user guide that was the cause of my problems!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...