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...
  1. Private Function output()
  2. MsgBox("Hello")
  3. End Function
which would be called by...
  1. output()
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...
  1. Private Function output(ByVal message As String)
  2. MsgBox(message)
  3. End 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...
  1. output("This is our custom message!")
Finished! Below is the full source to the project. Thanks for reading!
  1. Public Class Form1
  2. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  3. output("This is our custom message!")
  4. End Sub
  6. Private Function output(ByVal message As String)
  7. MsgBox(message)
  8. End Function
  9. End Class

Add new comment