xhai wrote:small problem.. it accept strings how to i change it so it can only accept integers only..
This is funny: your new "small problem" is much more complex than the 2 decimals original one! If you want that the "entry" variable contain just numbers, so the arithmetic operation don't mark any errors, then there are two possible ways to achieve that.
The first one is to read the entry with SET /P and
then review the entry, mark an error if is wrong and repeat the process until the entry is correct. You may read possible methods to check if the entry contain just digits at
Check variable is number post. However, in this case your requirement is more complex, because the program needs
three numbers separated by spaces! Also, you must specify other points; for example, if the entry contains
more than three numbers, do you want to ignore the rest or mark an error? Good luck with that... Of course, you could read just one value per line and check it, so you need to define a subroutine to check the number and call it three times.
Another possible solution is to
restrict the entry so it can only accept numbers; more specifically, to just accept precisely three integers of a maximum of 4 digits each separated by a space. This method is more pleasant for the user and provide a correct entry always. You may use my
ReadFormattedLine subroutine to achieve this in a very simple way; just change this line:
... by this one:
Code: Select all
call :ReadFormattedLine entry="##### ##### #####" /M "%i%- " /F
Of course, you must also include the code of the subroutine in your Batch file, that is "just" 145 lines long!
Finally, I state the solution that, in my opinion, is the best suited for your needs. After this line:
Code: Select all
echo Enter L, W and H values separated by spaces (nothing to end):
... insert this one:
Code: Select all
echo If you enter any wrong value, the program will fail^!
Antonio