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

Author Topic: Using IF command in a batch file...?  (Read 3352 times)

0 Members and 1 Guest are viewing this topic.

Fuzz_64

  • Guest
Using IF command in a batch file...?
« on: April 03, 2004, 10:45:15 AM »
Hello everyone.  I was just wondering if anyone could help me out quickly.  I've been given an assignment by my teacher (yesterday) and he expects me to know a fair amount of information about writing batch files by Monday morning at 9am.  I'm not doing too badly overall so far, but I've run into a wall at the moment.  What I want to do is have a program do output for 1-3 variables.  Here's an example of what I mean.

C:\myprogramname

Hello!

C:\myprogramname Dustin

Hello Dustin!

C:\myprogramname Dustin Lacey

Hello Dustin!  Who is your friend Lacey?

or

C:\myprogramname Dustin Lacey Bob

Hello Dustin!  Who is your friend Lacey?  And what is Bob up to these days?

I'm find with the concepts of using %1, %2 %3, etc etc.  I'm also ok with jumping around a bit in the program using labels.  I'm just having trouble with IF statements.

I can't  figure out how to say if %1 has nothing in it then write "Hello" and skip the rest of the program.

I'm just not sure how to tell if %1 %2 and %3 are empty or not by using an IF statement.  If someone could help me out a bit, that would be much appreciated.  Thank you.

Tom Boykin

  • Guest
Re: Using IF command in a batch file...?
« Reply #1 on: April 07, 2004, 07:38:56 AM »
Sample code:


@echo off
if (%1) == () goto :noparam1
if (%2) ==() goto :noparam2
if (%3) == () goto :noparam3
echo.
echo Hello %1! Who is your friend %2? And what is %3 up to these days?
echo.
goto :exit
:noparam1
echo.
echo ***** Error ***** No parameters were supplied to command
echo.
goto :exit
:noparam2
echo.
echo Hello %1!
echo.
goto :exit
:noparam3
echo.
echo Hello %1! Who is your friend %2?
echo.
:exit

Fuzz_64

  • Guest
Re: Using IF command in a batch file...?
« Reply #2 on: April 07, 2004, 08:36:25 AM »
  :D Thank you!  Thankfully my test was rescheduled, so now I know what I'm doing for it.  Thanks again for your help!!!