Function without an 'AS' clause

bcm

Well-known member
Joined
Aug 13, 2007
Messages
56
Programming Experience
Beginner
I am writing a project VB.NET2005 where I declared a Function Capture_error() but it show following error:

"Function without an 'AS' clause;return type of object assumed"

What can I do for it
:(
 
You can add an 'As' clause. Everything that has a tpye should be declared 'As' that type. Functions have a type because they return a value. Just as you declare an Integer variable like this:
VB.NET:
Private myVariable [B]As[/B] Integer
so you declare a function that returns an Integer like this:
VB.NET:
Private Function myFunction() [B]As[/B] Integer
If you don't declare a type then it will assume type Object, as the warning states. This makes your code less efficient, harder to maintain and more error-prone.

The fact that you got that warning indicates that you have Option Strict turned Off, which is unfortunately the default. I strenuously recommend that you turn it On. In that case that code would refuse to compile, thus preventing you from releasing a product that is less efficient, harder to maintain and more error-prone.
 
Last edited:
I am writing a project VB.NET2005 where I declared a Function Capture_error() but it show following error:

"Function without an 'AS' clause;return type of object assumed"

What can I do for it
:(

Make it a Sub if it has no return value!
 
Back
Top