| 1. |
Solve : set /a and variable names? |
|
Answer» An example of the code I'm using that works properly. This allows a user to input a numerical value, then the process will loop that many times, letting the user specify a new VARIABLE each time. Your second thought is correct, variable names cannot include spaces They can, but it should be avoided as a rule because sometimes problems can happen, like now when the combination of set /a and delayed expansion is a bit toxic. Really!!! Just shows how far BACK I go, we never had spaces in anything when I were a lad GThanks for the help. I played around with the code above and removed the delayed expansion. Seems set /a just won't play with multi-word variable names. Guess I need to break this bad habit in naming my variables. Just seems so much more logical and easy to ready with spaces. Maybe it's just me. Anywho, thanks again.Quote from: gregory on October 17, 2008, 08:23:29 AM Just seems so much more logical and easy to ready with spaces. Maybe it's just me. Not many programming or scripting languages ALLOW spaces in variable names. With Windows command prompt at least you can use them sometimes, although many serious programmers strongly deplore their use. Underscores hyphens and dots are popular as substitutes. The reason why set /a does not like variable names with spaces is, I think quite simply because unlike simple set, set /a does not require % signs around a variable to the right of the = for operations with literal numbers such as set /a number=number+1 alternative, more compact format: set /a number+=1 and therefore would have trouble DECIDING where variable names end. although of course you would need to use !number! on the right of the = when using delayed expansion. |
|