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

'Whatever

End Function

Recommended Answers

All 2 Replies

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).

Thank you for your explanation...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.