Define a function procedure.
Syntax [Public [Default] | Private ] Function name([arg_List]) [statements] [name=expression] Exit Function [statements] [name=expression] End Function Key Public Extend the scope of this function to all procedures in the project. Public Default Define a method as the default member of a class (Only for public functions defined within a class.) Private Restrict the scope of this function to procedures within the same module. name The name of the function. arg_List Argument variabless passed to the function, comma separated. By default, each local variable=argument (ByRef) To have each local variable=value of the argument prefix the argument with 'ByValue'. statements Program code expression The value to return.
Function AddQuotes(str) ' Return the original string "surrounded with double quotes"
AddQuotes = Chr(34) & str & Chr(34)
End Function Function DemoFunc(Arg1, ByRef Arg2) ' Return the two arguments in a single string DemoFunc = "First: " & Arg1 & " second: " & Arg2 End Function
“The most important thing in an argument, next to being right, is to leave an escape hatch for your opponent, so that he can gracefully swing over to your side without too much apparent loss of face” ~ Sydney J. Harris
Sub - Start a subprocedure
IsMember.vbs - Function to determine group membership
Equivalent Powershell command: Functions