That is SO, SO, SO unusual.... I don't think it would ever have occurred to me to enclose the expression in quotes...
Thank you
Main Topics
Browse All TopicsDue to serious lack of sleep I am having difficulties concentrating on the following:
The problem is this. The simple condiional statements work well on their own however, when the conditional statements are combined the code produces an error.
I am not concerned with the mathematical formulas.
For the curious though, the code simply generates a year-value. If no parameters are passed then it generates a random date between 1752 to the current year. If parameters are passed then it generates a random year-value between %1 and %2. If only one parameter is passed then a year-value is not generated.
CODE 1 (Works okay)
@echo off
if "%1"=="" set /a RndYear = %random% %% (%date:~6,4% - 1752 + 1) + 1752
if not "%1"=="" if "%2"=="" exit /b
if not "%1"=="" set /a RndYear = %random% %% (%2 - %1 + 1) + %1
exit /b %RndYear%
CODE 2 (Same code using nested IFs - does not work)
@echo off
if "%1"=="" (
set /a RndYear = %random% %% (%date:~6,4% - 1752 + 1) + 1752
) else (
if "%2"=="" (
exit /b
) else (
if not "%1"=="" set /a RndYear = %random% %% (%2 - %1 + 1) + %1
)
)
exit /b %RndYear%
I have tried negating the conditions however, I receive the same error.
This may be a simple problem as it may be due to something I have overlooked. As I said, I'm dog-tired and mentally drained.
I have deliberately not included the error message because glancing at the code, both appear to be logically and lexically correct. My XP DOS version is 5.1.2600.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: MMierzwaPosted on 2009-04-28 at 00:41:38ID: 24248387
It seems that problem is in set not with if.
Try to put it in " ".
set /a RndYear = "%random% %% (%date:~6,4% - 1752 + 1) + 1752"
Should work.