1.

Solve : Batch file & choices?

Answer»

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
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. 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/Quote from: arough 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/
Good for you. I'm glad you made your own way.


Discussion

No Comment Found