
Problem: Subs Vs. Functions
As you will see, VB under the .NET platform is very different from VB6. To set the stage, the next several pages of
this chapter will overview some of the ‘clean up’ which has occurred. Even if you do not have exposure to VB 6.0, this
information will still be quite useful, as you will be exposed to a handful of new VB programming constructs.
In VB 6.0, the correct syntax for passing parameters differs between subroutines and functions. A function call must
enclose parameters in parenthesis. A subroutine call must NOT enclose parameters in parenthesis, unless the Call
keyword is used. Why this inconsistency? No good reason, so VB removes it.
'VB 6.0 Code
iResult = SomeFunction(arg1, arg2)
SomeSub arg1, arg2
Call SomeSub(arg1, arg2)
VB forces procedure parameters to always be enclosed by parenthesis. As a convenience however, if you are calling a
constructor (defined in just a bit) that does not take any parameters, you can omit the empty parentheses. Also, if you
are calling a subroutine or function that take no parameters, the empty parentheses can be omitted.
'VB code
result = SomeFunction(arg1, arg2)
'Note: params required!
SomeSub(arg1, arg2)
'Either of these calls are OK, if the Car class has a no-arg constructor.
Dim myCar As New Car
Dim myOtherCar As New Car()
'Either of these calls are OK, if the MySub method takes zero arguments.
MySub()
MySub
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an
online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
Subs vs. Functions
Table of Contents
Courseware
Training Resources
Tutorials
Services