Jump to content
Macro Express Forums

Copy a global variable to a local of same name?


Recommended Posts

If I have T1 defined as a global variable in a parent macro and T1 defined in a called macro as a local is there any way to copy the value from the global to the local? I'm guessing not without using the registry as I am doing but I thought I would ask.

Link to comment
Share on other sites

If I have T1 defined as a global variable in a parent macro and T1 defined in a called macro as a local is there any way to copy the value from the global to the local? I'm guessing not without using the registry as I am doing but I thought I would ask.

 

I assume you mean without using another global variable as I've done here?

 

Parent Macro

Variable Set String %T[1]% to "Initial value of T1 in Parent macro"

Text Box Display: Parent Global

Variable Set String %TextHolder% to "%T[1]%"

Macro Run: TEMP-Cory-Submacro

Macro Return

 

 

<VARIABLE SET STRING Option="\x00" Destination="%T[1]%" Value="Initial value of T1 in Parent macro"/>
<TEXT BOX DISPLAY Title="Parent Global" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 T1 = \\f1 %T[1]%\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<VARIABLE SET STRING Option="\x00" Destination="%TextHolder%" Value="%T[1]%"/>
<MACRO RUN Use_ID="FALSE" Name="TEMP-Cory-Submacro" ID="-1" Wait="TRUE"/>
<MACRO RETURN/>

 

SubMacro

Variable Set String %T[1]% to "Initial value of T1 in submacro"

Text Box Display: Submacro value

Variable Set String %T[1]% to "%TextHolder%"

Text Box Display: Submacro value

Macro Return

 

<VARIABLE SET STRING Option="\x00" Destination="%T[1]%" Value="Initial value of T1 in submacro"/>
<TEXT BOX DISPLAY Title="Submacro value" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 T1 = \\f1 %T[1]%\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<VARIABLE SET STRING Option="\x00" Destination="%T[1]%" Value="%TextHolder%"/>
<TEXT BOX DISPLAY Title="Submacro value" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 T1 = \\f1 %T[1]%\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<MACRO RETURN/>

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Yeah, without using another. I think it was a stupid question. It would have to be something like Set %My Text%-Global to %My Text%-Local and of course there's just no way. As long as there is a local %My Text% the submacro will never be able to see the global.

 

My problem is that my biggest client has tons of macros and almost all of them use submacros. But in the ME 3 days how I handled this to avoid stepping on the limited old style array variables was to write a var to the registry, run the sub macro, save all the vars, clear all the vars, then read the registry value back in. Then essentially the reverse to pass the value back to the parent. Worked slick but now I want change this to a more sensible method. Especially since MEP crashes now every time I do a Variable Save All! You see how I do it now in my Serial Time macro but I can't afford the time to completely recode all my old macros so I was trying to find a way to use local and globals. So for the time being I decided to make all my subroutines local vars, dump the variable save/restore and keep the registry pass betweens. Essentially doing what you have suggested except the third party is the registry instead.

 

But you know your idea got me thinking just now. I usually use a registry value named "Feedback" in those cases I could use a global var %Feedback% instead. Mehhh... Then I would have to edit all the parent macros as well. If I'm going to do that I might as well gut out all the CDNT arrays. I'm already working on a macro to do just that and the first stage is already done!

Link to comment
Share on other sites

I guess I've always thought thoroughness required it! Is it (and Macro Stop) redundant? If so, what are they intended for?

Macro Stop stops a macro. If a called executes Macro Stop both the main and called macro stop. It is not necessary to put a Macro Stop command at the end of the main macro. When the main macro finishes execution it automatically stops.

 

Macro Return stops execution of a called macro. Use Macro Return in the middle of a logic statement to return to the main macro before the end of the called macro. It is not necessary to put a Macro Return at the end of the macro.

 

A Macro Return in the main macro works the same as the Macro Stop command.

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...
×
×
  • Create New...