VBScript: “functionName = value” vs. “return value”

In VB.NET, it’s quite common to see people returning value for a function by assigning value to the function name:

Function GetNumber as Integer
  GetNumber = 15
End Function

This is equivalent to:

Function GetNumber as Integer
  return 15
End Function

The difference between this 2 methods is that if you assign a value to the function name, the function does not exit until it hits the end of the function or hits the Exit Function statement, where if you return the value, the function exits at that point.

Assigning value to function name is a legacy of the VB world and using the return statement is more conventional.

Check out more details here:  http://msdn.microsoft.com/en-us/library/x7hbf8fa(VS.85).aspx


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s