Jump to content
Macro Express Forums

Nested Variable?


Cory
 Share

Recommended Posts

Is there a way to, in effect, do a %T%N1%%? IOW have the number in the string variable increment?

 

Specifically I’m dealing with a tab delimited file that comes form an Excel spreadsheet with a variable number of data columns. What I am doing is a little more complicated in actuality but I can distill it to a simpler example. Suppose I read in the first line from the text file. In the register I will have values in T1 thru some unknown number of strings. I want a repeat to check each of them in sequence to determine how many there are. So I was thinking that one could have a repeat and put the counter in %N1%. Then use that counter as the number part of the string variable. As soon as I encounter the first blank record I can subtract one form N1 and know how many columns there are.

 

I tried a simple test using text type but the test prints out “%T1%%T2%%T3%...” instead of the text save in the string vars. I’ve scanned Joe’s book for it and also the forum here but I can’t find anything relevant. Probably because I don’t know what the proper terminology would be for this. Also maybe there’s a completely different way to approach this. This must be a common problem so there must be an elegant solution. For the moment I’ll use a limited ugly approach, hopefully one of you can help me cut it out later.

 

Thanks!

Link to comment
Share on other sites

Hello Cory!

 

You can do this with version 3.5d or later. Here is an explanation from a different post (thanks Kevin!):

 

 

----------

Variable Evaluation Level

 

This feature allows the use of one variable to access another one. Consider, for example, the statement:

 

%T%N1%%

 

In Macro Express version 3.5c and earlier, if N1 contains 10 then the result will be %T10%. But, the content of T10 will not be accessed. The value will remain %T10%.

 

But, with the Variable Evaluation Level feature in version 3.5d and later, you can tell Macro Express to evaluate each statement that contains a variable multiple times. Thus, in our example, the first evaluation will result in %T10% and a second evaluation will retrieve the content of %T10%.

 

If N1 contains 1, then this will become %T1%. If N1 contains 99, then this will become %T99%. If N1 contains 101 then ... I don't know what will happen.

 

Because this multiple evaluation level has the potential of breaking existing macros, it is not enabled by default. To enable it, you need to enter a value in the registry.

 

Create a REG_DWORD registry value 'Variables Evaluation Level' in the registry key

HKEY_LOCAL_MACHINE\SOFTWARE\Insight Software Solutions\Macro Express\AdvOptions

-or-

HKEY_CURRENT_USER\SOFTWARE\Insight Software Solutions\Macro Express\AdvOptions

 

You may need to create the AdvOptions registry key.

 

To know whether to put the registry value in HKLM or HKCU you need to understand how Macro Express stores preferences. By default, Macro Express tries to store its preferences in HKLM. However, if the logged in user does not have access privileges to write to HKLM or if the ‘All users use the same settings’ option (found in Options, Preferences, Miscellaneous) is unchecked, then the preferences are stored in HKCU.

 

Set the Variables Evaluation Level to a number greater than 0. I have mine set to 5 but a value of 2 may be fine for your needs.

 

The value you set determines how many times the variable evaluation is repeated. If you have a complex statement that would require multiple passes to resolve, then you may want to set the Variables Evaluation Level to a larger number. But avoid very long loops, do not set this to a very large number.

 

All of this can be handled with a simple macro to enable this feature. This macro determines where in the registry (HKLM or HKCU) this option should be located and sets it. Try this:

 

<VSETMISC:T1:Preferences Registry Key><IVAR2:01:01:2><REGWINT:1:%T1%\AdvOptions\Variables Evaluation Level>

----------

 

 

Attached is an example so you can see how this works.

SampleVariableEvaluationLevel.mex

Link to comment
Share on other sites

Kevin:

Again, I searched for %T%N1%% and didn't find it on your site. Must be an ignored character in search engines. Another of those silly instances where I can't find something becasue I don't know what the proper term is for it. <g>

 

Hmmm.... One could do a simple data matrix with this....

 

Again, do I need to reload preferences?

Link to comment
Share on other sites

I searched for %T%N1%% and didn't find it on your site. Must be an ignored character in search engines.
Interesting. The % characters are stripped off during the search process. We'll have to look into that to see what, if anything, we can do about that.
One could do a simple data matrix with this...
True.
do I need to reload preferences?
You only need to enable the Variable Evaluation Level feature once. Well, that is, once per computer or if you enable it for a specific user and you do not have 'All users use the same settings' then you would have to do it for each user.

 

When you first set the option in the registry, you have to tell Macro Express to read it somehow. This can be done using the Reload Macro Preferences command or by terminating and restarting Macro Express.

 

You could have your macro look in the registry to see if the Variable Evaluation Level is set and if it isn't then set it and reload the preferences.

Link to comment
Share on other sites

That's exactly what I did.

<VSETMISC:T1:Preferences Registry Key><TVAR2:01:01:%T1%\AdvOptions\Variables Evaluation Level><REGRINT:1:%T1%><IFVAR2:2:01:3:2><IVAR2:01:01:2><REGWINT:1:%T1%><RELOADPREFS><ENDIF><CLEARVAR1:T:ALL><CLEARVAR1:N:ALL>

Works pretty slick and only will ever do the reload once per machine.

 

Now I have a new problem. How the heck do I use the nested variables? Everywhere I want to use them all I have is drop downs! I can’t type them in. Can change them in the direct editor?

Link to comment
Share on other sites

OK, continuing on from my last post….

 

I’m getting really frustrated, I spent all day on this and now when I thought I had a break thru it turns out it doesn’t work! Argggg…..

 

Here’s a simple example. I read one line from a tab delimited file and write to T1 thru T10. All I do is do one iteration at a certain line number which seems an easy way to read from the file. Anyway I would like to convert each text value to a decimal value. The idea is to have a repeat with a counter N1. Then in the repeat do a convert string to decimal. I envisioned something like %T%N1%% in the text variable and %D%N1%% in the decimal box. But it’s only a stinkin’ dropdown box so I can’t use that! What good is this VEL if you can’t punch it in anywhere? I tried editing it in the direct editor but everything squirreled out when I typed in %N1%. So as soon as I thought I had a solution I’m back here at the wall.

 

What I am doing is more complex but this should suffice as an example of my troubles. Any ideas?

Link to comment
Share on other sites

Never mind. I see now the VEL won't work in this case. So I boned up on the Run Macro in Variable and that does the trick very well. I was just being dense and I wasn't understanding how it worked. Now I see it's very simple. This is basically my test bed and now all I need to do is to adapt this to my more complex macro. Cool trick! I like this RMiV.

 

<TVAR2:10:01:5><TVAR2:11:01:25><TVAR2:12:01:80><REP3:01:000010:000001:00003:1:01:><TVAR2:04:01:<TMVAR2:06:%N1%:%N1%:000:000:>><RUNMACVAR:4><ENDREP>

Link to comment
Share on other sites

What good is this VEL if you can’t punch it in anywhere?
Ahhh! You hit the nail on the head. Yes, this is the disadvantage in the way it is implemented right now. It is easy to get a value out but it is not easy to put a value in. The sample macros describe how to make this work.

 

We have plans to improve this for a future version of Macro Express.

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...