create macro: Let's create a small handout with reports .

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: create macro: Let's create a small handout with reports .

#16 Post by jeb » 11 May 2023 05:52

Hi einstein1969,
einstein1969 wrote:
06 May 2023 02:17
Then I wanted to ask you why when there are quotation marks you need two ^ carets. Also why does it work with 3 ^ caret too?. see the example that t3rry did.
You can use 2 or 3 carets, because only 2 are necessary, but one more doesn't harm in this case as the extra caret escapes the exclamation mark in phase 2, but there it's superfluous.

Code: Select all

echo Exclam^^!
In phase 2, the first caret escapes the second caret
Now the line looks like echo Exclam^!, the green caret is escaped
In phase 5(delayed expansion) the single caret escapes the exclamation mark

Code: Select all

echo Exclam^^^!
In phase 2, the first caret escapes the second caret, the third caret escapes the exclam, it's superfuous, because in phase2 the exclam has no special meaning
Now the line looks like echo Exclam^!, the green caret and the exclam are escaped
In phase 5(delayed expansion) the single (first) caret escapes the exclamation mark.
einstein1969 wrote:
06 May 2023 02:17
But I wanted to ask you a question. What is your method that you use and have you used to discover the various ways to create macros.
I focus to the goal and go backwards.
My goal was to place the parameters at the end of a macro.

Then I need a blackbox/command/syntax that can get these parameters without any postfix code.
I searched for a solution to

Code: Select all

%blackboxmacro% arg1 arg2
or 
%blackboxmacro% arg1 arg2)
The second form requires an opening parenthesis, but there are only a few possible constructs, an IF-block, a simple block or a FOR-Loop.

Code: Select all

<START OF BLACKBOX>( <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2 )
<START OF BLACKBOX>IF condition ( <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2 )
<START OF BLACKBOX>FOR .. %%X in (something) do (  <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2 )
The IF-Block seems to be not very promising, because it's not better than a simple parentheses block.
But a simple parentheses block has the same problem/complexity like a solution without parenthesizes at all.

Code: Select all

<START OF BLACKBOX> <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2
I thought about the FOR-Block, but obviously it's very tricky, because closing parenthesizes in arg1 or arg2 would destroy the complete logic.
The only good point about FOR-Loops are the fact, that it can execute the block more than once.

But I focused then on the simple form

Code: Select all

<START OF BLACKBOX> <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2
Which command could get arg1 and arg2 without throwing an error?
I saw the possible solutions in SET or CALL somebatch.bat, perhaps something like redirection or pipes, but that didn't seem possible.
After the possible last commands of the blackbox were found, the next question occurs, how to work with a value which is set at the end?
This was obviously (really), because there is only one possible command that do things after it do something at the end, and that's a FOR-Loop.
The rest is history.

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: create macro: Let's create a small handout with reports .

#17 Post by jeb » 11 May 2023 05:53

Hi einstein1969,
einstein1969 wrote:
06 May 2023 02:17
Then I wanted to ask you why when there are quotation marks you need two ^ carets. Also why does it work with 3 ^ caret too?. see the example that t3rry did.
You can use 2 or 3 carets, because only 2 are necessary, but one more doesn't harm in this case as the extra caret escapes the exclamation mark in phase 2, but there it's superfluous.

Code: Select all

echo Exclam^^!
In phase 2, the first caret escapes the second caret
Now the line looks like echo Exclam^!, the green caret is escaped
In phase 5(delayed expansion) the single caret escapes the exclamation mark

Code: Select all

echo Exclam^^^!
In phase 2, the first caret escapes the second caret, the third caret escapes the exclam, it's superfuous, because in phase2 the exclam has no special meaning
Now the line looks like echo Exclam^!, the green caret and the exclam are escaped
In phase 5(delayed expansion) the single (first) caret escapes the exclamation mark.
einstein1969 wrote:
06 May 2023 02:17
But I wanted to ask you a question. What is your method that you use and have you used to discover the various ways to create macros.
I focus to the goal and go backwards.
My goal was to place the parameters at the end of a macro.

Then I need a blackbox/command/syntax that can get these parameters without any postfix code.
I searched for a solution to

Code: Select all

%blackboxmacro% arg1 arg2
or 
%blackboxmacro% arg1 arg2)
The second form requires an opening parenthesis, but there are only a few possible constructs, an IF-block, a simple block or a FOR-Loop.

Code: Select all

<START OF BLACKBOX>( <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2 )
<START OF BLACKBOX>IF condition ( <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2 )
<START OF BLACKBOX>FOR .. %%X in (something) do (  <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2 )
The IF-Block seems to be not very promising, because it's not better than a simple parentheses block.
But a simple parentheses block has the same problem/complexity like a solution without parenthesizes at all.

Code: Select all

<START OF BLACKBOX> <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2
I thought about the FOR-Block, but obviously it's very tricky, because closing parenthesizes in arg1 or arg2 would destroy the complete logic.
The only good point about FOR-Loops are the fact, that it can execute the block more than once.

But I focused then on the simple form

Code: Select all

<START OF BLACKBOX> <BLACK-MAGIC> <END OF BLACKBOX>  ... arg1 arg2
Which command could get arg1 and arg2 without throwing an error?
I saw the possible solutions in SET or CALL somebatch.bat, perhaps something like redirection or pipes, but that didn't seem possible.
After the possible last commands of the blackbox were found, the next question occurs, how to work with a value which is set at the end?
This was obviously (really), because there is only one possible command that do things after it do something at the end, and that's a FOR-Loop.
The rest is history.

einstein1969
Expert
Posts: 960
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: create macro: Let's create a small handout with reports .

#18 Post by einstein1969 » 16 May 2023 11:19

thanks jeb, I didn't answer right away because I couldn't enter the forum

Post Reply