Page 1 of 1

More On User Input

Posted: 21 May 2010 19:05
by sp11k3t3ht3rd
Why doesn't this code work?

Code: Select all

@echo off
cls
title Java Code Generator
echo An example of an item number would be: 995
set /p itemNumber =Please type the item number here:
pause
echo The number of items can range from 1 to 999999999 in most cases.
set /p numberOfItem =Please type the number of that item here:
echo addItem(%itemNumber%,%numberOfItem%) > AddItemCode.txt
pause
cls
echo Your code has been place in a .txt file named AddItemCode.txt. You will find this file in the directory this program is in.
pause
exit

when you open the file makes it only prints out the addItem(,)

Re: More On User Input

Posted: 22 May 2010 01:21
by !k
You have unwanted spaces

Code: Select all

set /p itemNumber=Please type the item number here: 
set /p numberOfItem=Please type the number of that item here:

Re: More On User Input

Posted: 22 May 2010 10:02
by sp11k3t3ht3rd
So I can't put anything in between the two input questions?

Re: More On User Input

Posted: 22 May 2010 10:23
by jeb
sp11k3t3ht3rd wrote:So I can't put anything in between the two input questions?


No,what !k said is, that it these two lines are different

Code: Select all

set /p itemNumber=Please type the item number here: 
set /p itemNumber =Please type the item number here:


If you place a space between the itemNumber and the equal sign the name of the variable will be "itemNumber ", and that's why your echo failed

Code: Select all

echo %itemNumber% is empty
echo %itemNumber % should work


jeb

Re: More On User Input

Posted: 22 May 2010 13:31
by sp11k3t3ht3rd
Ooooohhhhhh... Thanks! :)