-
February 23rd, 2006, 08:28 PM
#1
[RESOLVED] batch: IF ELSE STATEMENT
IF ELSE STATEMENT
Since there is no else statement in Batch script. How do I by pass that?
I want this script will ask for a name if the name doesn't match the input.
The name will be hardcode, so the person who run it doesn't enter his/her name everything. It just goes directly to check status right away and print out the message.
Why this not working the way I want it?
This will goes through all command even though I try to put in JOHN or DAVE.
How can I covert the user input to all CAPS or the variable %NAME% to all CAPS?
---------
Code:
@ECHO OFF
SET NAME="ENTER_NAME_HERE"
GOTO :START_MENU
:START_MENU
IF %NAME% == "ENTER_NAME_HERE" GOTO :ASK_MENU
:END
:ASK_MENU
SET /P NAME="ENTER NAME: " GOTO :CHECK_MENU
:END
:CHECK_MENU
IF %NAME% == "JOHN" GOTO :JOHN_MENU
IF %NAME% == "DAVE" GOTO :DAVE_MENU
:END
:JOHN_MENU
ECHO YOUR NAME IS: %NAME% HAVE A NICE DAY!
:END
:DAVE_MENU
ECHO YOUR NAME IS: %NAME% PEACE OUT!
:END
PAUSE
---------------
thanks for the help..
-
February 23rd, 2006, 10:11 PM
#2
Re: batch: IF ELSE STATEMENT
Sorry to tell you but there is no way to change cases in just plain DOS.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
February 23rd, 2006, 10:48 PM
#3
Re: batch: IF ELSE STATEMENT
You might want to try it in VB Script. You can use Visual Basic commands to convert the case, and use IF-THEN-ELSE statements.
-
February 21st, 2008, 05:40 PM
#4
Re: [RESOLVED] batch: IF ELSE STATEMENT
You can simulate IF ELSE statement like this:
Code:
@echo off
set answer=one
if not "%1" == "1" (
set answer=two
if not "%1" == "2" (
goto bad_argument
)
)
echo Argument %1 is %answer%
goto end
:bad_argument
echo Bad Argument
:end
Last edited by PeejAvery; February 22nd, 2008 at 08:05 AM.
Reason: Added code tags.
-
March 3rd, 2008, 04:40 PM
#5
Re: [RESOLVED] batch: IF ELSE STATEMENT
There is indeed IF-ELSE syntax in batch. This works for me, but you have to be sure to use it exactly as shown:
Code:
IF <statement> (
..
..
) ELSE (
...
...
)
I believe the parentheses must be used exactly as shown above, or the statement won't work properly.
I have not, however, found a nice way to handle ELSE-IF statements. So, you have to make big nested IF blocks:
E.g.
IF <statement> (
IF <statement> (
...
) ELSE (
...
)
) ELSE (
...
)
One annoyance I've noticed is that assignments (i.e. SET statements) made within an IF block are not realized until AFTER the IF-bock. So, in other words, you can't rely on variable assignment within an IF-block.
Last edited by Quimbly; March 4th, 2008 at 12:55 PM.
-
June 10th, 2009, 10:12 AM
#6
Re: [RESOLVED] batch: IF ELSE STATEMENT
A way to use an IF ELSE IF statement is simply nest the ELSE IF
IF <arg> (
....
) ELSE (
IF (
......
)
......
)
-
June 10th, 2009, 12:09 PM
#7
Re: [RESOLVED] batch: IF ELSE STATEMENT
Welcome to the forums IT Man. Please remember to keep your posts relevant. This thread is over a year old.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|