|
Answer» I'm making a bat file that needs a CD key to start installation of a program that I made but it doesn't accept the key I made with the code and with any key it gives this error "missing operator". The code for the bat file is
Code: [Select]echo off rem xxxxx-xx-xxx-x rem xxxxx-xx-xxx-3 rem xxxxx-xx-112-3 rem xxxxx-22-112-3 rem 03256-22-112-3 rem 03256/22-112/3=12 cls echo. echo. echo. echo welcome %USERNAME% to random DESKTOP wallpaper installer by Matthew fosdick pause cls echo. echo. echo. echo you will need 9 photos, you CD key, this CD, and aprox. 12.3 MB Hard disk space. pause cls :CD echo. echo. echo. echo please enter the first 6 digits of your CD key. EX. 123456-xx-xxx-x set /P key1=key: cls echo Thank you. please enter the next 2 digits of your CD key. EX. xxxxxx-78-xxx-x set /p key2=key: cls echo Thank you. please enter the next 3 digits of your CD key. EX. xxxxxx-xx-901-x set /p key3=key: cls echo Thank you. please enter the last digits of your CD key. EX. xxxxxx-xx-xxx-2 set /p key4=key: cls echo Thank you. We will check your key in the moment. pause set /a c="%key1%/%key2%' set /a d="%c%-%key3% set /a e="%d%/%key4% if "%e%"=="12" goto con goto CD
:con echo Thank you. we will begin installation in a moment pause What key are you attempting to use?the key is at the top of the bat file it is 03256-22-112-3 Try removing the leading 0. So the first number would be 3256 instead of 03256.iI dont get a missing operator error any more but pause command at the end is not working.Sometimes the /a switch of the set command can confuse numbers with leading zeros with something else that requires more operators.Here's your problem-
Code: [Select]set /a c="%key1%/%key2%' set /a d="%c%-%key3% set /a e="%d%/%key4% 1. The missing operator message is caused by those quotes which should either not be there (preferably) or at least match them start and end if you insist on having them (why?) 2. A leading zero causes set /a to read the number as an octal value. 3. See below
Code: [Select]echo off rem correct key is 03256-22-112-3 rem therefore... set key1=03256 set key2=22 set key3=112 set key4=3
rem neutralize any leading zeroes for each key
rem key1 has 5 digits so add 100000 (by prepending a 1) set key1string=1%key1% rem now take it away again with set /a set /a key1=%key1string%-100000
rem key2 has 2 digits so add 100 (by prepending a 1) set key2string=1%key2% rem now take it away again with set /a set /a key2=%key2string%-100
rem key3 has 3 digits so add 1000 (by prepending a 1) set key3string=1%key3% rem now take it away again with set /a set /a key3=%key3string%-1000
rem key4 has 1 digits so add 10 (by prepending a 1) set key4string=1%key4% rem now take it away again with set /a set /a key4=%key4string%-10
echo Numerical values: echo key1=%key1% echo key2=%key2% echo key3=%key3% echo key4=%key4%
set /a c=%key1%/%key2% echo Arithmetic operation (1) %key1%/%key2%=%c%
set /a d=%c%-%key3% echo Arithmetic operation (2) %c%-%key3%=%d%
set /a e=%d%/%key4% echo Arithmetic operation (3) %d%/%key4%=%e%
if "%e%"=="12" echo Correct!
Code: [Select]Numerical values: key1=3256 key2=22 key3=112 key4=3 Arithmetic operation (1) 3256/22=148 Arithmetic operation (2) 148-112=36 Arithmetic operation (3) 36/3=12 Correct!thank you it works great does it need modification if the first GROUP has 6 digits ex 123456
Quote from: mat123 on March 06, 2010, 02:54:46 PM does it need modification if the first group has 6 digits ex 123456
It should be obvious that the answer is "yes". I thought I had provided enough clues in the REMS. Study them. i have a new problem any other key other than the 03256 key doesn't work ex 22428-89-156-8 22428/89=252 252-156=96 96/8=12Are you sure?
Code: [Select]Numerical values: key1=22428 key2=89 key3=156 key4=8 Arithmetic operation (1) 22428/89=252 Arithmetic operation (2) 252-156=96 Arithmetic operation (3) 96/8=12 Correct!it works now must have been something with my computer and is there any programing errors in this code for the key generator
echo off :A cls Set /a key2=(%Random% %%89)+10 Set /a key3=(%Random% %%899)+100 Set /a key4=(%Random% %%9)+1
set /a e="12"*"%key4%" set /a d="%e%"+"%key3%" set /a key1="%d%"*"%key2%" echo your key is %key1%-%key2%-%key3%-%key4% pause goto a well, it produces keys...
why are you using those quote marks? oops read the page for the set command wrong
|