Jump to content
Macro Express Forums

Is there a way to create a Global Variable that goes into all macros?


Recommended Posts

Example:

 

If my working folder right now is D: drive, and in the future (or on another PC) my working folder is E: drive,

 

Instead of changing all my macro directories from D:=> E: (Which could take a long time)

 

Is there a way to create a GLOBAL variable, for example %A1% => where you can change it from D: to E: etc etc. without having to change the drives in all the macros?

 

This way, instead of using D: or E: in each and every macro, you can just substitute %A1% which can easily be changed...

 

 

 

 

(Okay this is separate from ME3 but if possible this would be very useful also!)

What about for .BAT Files? Is there a way for .BAT files to use a Global .Bat file variable?

 

Example:

Start.Bat Contains:

"D:

CD\MyWorkingFiles

MyProgram.exe"

 

 

Instead of using D: in the Start.Bat, can we use something like

SetGlobalVariable => D:\GlobalVariable.ini (Inside this file is simple "E:")

 

Example2:

Start.Bat Contains:

"SetGlobalVariable => D:\GlobalVariable.ini

%GlobalVariable%

CD\MyWorkingFIles

MyProgram.exe"

 

 

 

This way, let's say I had 100 .BAT Files, instead of changing all .BAT files from D: to E:, I would just have to change D:\GlobalVariable.ini from D: to E:

 

Is this possible?

Link to comment
Share on other sites

If my working folder right now is D: drive, and in the future (or on another PC) my working folder is E: drive,

 

Instead of changing all my macro directories from D:=> E: (Which could take a long time)

 

Is there a way to create a GLOBAL variable, for example %A1% => where you can change it from D: to E: etc etc. without having to change the drives in all the macros?

 

This way, instead of using D: or E: in each and every macro, you can just substitute %A1% which can easily be changed...

My preferred method is to create a registry key and value with the correct value for that machine. Suppose you have 2 computers, one of which will use drive D:, the other drive E:

You create a registry key to hold some appropriate values, e.g. HKEY_CURRENT_USER\Software\MEPValues.

You then create a new value name and value under this key called, say, MacroDrive, of type String or REG_SZ, and give it a value on one computer of D:, and on the other of E:.

Your macro then reads this registry value into a string variable and uses it, as in:

Read Registry Value "HKEY_CURRENT_USER\SOFTWARE\MEPValues\MacroDrive" into %tDrive%
Change Directory/Folder to "%tDrive%\MyFolder"

(Okay this is separate from ME3 but if possible this would be very useful also!)

What about for .BAT Files? Is there a way for .BAT files to use a Global .Bat file variable?

 

Example:

Start.Bat Contains:

"D:

CD\MyWorkingFiles

MyProgram.exe"

 

Instead of using D: in the Start.Bat, can we use something like

SetGlobalVariable => D:\GlobalVariable.ini (Inside this file is simple "E:")

Control Panel / System / Advanced / Environment Variables

Add a new variable called, say, WorkingDrive and set it to the relevant drive for that computer, e.g. D:. Then your .bat file will read:

%WorkingDrive%
cd \MyWorkingFolder
MyProgram.exe

Link to comment
Share on other sites

Paul's use of the Windows registry has the advantage that you load the value once, and it stays there indefinitely through reboots and restarts of ME. If you don't want (or aren't allowed) to change the registry, you can do almost the same thing by scheduling a macro to run at ME startup. In the macro you save the disk drive to an environment variable. All your other macros simply read back the environment variable. When you move to a different PC, you simply change the startup macro to whatever fits that PC.

 

If you use Paul's Control Panel / System / Advanced method of creating an environment variable for .BAT files, then (after a reboot of Windows) it becomes accessible to ME as an environment variable as well. It also survives reboots and restarts of ME. (I didn't know that until I tested. In fact I didn't know about the Control Panel way to create the variable until I read it here -- Thanks, Paul.)

Link to comment
Share on other sites

In the future create two separate posts.

.............................................................

For the batch files you can dynamically create them in the macro. This way you can use a variable derived however you like for the driver letter. However in your example I would not use a batch file as it would be easier to use a Program Launch command.

 

If you search some of my posts you will find descriptions of how I create portable macro packages. Essentially the path to the macro file is massaged to create a Macro Folder variable and from that point on all the macro commands use that to find supporting files like INI’s or create things like log files. What I have found to work the best with distributed macros is to have global things like the location of the client’s folders in an INI in the macro folder for all to use. Then preferences and such I store locally in the registry as Paul suggested. This way if the clients folder moves I can change it in one place and also is handy for development testing. Then the users can have personalized settings like email addresses, preferences like if a macro prompts them for a confirmation or not in the registry which can be different for every user.

 

I’m duessing you don’t need to know the exact working folder but rather you could use things like the environmental variable %Temp% which points to the Temp folder. EG you could create a batch file and save it to %Temp%\MEP\SomeStuff.bat and run it from there. That’s the whole idea behind the system temp folder.

Link to comment
Share on other sites

If you search some of my posts you will find descriptions of how I create portable macro packages. Essentially the path to the macro file is massaged to create a Macro Folder variable and from that point on all the macro commands use that to find supporting files like INI's or create things like log files. What I have found to work the best with distributed macros is to have global things like the location of the client's folders in an INI in the macro folder for all to use.

The advantage of Cory's use of .INI files over my suggestion of using the registry is that they can be edited more easily (i.e. by any text editor).

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