How I did something (useful) in VB in half an hour

It all started when I wanted to calculate some statistical measures like variance/std deviation automatically in Excel. I was planning to use the Analysis Toolpak in Excel. It's available in Tools -> Add-ins -> Select Analysis Toolpak -> Click Ok. Unfortunately, I found that neither was it installed on my system nor was it a free legal download (The addin was a file named proplus.msi). So I thought I might write some custom functions for these myself.
After some Googling, I had some idea to begin with.

To start with, go to Tools -> Macro -> Visual Basic Editor (Shortcut Alt+F11).
In VB editor go to Insert -> New Module (Alt+I+M)
Now I wanted to write a function. More Googling resulted in the basic syntax for writing methods. I wanted one thing in particular, for calculation of variance, a column of data had to be given as the input. What I was looking for was something similar to an ArrayList in java. Some more search and I found that I was supposed to use the data type Variant for this.
One observation was that Variant is somewhat similar to Object in java i.e. anything is passable as a Variant. And another was that, variants can be used directly without casting.

Take a look at the code I came up with:

Function variance(a As Variant) As Double
Dim answer As Double
Dim avg As Double
Dim sum As Double
Dim obj As Variant
Dim count As Integer
count = 0
sum = 0
avg = WorksheetFunction.Average(a)

For Each obj In a
sum = sum + ((obj - avg) ^ 2)
count = count + 1
Next
answer = sum / count
variance = answer
End Function

After saving this, I was able to use the method variance in the workbook as just another function like CONCATENATE or AVERAGE.

More lessons from this exercise are :
1) Standard Excel functions can be accessed using WorksheetFunction.methodName
2) How to traverse a list using for-next loops


The best way is to use functions already available in Excel. I did this because I wanted to learn how to write VB macros/custom functions in Excel and to write a simple VB function without any error.

The art of going slow

Just thought of recording my experiment with slowness. It all started with an email forward which was talking about the slow movement taking on silently in Europe starting with the concept of Slow Food, which you might have guessed as opposed to fast food. Anyway, as the name suggests the movement is all about going slow. That's it. And in every possible task - do it consciously. Sounds wonderful doesn't it - especially for all those lazy readers. Actually it is.

The prime rationale behind this is to go easy on the anxiety and do things better. Of course, we in fact practise this unconsciously- rather forced to practise it. Imagine you are in caught in a traffic at T.Nagar or wherever, possibly sweating in a hot afternoon and thousands of horns honking at you to move forward when you have just enough space to allow a current of air between you and the vehicle ahead. That is one point where your adrenaline rushes and the stress level goes to an all time high isn't it. Well the good news is that you need not feel such sensations anymore. Consciously shift your thinking about our topic - yes slowness. After all you are supposed to be slow. So, the traffic is somehow helping you. Take a deep breath, and share the philosophy with the honker. Sometimes you'll get showered with pleasant acknowledgements especially from auto drivers. Take them as your motivators and strive forward with your goal. You'll receive enlightenment. Or you can choose to retort slowly- " Youuu..areeee...aaaa... reeeeeal.....bosss......stud". The other party will never know you are praising or scolding. It really saves you from getting a bloody nose.

Further in some countries embracing this principle, the per-week work hours are restricted to 28.8. But the productivity level in these places are comparatively high.(It's interesting to compare this with a typical software engineer's work hours. Maybe its more meaningful to compare with 3 or 4 of them taken together.) That basically is because, the slower you are, the more you are able to see and avoid mistakes and hence lesser the defects and higher the productivity. It's easy on the blood pressure too. Further tea is considered as the drink of the slow. But coffee beats tea any day easily.

What happened to my experiment? It was a huge success. I woke up slowly, ate slowly, watched a slow going movie, again ate slowly and crept into the bed slowly. What about work????? It was a Sunday!

You may be interested in visiting the official slow site : http://www.slowdownnow.org/

Rational Software Architect - A mini review

J2EE development is going strong and it will certainly in the future. In most places. So, no wonder products aimed at easing stuff up for developers is destined to thrive. So is RSA - http://www-306.ibm.com/software/awdtools/architect/swarchitect/index.html.On thinking what makes RSA tick(read RSA 6 or 7)..the following points spring up in that order:
1. All under one roof - do every deliverable with RSA.
2. Don't sweat it out - It's fairly simple to learn and get acquainted with.
3. Performance - Will talk about this soon.

Now with RSA, you can do/deliver most of your J2EE artifacts and it provides a very good usable IDE to do so. One of the noteworthy things is UML modelling/design. We all know how important is design in any project and a good design cuts cost/rework and adds to the bottom line and so on. But design seldom is stable and it evolves/changes during development. So syncing up the developed code and design is always a challenge and doing it well is very useful for everyone. RSA accommodates this with alacrity.Now the advantage here is that, you can have the design model and development code in the same workspace and it allows for easy referring to the design during development and vice versa. Forward engineering and reverse engineering have never been so easy. Applying design patterns can also be done but I haven't tried it out myself.

As its built on Eclipse, development ease is also taken care of. Further it supports And to use RSA, the tutorials are fairly good and the time to learn it will be minimal, provided the user knows what he wants.In any system, the wait time experienced promotes a feeling of added complexity. And this factor is less in RSA. Since there is no need of a separate designing software, it will be easy on the system resources as most of good UML design softwares tend to eat up more resources.

Ofcourse, there's a lot more in RSA than what's mentioned here which haven't been discussed like JSF/Junits/Change management linking/Code review tools/Plugins etc. Overall the experience with RSA for J2EE development is good.