1.

Solve : Don't quite understand this??

Answer»

Code: [Select]goto label%errorlevel%

:label0
echo Program had return code 0... No error
goto end

:label1
echo Program had return code 1... Error opening file
goto end

:label2
echo Program had return code 2... Error reading file
goto endThe part where it says "goto label%errorlevel%" Does it mean that it would jump to the ":label" that has the correct errorlevel beside it? And then do whatever tasks that are underneath it? And also, The % on either side of the errorlevel, would that mean that it changes?
If I had something like this:
Code: [Select]@echo off
cls
echo Hi, my name is %1
PAUSE
myname jack
then when you press any key (at the pause part) how does it know that the variable is jack? And if I wanted to make it display, "Hi my name is jack" And then when you press any key it displays "hi, yourname is suzanne" how would you do that?

Thanks to anyone who helps!Quote

The part where it says "goto label%errorlevel%" Does it mean that it would jump to the ":label" that has the correct errorlevel beside it? And then do whatever tasks that are underneath it? And also, The % on either side of the errorlevel, would that mean that it changes?

Yes it does change. Most MS commands issue errorlevels that can be checked in a batch file. (generally 0 indicates the command completed successfully; anything else indicates it didn't....there are exceptions!). Also, the actual compare for errorlevel is equal to or greater than which can present some challenges when checking the codes.

Myname.bat
Code: [Select]@echo off
cls
echo Hi, my name is %1
pause

The %1 is a command line parameter. The number part indicates which parm from the command line to use.

myname Jack
myname Suzanne

Each TIME the batch file myname is run, the first parameter on the command line is substituted for the %1 variable.

myname Jack will output Hi, My name is Jack
myname Suzanne will output Hi, My name is Suzanne

Hope this helps a little. 8-)

PS. Any good DOS book from the library should be ABLE to EXPLAIN this and MUCH more.thanks!


Discussion

No Comment Found