Custom Functions
Submitted by Yorkiebar on Saturday, October 19, 2013 - 04:33.
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;
As an example;
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;
Finished!
- {Privacy} Function {Function Name}({Parameters, if any})
- End Function
- Private Function test(ByVal s As String)
- End Function
- test("Hello")
Add new comment
- 132 views