More On User Input

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
sp11k3t3ht3rd
Posts: 26
Joined: 20 May 2010 15:39

More On User Input

#1 Post by sp11k3t3ht3rd » 21 May 2010 19:05

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(,)

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: More On User Input

#2 Post by !k » 22 May 2010 01:21

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:

sp11k3t3ht3rd
Posts: 26
Joined: 20 May 2010 15:39

Re: More On User Input

#3 Post by sp11k3t3ht3rd » 22 May 2010 10:02

So I can't put anything in between the two input questions?

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: More On User Input

#4 Post by jeb » 22 May 2010 10:23

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

sp11k3t3ht3rd
Posts: 26
Joined: 20 May 2010 15:39

Re: More On User Input

#5 Post by sp11k3t3ht3rd » 22 May 2010 13:31

Ooooohhhhhh... Thanks! :)

Post Reply