Answer» 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.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 Thank you! THANKFULLY my test was rescheduled, so now I know what I'm doing for it. THANKS again for your help!!!
|