Set /a switch

A

ALF

hi, any ideas why I cannot get the right answer when I'm
using set /a totalfiles=6,220+1,000. But, when I remove
the comma it works fine. Do I miss something?

thanks in advance,
AL
 
R

Ritchie

ALF said:
hi, any ideas why I cannot get the right answer when I'm
using set /a totalfiles=6,220+1,000. But, when I remove
the comma it works fine. Do I miss something?

In the SET /A command, the comma is used to separate expressions:-

set /a a=2,b=2,c=a+b

If the numbers that you're trying to add were parsed from the DIR
command, you could use it's /-C switch to disable the commas.
Otherwise you could remove them using variable substitution, see
SET/? or by specifying a comma as the DELIMS in a FOR /F statement,
see FOR/?.
 
M

Marty List

Alf said:
Thanks. Just a follow up question, how do I set the output
back to default.

ex. set /a 1000+2000 = 3000. Needed output is 3,000.

thanks again.


Read the syntax built-in to the SET command, using "SET /?". You can use :~
to do variable substitution. This will handle numbers under 1 trillion
(999,999,999,999).

Remove the line numbers (use them to identify unwanted line
wraps)

01. @Echo Off
02. SetLocal EnableExtensions
03. Set /a TOTAL=1000+2000
04. Echo %TOTAL%
05. Call :_ADD_COMMAS %TOTAL% TOTAL
06. Echo %TOTAL%
07. GoTo :EOF
08.
09. :_ADD_COMMAS
10. Set BUFFER=%1
11. If Not Defined BUFFER Set BUFFER=0
12. If Not "%BUFFER:~0,-3%" == "" Set BUFFER=%BUFFER:~0,-3%,%BUFFER:~-3,3%
13. If Not "%BUFFER:~0,-7%" == "" Set BUFFER=%BUFFER:~0,-7%,%BUFFER:~-7,7%
14. If Not "%BUFFER:~0,-11%" == "" Set
BUFFER=%BUFFER:~0,-11%,%BUFFER:~-11,11%
15. Set %2=%BUFFER%
16. GoTo :EOF
 
A

Alf

thanks Marty. How come it doesn't work in windows NT?
-----Original Message-----




Read the syntax built-in to the SET command,
using "SET /?". You can use :~
 
M

Marty List

Alf said:
thanks Marty. How come it doesn't work in windows NT?

I assume you mean NT 4.0, because it does work on NT 5.0 (aka Windows 2000),
NT 5.1 (aka Windows XP) and NT 5.2 (aka Windows Server 2003). The main
reason it doesn't work on NT4 is you posted this question in a Windows 2000
newsgroup, and didn't mention that you needed it to work on NT4. Some of
the options used for the SET command were added starting with Windows 2000.
I don't have access to NT4 right now, but if you look at the SET /? syntax
under NT4 you'll easily see why it's not working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top