Computer Hope

Microsoft => Microsoft DOS => Topic started by: Woodman on April 06, 2009, 08:36:06 PM

Title: Using Evaluate in batch script.
Post by: Woodman on April 06, 2009, 08:36:06 PM
XP Home.

With regard to Dias de Verano's reply #4 here (http://www.computerhope.com/forum/index.php/topic,80530.0.html) is there any way of amending the following script to prevent the runtime error "') was unexpected at this time"?

Evaluate formatnumber(22) returns the correctly formatted number when entered at the command prompt.

Code: [Select]

@echo off
cls

for /f %%1 in ('evaluate formatnumber(22)') do (
    set number=%%1
)
echo %number%

Thanks.
Title: Re: Using Evaluate in batch script.
Post by: BC_Programmer on April 06, 2009, 08:49:55 PM
Code: [Select]

@echo off
cls

for /f %%1 in ('evaluate WScript.echo formatnumber(22)') do (
    set number=%%1
)
echo %number%

oops... that doesn't work either.

Ahh- but I see from comparing it to Dias's script:

Code: [Select]

@echo off
cls

for /f %%1 in ('evaluate "formatnumber(22)"') do (
    set number=%%1
)
echo %number%
add quotes around the expression.
Title: Re: Using Evaluate in batch script.
Post by: Dias de verano on April 07, 2009, 12:55:47 AM
Yes, if you have a closing parenthesis in the dataset part of any FOR construct you need to protect it by quoting. This is a batch requirement, not a vbs thing.

Title: Re: Using Evaluate in batch script.
Post by: Woodman on April 07, 2009, 04:03:35 AM
Thank you both for the responses and for your patience with us learners.