Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

WAD handling variables with $-prefix

Aug
258
4
Hi,

I'm doing some considerations for a script to create a fileage-report.
In preparation for this I'm using variables beginning with the $-sign, which should be allowed
as the help says "The environment variable names you use this way may contain any alphabetic or numeric characters, the underscore character _, and the dollar sign $"
But I have a funny behavior: when I issue the commands at the prompt, they are ok
Code:
C:\Program Files\JPSoft\TCMD13x64 >ver
 
TCC  13.04.63 x64  Windows 7 [Version 6.1.7601]
 
C:\Program Files\JPSoft\TCMD13x64 >plugin
TCC: No plugins loaded
 
C:\Program Files\JPSoft\TCMD13x64 >set    $yearsback=10
 
C:\Program Files\JPSoft\TCMD13x64 >set    $lastindex=%@eval[%$yearsback + 1]
 
C:\Program Files\JPSoft\TCMD13x64 >set    /a $nelements=%$yearsback + 2
12
 
C:\Program Files\JPSoft\TCMD13x64 >set    /a $baseyear=%_year - %$yearsback
2002
 
C:\Program Files\JPSoft\TCMD13x64 >
C:\Program Files\JPSoft\TCMD13x64 >set    $*
$baseyear=2002
$lastindex=11
$nelements=12
$yearsback=10
 
C:\Program Files\JPSoft\TCMD13x64 >
C:\Program Files\JPSoft\TCMD13x64 >unsetarray /q array
 
C:\Program Files\JPSoft\TCMD13x64 >setarray array[%$nelements]
 
C:\Program Files\JPSoft\TCMD13x64 >echo    %@arrayinfo[array,0]
  1
 
C:\Program Files\JPSoft\TCMD13x64 >echo    %@arrayinfo[array,5]
  12
and if I run them as a btm they do not work.
Code:
C:\Program Files\JPSoft\TCMD13x64 >filecount_per_year.btm
echo    on
setlocal
on      break goto end
rem    The environment variable names you use this way may contain any alphabetic or numeric characters,
rem    the underscore character _, and the dollar sign $
set    $yearsback=10
set    $lastindex=1
set    /a $nelements=yearsback + 2
set    /a $baseyear=2012 - yearsback
set    $*
$baseyear=2012
$lastindex=1
$nelements=2
$yearsback=10
unsetarray /q array
setarray array[nelements]
C:\Program Files\JPSoft\TCMD13x64\filecount_per_year.btm [16]  Usage : SETARRAY name[a[,b[,c[,c]]]] [...]
echo    1
  1
echo    0
  0
endlocal
quit

Neither "SET /A" nor "@EVAL" can handle the $variables.
Am I on the wrong track?
 
Hmmm!. The character is legal in variable names. Bit "%$" also has a meaning of its own. And the help doesn't say all legally-named variables may be freely de-referenced with "%". There's no problem if you de-reference them with %[]. I wonder what Rex will say.
Code:
v:\> type dollar.btm
echo on
set    $yearsback=10
set    $lastindex=%@eval[%[$yearsback] + 1]
set    /a $nelements=%[$yearsback] + 2
set    /a $baseyear=%_year - %[$yearsback]
set $*
unsetarray /q array
setarray array[%[$nelements]]
echo    %@arrayinfo[array,0]
echo    %@arrayinfo[array,5]
 
v:\> dollar.btm
set    $yearsback=10
set    $lastindex=11
set    /a $nelements=10 + 2
set    /a $baseyear=2012 - 10
set $*
$baseyear=2002
$lastindex=11
$nelements=12
$yearsback=10
unsetarray /q array
setarray array[12]
echo    1
  1
echo    12
  12
 
Vince, %[] is a cool idea, but makes it unnecessarry complicated.
Then I would abdicate the dollar-sign.
Perhaps I should use the euro-sign € ;)
 
Vince, %[] is a cool idea, but makes it unnecessarry complicated.
Then I would abdicate the dollar-sign.
Perhaps I should use the euro-sign € ;)
Is the Euro symbol readily accessible (wouldn't know here in the states). Do you need a prefix at all?

P.S., The "Frank" image is a bit unnerving but it brings back fond memories and has prompted me to listen (after a long time) to some of the most creative music I can think of.
 
There are a few other places where the %[] notation is needed ... IIRC, in "DO x" and "FOR %x" routines, because one-letter variable names have some preference.
 
Is the Euro symbol readily accessible (wouldn't know here in the states).
I can access it on my german keyboard with AltGr-E.
Do you need a prefix at all?
No, it's just for having them all togehter with a "set $*". I thought it could be convenient for my little "project" because I fear I will have to check the variables very often;)

P.S., The "Frank" image is a bit unnerving but it brings back fond memories and has prompted me to listen (after a long time) to some of the most creative music I can think of.
I'm very happy I brought FZ back in mind. I am/was a really big fan since I was ~16 years old.
But why is the picture unnerving? Do you think the other forum members could be nerved, too?
Please let me know.
 
I'm very happy I brought FZ back in mind. I am/was a really big fan since I was ~16 years old.
But why is the picture unnerving? Do you think the other forum members could be nerved, too?
Please let me know.
Basically because he's no longer with us and I figure if that were not the case **someone** would, today, be making new music that I like. I'm not offended by the image; it just makes me think.
 
And just to jog a few more memories, last week, Donovan (as in Donovan Leitch) performed at a jazz festival here in Syracuse, NY.
 
I've choosen the picture as a kind of hommage. And sometimes I get the blues, too, if I think of former times :cool:
 
what do you think of this version?
Code:
echo    on
setlocal
on      break goto end
 
set    _$yearsback=10
set    _$lastindex=%@eval[%_$yearsback + 1]
set    /a _$nelements=%_$yearsback + 2
set    /a _$baseyear=%_year - %_$yearsback
 
set    _$*
 
unsetarray /q _$array
setarray _$array[%_$nelements]
echo    %@arrayinfo[_$array,0]
echo    %@arrayinfo[_$array,5]
 
endlocal
quit
which doesn't run into the %$ trap:
Code:
echo    on
setlocal
on      break goto end
set    _$yearsback=10
set    _$lastindex=11
set    /a _$nelements=10 + 2
set    /a _$baseyear=2012 - 10
set    _$*
_$baseyear=2002
_$lastindex=11
_$nelements=12
_$yearsback=10
unsetarray /q _$array
setarray _$array[12]
echo    1
  1
echo    12
  12
endlocal
quit
 
Hi,

I'm doing some considerations for a script to create a fileage-report.
In preparation for this I'm using variables beginning with the $-sign, which should be allowed
as the help says "The environment variable names you use this way may contain any alphabetic or numeric characters, the underscore character _, and the dollar sign $"
But I have a funny behavior: when I issue the commands at the prompt, they are ok

WAD -- see the help for "batch file parameters". %$ has a different meaning in batch files.
 
I have a vague memory that the help file once strongly recommended beginning variable names with a letter. Now I can't find it. Was the suggestion removed, or is this just a Fig Newton of my imagination?
 
I don't know that it was ever in the documentation, but it is definitely a good idea. Variable names beginning with a '_' are assumed to be internal variables (though you can override them with an environment variable, after a wasted search through the internal list), and variables beginning with a number or '$' are treated as batch (or alias) parameters.

If users are suffering from an overwhelming compulsion to use otherwise invalid characters in variable names, they can always use the %[] syntax.
 
I don't know that it was ever in the documentation, but it is definitely a good idea. Variable names beginning with a '_' are assumed to be internal variables (though you can override them with an environment variable, after a wasted search through the internal list), and variables beginning with a number or '$' are treated as batch (or alias) parameters.

If users are suffering from an overwhelming compulsion to use otherwise invalid characters in variable names, they can always use the %[] syntax.
Yet a little bit stressed? Not very politely :(
I don't know why I ran into this trap. Normally I do not use any prefixes in my variables.
And I said
Am I on the wrong track?
 

Similar threads

Back
Top