Archive for December, 2007

Small Update of VBA Library

Sunday, December 30th, 2007

As I am working on some small Excel Project, I have stuffed some new things in the VBA Library. There are new functions for talking to MS Word and MS Outlook and one function to compare arrays. Not very fancy, but I post it here anyway to make sure I don’t forget that they are there and ready to be used.

The library can be found here.

Classic for-loop in a windows batch file

Monday, December 17th, 2007

Question: How can a classic for loop

for (int i=0;i<10;++i) {
// do stuff
}

be realized in a windows batch file?

Answer:

echo off
SET /a i=0

:loop
IF %i%==10 GOTO END
echo This is iteration %i%.
SET /a i=%i%+1
GOTO LOOP

:end
echo That’s it!

The answer uses goto and the /A option of the set command. Without that option, SET interprets the right side of the equals sign as a string and i would contain ‘i+1′, then ‘i+1+1′ and so on. To make SET interpret the right side as an arithmetic operation, the option /A is required. Enter SET /? to get a detailed explanation of the SET command’s capabilities.