I like so many others seek out code snippets from time to time to provide some functionality. Most are easy to incorporate. But I have not yet figured out how to use a function, like below. How does one call something like this in another program?

Private Function Search(path As String, Recursive As Boolean) As Boolean


End Function

6 Years
Discussion Span
Last Post by tareywolf

A Sub is a piece of code that takes zero or more parameters and does something. It does not return a value. A Function is the same thing except it returns a value that can be assigned to another variable. For example

Private Function AddTwo(firstNum As Integer, secondNum As Integer) As Integer
    Return firstNum + secondNum
End Function

Anywhere else in your program you can code

myResult = AddTwo(5,3)

Just like a varible, a Function has a type. The type of the function is specified on the same line as the declaration. The type refers to the type of value that is returned. In the above example, the type is specified like "As Integer". Functions can return any type of variable, be it simple (like Integer) or complex (like Dictionary, List or Array).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.