Monday, September 29, 2008

Single Line If ... Then Using Colon For Multiple Statements

This might be a very simple one...
Many of you might know this before...
But, i just learnt it as part of my VB 2008 reading...

Its the If ... Then statement.

WHAT WE ALL KNOW IS

If intNetSalary = 10 Then
intGrossSalary = intNetSalary + intTax
End If


It can also be written as in one line:

If intNetSalary = 10 Then intGrossSalary = intNetSalary + intTax

But, in case of multiple statements within a If conditions...

If intNetSalary = 10 Then
intSubTotalSalary = intNetSalary + intMedicalDeduction
intGrossSalary = intSubTotalSalary + intTax
End If


THE NEW THING I LEARNT IS...IT CAN BE WRITTEN IN ONE LINE... HOW?

If intNetSalary = 10 Then intSubTotalSalary = intNetSalary + intMedicalDeduction : intGrossSalary = intSubTotalSalary + intTax

Isn't that great? I just learnt it...may be most of us don't know about it :)

~ Ram ~

No comments: