In VBA the Return
statement (which does exist) serves an entirely different purpose; it's used in conjunction with the legacy GoSub
statement, to return from a subprocedure jump:
bar = 42
GoSub Foo
Exit Sub
Foo:
Debug.Print bar
Return
This type of construct is present in the language to support earlier versions/dialects of BASIC, and shouldn't be seen in modern VBA code.
Functions and Property Get
procedures return their return value by assigning to the procedure's identifier:
getServer = "abc"
Note that the procedure's identifier is essentially a local variable, and thus the assignment doesn't return. Use Exit Function
statements to bail out.
Also, {NEWLINE}
is the end-of-instruction marker in VBA, not ;
semicolon ;-)
The semicolon is used in VBA to control the behavior of string-printing, e.g. Debug.Print
and Write#
statements.
Sub test()
Debug.Print 1; 2; 3;
Debug.Print 4; 5; 6; ' prints on the same line as the previous statement
End Sub
Whereas this would output on 2 separate lines:
Sub test()
Debug.Print 1; 2; 3
Debug.Print 4; 5; 6 ' prints on the next line
End Sub