create macro: Let's create a small handout with reports .
Posted: 02 May 2023 06:20
I'm going crazy creating macros and I ask you for help starting from simple examples.
If you have links that summarize I would like to know them.
I searched the forum and came across threads that always took for granted something that was too big for my mental capacity.
I need to optimize a script to run as fast as possible. A very good way is to create a code that creates other static code with calculations prepared beforehand.
But I still want to leave some calculations without necessarily pushing this method to the maximum. So I have code that needs to be executed differently depending on certain values.
Instead of using "IF" commands I wanted to create macros to insert into the code using the percent expansion "%" and the trick of eliminating the macro from the environment to perform "set" calculations as quickly as possible.
Request:
1) What changes do I need to make to achieve my goal?
2) for complex code should I use the LF trick? Can I avoid this by putting all the code on one line? What advantages are there?
3) what other precautions should I take into account to use both variables expanded by the "%" and delayed variables "!" at the time of execution of the macro?
4) Can I also use "%" and delayed expansions in the macro definition?
5) When executing the macro, can I use additional "%" and delayed "!" expansions?
This is the schematic of the code to transform/complete:
example of macro1:
or:
How should I define these macros?
EDIT: correct an error on code "else"
If you have links that summarize I would like to know them.
I searched the forum and came across threads that always took for granted something that was too big for my mental capacity.
I need to optimize a script to run as fast as possible. A very good way is to create a code that creates other static code with calculations prepared beforehand.
But I still want to leave some calculations without necessarily pushing this method to the maximum. So I have code that needs to be executed differently depending on certain values.
Instead of using "IF" commands I wanted to create macros to insert into the code using the percent expansion "%" and the trick of eliminating the macro from the environment to perform "set" calculations as quickly as possible.
Request:
1) What changes do I need to make to achieve my goal?
2) for complex code should I use the LF trick? Can I avoid this by putting all the code on one line? What advantages are there?
3) what other precautions should I take into account to use both variables expanded by the "%" and delayed variables "!" at the time of execution of the macro?
4) Can I also use "%" and delayed expansions in the macro definition?
5) When executing the macro, can I use additional "%" and delayed "!" expansions?
This is the schematic of the code to transform/complete:
Code: Select all
@echo off
setlocal EnabledelayedExpansion
For /L %%L in () do (
rem create macro for faster execution
if !condition! equ 1 (
rem create macro1
set "macro1=definition1"
) else (
set "macro1=definition2"
)
call :sub1
)
goto :eof
:sub1
(
set macro1=
For /L %%M in () do (
rem execute macro1
%macro1%
)
)
goto :eof
Code: Select all
for %%G in (!var!) do (
set "array[%%G]=!array[%%G]!!var2!"
set "array2[%%G]=!array2[%%G]!!var2!"
)
Code: Select all
for /L %%G in (1,1,!var2!) do echo %CHAR%!array[%%G]!
EDIT: correct an error on code "else"