Parameters/Arguments
Submitted by Yorkiebar on Saturday, October 19, 2013 - 04:33.
What are 'Arguments'?
In programming, arguments are pieces of data which are sent to a function upon calling that function. Arguments can be any standard variable type, this includes types such as 'String', 'Integer' and 'Boolean'.
What are 'Parameters'?
Parameters (Params) are the pieces of data which are request or required once a function has been called. Parameters are filled with the given argument which is sent from the calling of the function.
Example:
As an example, if we had a simple function named 'a' which created a messagebox to say "Hello", we could change this to accept a customized String variable type and output that instead...
First we have our standard function which has no parameters...
which would be called by...
Now, we want can make it take a String to output through the message. To do this we first decide on a type of variable we want to request, ours will be String for our Messagebox. Next we give it a variable name, ours will be called 'message'. Then we add it to the brackets of our function...
The keyword 'ByVal' just means it is an argument which we are creating. Also, we change the String "Hello" to our variable name so it referencing to our argument which will be output in the message box. We don't surround it with quotes (") because the variable is already a string, if we did surround it with quotes (") it would just output our variable name as a string.
Now that we are taking one parameter we are receiving an error when we call the function, the error says:
"Argument not specified for argument 'message'." So lets specify it...
Finished!
Below is the full source to the project. Thanks for reading!
- Private Function output()
- MsgBox("Hello")
- End Function
- output()
- Private Function output(ByVal message As String)
- MsgBox(message)
- End Function
- output("This is our custom message!")
- Public Class Form1
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- output("This is our custom message!")
- End Sub
- Private Function output(ByVal message As String)
- MsgBox(message)
- End Function
- End Class
Add new comment
- 92 views