Verified Jobs Live
Visual Basic Easy Level ~3 min read

In VB.NET, how do Sub and Function differ?

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

A Sub performs an operation without returning a value through its declaration, while a Function returns a value of a declared or inferred return type. Both can accept parameters and can have observable effects. Choose a Function when the caller needs a result, such as a calculated total, and keep the type explicit in public APIs. A Sub can still modify shared state or an argument through ByRef, so returning nothing does not mean doing nothing. These questions use VB.NET rather than legacy VB6 unless stated otherwise.

Advertisement