1.

Solve : Wrapping a For command string. (Resolved)?

Answer»

Win XP Home.

Is it possible to WRAP a string in a For command so that the entire contents of the string can be displayed on a standard 80-column screen when using Edit.com? I've tried the caret which gives an invalid SYNTAX.

Example - December") do ( is offscreen.

Code: [Select]
@echo off
cls

for /f "tokens=%1" %%1 in (
"January February March April May June July August September October November December") do (
echo %%1 is month number %1
)
for /f "tokens=%1" %%1 in (
"January February March April May June July"
"August September October November December"
) do (
echo %%1 is month number %1
)

no, i don't think it's possible.
command line interpreterA parenthetical structure like the dataset of a FOR construct cannot be broken e.g. with carets but other lines can, and long strings can be put in variables and expanded by cmd.exe at run TIME.

Code: [Select]@echo off
set Months=January February March April
set Months=%Months% May June July August
set Months=%Months% September October November December
for /f "tokens=%1" %%1 in ("%Months%") do (
echo %%1 is month number %1
)

or...

Code: [Select]@echo off
set Months=January February March April ^
May June July August ^
September October November December
for /f "tokens=%1" %%1 in ("%Months%") do (
echo %%1 is month number %1
)

Thank you both for the very quick responses.

Not strictly answering the question, but I couldn't resist this, using my trusty Evaluate script

Code: [Select]@echo off
echo Wscript.echo eval(WScript.Arguments(0))>Evaluate.vbs
For /f %%A in ( ' cscript //nologo Evaluate.vbs "MonthName(%1)" ' ) do (
echo %%A is month number %1
)


Plus, if you

1. Just put the script somewhere on your PATH

Evaluate.vbs

Code: [Select]Wscript.echo eval(WScript.Arguments(0))
2. Set the default script engine to Cscript.exe (it sticks till you change it)

Code: [Select]cscript //H:CScript
3. Set the default cscript behaviour to nologo (again, sticks until you save the opposite option)

Code: [Select]cscript //Nologo /S
... if you do these things the FOR line contracts down to


Code: [Select]For /f %%A in ( ' Evaluate "MonthName(%1)" ' ) do (
and

Code: [Select]evaluate "expression"
gives you all kinds of goodies (consult VBS documentation, not everything works, but a handy subset does)

USE quotes if there are spaces in the expression

like

Code: [Select]
C:\>evaluate weekdayname(weekday(date),0)
Friday

C:\>evaluate weekdayname(weekday(date),1)
Fri

C:\>evaluate 5/2
2.5

C:\>evaluate (date-1)
02/04/2009

C:\>evaluate (date+1)
04/04/2009

C:\>evaluate day(date)
3

C:\>evaluate month(date)
4

C:\>evaluate sqr(25)
5

C:\>evaluate sqr(26)
5.09901951359278

C:\>evaluate formatnumber(sqr(2),1)
1.4

C:\>evaluate formatnumber(sqr(2),2)
1.41

C:\>evaluate formatnumber(sqr(2),3)
1.414

C:\>evaluate formatnumber(sqr(2),4)
1.4142

C:\>evaluate formatnumber(sqr(2),5)
1.41421

C:\>evaluate Monthname(1,0)
January

C:\>evaluate Monthname(1,1)
Jan

C:\>evaluate FormatDateTime(date(),0)
4/3/2009

C:\>evaluate FormatDateTime(date(),1)
Friday, April 03, 2009

C:\>evaluate FormatDateTime(time(),3)
10:34:17 AM

C:\>evaluate FormatDateTime(time(),4)
10:34

C:\>evaluate timer
38112.15

And then, for a heavyweight experience, we have the virtually unusable and wholly undocumented (and thus useless) BCScript and BCEval:


Code: [Select]D:\VBPROJ\VB\BASeParser\bceval>bceval Sqr(12-14*2)+23
parsed Expression Sqr(12-14*2)+23
result:
23 + 4i

D:\VBPROJ\VB\BASeParser\bceval>BCeval {1,2,3}*{4,5,6}
parsed Expression {1,2,3}*{4,5,6}
result:
{{4,5,6},{8,10,12},{12,15,18}}

D:\VBPROJ\VB\BASeParser\bceval>BCeval ({1,2,3}*{4,5,6})*2
parsed Expression ({1,2,3}*{4,5,6})*2
result:
{{8,10,12},{16,20,24},{24,30,36}}

D:\VBPROJ\VB\BASeParser\bceval>BCeval ({1,2,3}*{4,5,6})*i
parsed Expression ({1,2,3}*{4,5,6})*i
result:
!Error #438("Object doesn't support this property or method in op *")!

D:\VBPROJ\VB\BASeParser\bceval>


Note that the last one, multiplying an Array (list) by imaginary number i fails. I thought about it and it's because I didn't implement that yet.

I also need to make it's output batch-friendly. I've only reaffirmed to myself that I NEED documentation on the functions and operators and so forth in the Evaluator. I forgot the syntax for my SEQ() and SEQEX() functions...



Discussion

No Comment Found