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

Author Topic: Wrapping a For command string. (Resolved)  (Read 2756 times)

0 Members and 1 Guest are viewing this topic.

Woodman

    Topic Starter


    Beginner
    Wrapping a For command string. (Resolved)
    « on: April 02, 2009, 09:45:43 PM »
    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
    )
    « Last Edit: April 03, 2009, 02:51:29 AM by Woodman »

    Reno



      Hopeful
    • Thanked: 32
      Re: Wrapping a For command string.
      « Reply #1 on: April 02, 2009, 11:24:06 PM »
      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 interpreter

      Dias de verano

      • Guest
      Re: Wrapping a For command string.
      « Reply #2 on: April 03, 2009, 01:20:40 AM »
      A 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
      )


      Woodman

        Topic Starter


        Beginner
        Re: Wrapping a For command string. (Resolved)
        « Reply #3 on: April 03, 2009, 02:50:46 AM »
        Thank you both for the very quick responses.


        Dias de verano

        • Guest
        Re: Wrapping a For command string. (Resolved)
        « Reply #4 on: April 03, 2009, 03:07:57 AM »
        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

        « Last Edit: April 03, 2009, 03:56:51 AM by Dias de verano »

        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: Wrapping a For command string. (Resolved)
        « Reply #5 on: April 03, 2009, 01:17:28 PM »
        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...
        I was trying to dereference Null Pointers before it was cool.