Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is with Else : Syntax ?? 1

Status
Not open for further replies.

steve728

Programmer
Mar 16, 2003
536
US
In my current employer's VB.NET coding I frequently see the following conditional coding:

If memvar = True Then
Do something...
Else : Me.TxtBox.Text = "DuDah"

Is there any reason, advantage to using the above versus the traditional syntax of:

If memvar = True Then
Do something...
Else
Me.TxtBox.Text = "DuDah"
End If

Thanks in advance,

Steve


 
To my knowledge...there is no benefit to using the colon :)) in your line statements. The colon can be used if the code to run based on the condition is one line long. I don't think it will allow you to have more than one line and I think that is why it is there in the first place......

But on the contrary, I find myself not using them at all. They tend to deter from the visual look of the code for flow control. I have always been told that each portion of a conditional statement should not use the colon :)) for uniformities sake. At the very least you should not mix the two formats.

In other words, this:

Code:
Select Case someNumber
    Case 1 : 'Do Something
    Case 2 : 'Do Something Else
    Case Else : 'End something to do
End Select

Is the same, is basically just as acceptable as,and should perfrom just the same as:

Code:
Select Case someNumber
    Case 1
        'Do Something
    Case 2
        'Do Something Else
    Case Else
        'End something to do
End Select

But you will find the second example used so much more than the first....and you really should use the second.

No matter what, you should not mix like this:

Code:
Select Case someNumber
    Case 1 : 'Do Something
    Case 2
        'Do Something Else
    Case Else : 'End something to do
End Select

That just poor form. My couple of cents....

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
VB/Access Programmer
 
chrissie1 said:
shorter, saves on returns.

[lol]

You have less returns, but you also have more colons. The return key is physically larger on the keyboard, so I prefer that instead. It provides a bigger target for my fat fingers.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
You actually have one colon instead of two returns and you loose the end if. So in the end that could save you millions of keystrokes.... a day.

Of course it doesn't increase readability.

Christiaan Baes
Belgium

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top