Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Using Evaluate in batch script.  (Read 2568 times)

0 Members and 1 Guest are viewing this topic.

Woodman

    Topic Starter


    Beginner
    Using Evaluate in batch script.
    « on: April 06, 2009, 08:36:06 PM »
    XP Home.

    With regard to Dias de Verano's reply #4 here 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.

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: Using Evaluate in batch script.
    « Reply #1 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.
    I was trying to dereference Null Pointers before it was cool.

    Dias de verano

    • Guest
    Re: Using Evaluate in batch script.
    « Reply #2 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.

    « Last Edit: April 07, 2009, 01:06:18 AM by Dias de verano »

    Woodman

      Topic Starter


      Beginner
      Re: Using Evaluate in batch script.
      « Reply #3 on: April 07, 2009, 04:03:35 AM »
      Thank you both for the responses and for your patience with us learners.