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

Author Topic: Batch file & choices  (Read 3230 times)

0 Members and 1 Guest are viewing this topic.

arough

    Topic Starter


    Newbie

    Batch file & choices
    « on: November 13, 2009, 04:27:24 AM »
    I'm new to this level of programing so forgive me if any of this is stupid. I'm trying to write a batch file that reads from a spread sheet and does something based on an input.

    I already got it reading and doing with:

    for /f "skip=1 delims=, tokens=1,2,3,4,5,6,7,8,9,10,11,12,12" %%g in (users1.csv) do set choice=%%p


    IF %choice% ==ONE GOTO ONE
    IF %choice% ==TWO GOTO TWO
    IF %choice% ==THREE GOTO THREE

    Where %%p is a colum in the spreadsheet and chice is just a variable. However i want to change it so rather than entering this choice on the spreadsheet they are propted for it. i.e.

    Press A for One
    Press B for Two

    Enter A or B

    I started by putting :

    for /f "skip=1 delims=, tokens=1,2,3,4,5,6,7,8,9,10,11,12,12" %%g in (users1.csv)  do  CHOICE /C:abc

    IF ERRORLEVEL ==2 GOTO TWO
    IF ERRORLEVEL ==1 GOTO ONE


    This worked for the first row on the spreadhseet but i can't get it to work for the following rows. I get the prmpts to enter abc... for the number of rows but this dosn't translate into jumping to the code section, running the code and then repeating for the next row.

    Hope thats clear, if you need anything else let me know. Full code bellow and spreadsheet is a csv file of peoples details.


    @ECHO OFF
    :BEGIN
    CLS


    ECHO Enter Letter for site:
    ECHO a for one
    ECHO b for two
    ECHO c for thre


    for /f "skip=1 delims=, tokens=1,2,3,4,5,6,7,8,9,10,11,12,12" %%g in (users1.csv)do (ECHO %%g
    for /f "skip=1 delims=, tokens=1,2,3,4,5,6,7,8,9,10,11,12,12" %%g in (users1.csv)  do  CHOICE /C:abcdefghijklmno


    IF ERRORLEVEL ==3 GOTO THREE
    IF ERRORLEVEL ==2 GOTO TWO
    IF ERRORLEVEL ==1 GOTO ONE
    GOTO END


    :THREE
    ECHO YOU HAVE PRESSED three
    GOTO END

    :TWO
    ECHO YOU HAVE PRESSED two
    ECHO %%g
    GOTO END

    :ONE
    ECHO YOU HAVE PRESSED ONE
    GOTO END

    :END

    Helpmeh



      Guru

    • Roar.
    • Thanked: 123
      • Yes
      • Yes
    • Computer: Specs
    • Experience: Familiar
    • OS: Windows 8
    Re: Batch file & choices
    « Reply #1 on: November 13, 2009, 04:38:30 AM »
    I'm just going to shorten your code. Instead of listing every number from x to y, why not do this instead?
    tokens=1-12

    So thr correct syntax would be:
    for /f "Skip=1 tokens=1-12 delims=," %%g in (whatever) do (
    command a
    command b
    ...
    )

    you can have as many commands as you like within the braclets.
    Where's MagicSpeed?
    Quote from: 'matt'
    He's playing a game called IRL. Great graphics, *censored* gameplay.

    arough

      Topic Starter


      Newbie

      Re: Batch file & choices
      « Reply #2 on: November 19, 2009, 02:07:00 AM »
      Thanks for the code shortening.

      I've given up trying to code my way out of this and created an excel macro which i linked to the batch file to do what i need. Cheers for the help/

      Helpmeh



        Guru

      • Roar.
      • Thanked: 123
        • Yes
        • Yes
      • Computer: Specs
      • Experience: Familiar
      • OS: Windows 8
      Re: Batch file & choices
      « Reply #3 on: November 19, 2009, 04:51:52 AM »
      Thanks for the code shortening.

      I've given up trying to code my way out of this and created an excel macro which i linked to the batch file to do what i need. Cheers for the help/
      Good for you. I'm glad you made your own way.
      Where's MagicSpeed?
      Quote from: 'matt'
      He's playing a game called IRL. Great graphics, *censored* gameplay.