views:

156

answers:

4

Hi All,

I would like to know the pros and cons of calling procedures with Call Keyword and without Call in VB.NET?

Private Sub ProOne()
     // Code Are Here
End Sub

Private Sub Calling()
   ProOne()           // I would like to know pros and cons of this
   Call ProOne()      // And I would like to know pros and cons of this
End Sub

Thanks in advance all.

+5  A: 

There are no pros, and there are no cons.

The Call keyword is a legacy keyword from older VB dialects.

In VB.net it has no meaning, and is syntatic sugar.

Binary Worrier
+5  A: 

From here:

"You normally use the Call statement to call a procedure that does not return a value. If the procedure returns a value, the Call statement discards it.

You are not required to use the Call statement when calling a procedure. However, it improves the readability of your code."

So, in essence, ProOne() and Call ProOne() are semantically equivalent.

Michael Todd
+2  A: 

From documentation

Transfers control to a Function, Sub, or dynamic-link library (DLL) procedure. [ Call ] procedureName [ (argumentList) ]

so,

You normally use the Call statement to call a procedure that does not return a value. If the procedure returns a value, the Call statement discards it.

You are not required to use the Call statement when calling a procedure. However, it improves the readability of your code.

astander
"However, it improves the readability of your code". Depends on personal taste, I can't abide it myself and never use it :)
Binary Worrier
+1  A: 

Although they are technically equivalent, I would argue against using "Call". When moving from VB6 to VB.Net, it's important to realizae that they are completely different languages that have to be written for in completely different ways. Unfortunately, Microsoft wanted to provide support for VB6 developers, and they provided this by adding functionality that mimics the VB6 functionality, but is siginificantly inferior to the .Net equivalent.

Cutting all ties with any of the VB6 holdovers will make developers stop using these bits as quickly as possible, and lead to better code output.

Chris