Solved

Batch Variable Behavior in Blocks

Posted on 2008-10-22
3
205 Views
Last Modified: 2010-04-21
Hello,

In a batch program I have a variable that performs different when within a block of code (see snippet).  If the code is executed in an IF statement  block %CONNECTIONS_VALUE% equals "" (double quotes).  If I remark out the IF statement start and end lines the value returned is correct.

What needs to be changed in standard Windows batch files to retain variables set in a block of code?

Thanks,

Michael

set CHECK_CONNECTIONS=1
 

if not %CHECK_CONNECTIONS% == 0 (

   set CONNECTIONS_VALUE=25

)
 

echo CONNECTIONS_VALUE: %CONNECTIONS_VALUE%

Open in new window

0
Comment
Question by:michael4606
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 125 total points
ID: 22783936
Works fine for me both ways.... odd.  So you are saying that

set CHECK_CONNECTIONS=1
 
REM if not %CHECK_CONNECTIONS% == 0 (
   set CONNECTIONS_VALUE=25
REM )
 
echo CONNECTIONS_VALUE: %CONNECTIONS_VALUE%

returns "" (actually "" and not blank?).  For me it returns 25 as expected?

Is this actual cut and paste of what you are doing or amended, could be you have additional spaces in or something etc.

Steve
0
 

Author Closing Comment

by:michael4606
ID: 31508877
>> could be you have additional spaces in or something

Perhaps so.  Also it seems I needed to use: setlocal ENABLEDELAYEDEXPANSION
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 22785302
You shouldn't need to do that, that is normally used within FOR loops so that a result computed as part of the script is computed each time around rather than once when the script is run but heh if it works for your script great!

thanks
Steve
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now