Custom Functions

What are custom functions? Custom functions are functions which you have made yourself. They can be Private (only the class in which it is created can use it) or Public (any class may use it). They are able to take parameters/arguments, can return data and can be ran on separate threads. When should you use custom functions? Whenever you have a script which needs to be ran over and over again at different positions within your source code you should create one function to contain the script. This way, you can call the function every-time the script needs to be ran, this saves time and space. How to create a custom function: To create a custom function, you simply follow these steps; - Decide whether it needs to be public, if not, choose private. - Choose an appropriate name for the function to be named. Make it something related to the prupose it servers, this way you will not be confused with larger scripts. - Decide which (if any) parameters it will need to take. Once you have decided on the features the function needs to have, you can now create the function. Click inside your class but outside of any other subs or functions and type;
  1. {Privacy} Function {Function Name}({Parameters, if any})
  3. End Function
As an example;
  1. Private Function test(ByVal s As String)
  2. End Function
Then to call the function you simply type the name of the function followed by two brackets. If any parameters/arguments are required you put them inside the brackets. Example;
  1. test("Hello")

Add new comment