Page 1 of 1

## Named Parameters. How they make you code more Readable. Rate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=92202&amp;s=aca19323df1791aae73ad4bfa91b0a95&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

• MrCupOfT

Reputation: 2298
• Posts: 9,535
• Joined: 29-May 08

Posted 11 March 2009 - 07:08 PM

I been wondering for a quite a while what VariableName:= was used for when you entering the values of parameter of a subroutine, function or method.
Today I realized what they are used for. So I wrote this tutorial so you can understand them too.

Named Parameters

To explain them, imagine that in your code you have the following routine. (Without using Named Parameters)
I know it's a bit simple but the principles that count in this tutorial
Private Function Divide(Byval Divider as Double, ByVal Divisor As Double) As Double
' Work out the quotient
Return Divider / Divisor
End Function

And you use it like.
Dim A As Double =10
Dim B As Double =2
Dim C As Double = Divide(A,B)

Without using Intellisense what A & B are being using for by the Divide Function is a bit hard.
In this example you could probably guess but what if the function was called xyz it is a lot harder.

But by using named parameters it's a lot easier.
Dim A As Double =10
Dim B As Double =2
Dim C As Double = Divide(Divider:=A,Divisor:=B)

Which is saying;-
The Divide function's Divider parameter is the contents of variable A
The Divide function's Divisor parameter is the contents of variable B

Another Example

Private Sub PrintHello(ByVal DoYouWantTheHello As Boolean)
If DoYouWantTheHello =True Then
Console.WriteLine("Hello World")
Else
Console.WriteLine("World")
End If
End Sub

PrintHello(DoYouWantTheHello:=True)

Using this alongside with using good variable names makes, in my opinion, the code a lot easier to understand by looking at it.

Is This A Good Question/Topic? 1

## Replies To: Named Parameters.

### #2 LemonMan

Reputation: 15
• Posts: 170
• Joined: 22-August 05

Posted 20 March 2009 - 04:11 PM

Wow, that could really help me. Thanks!

### #3 Lumenii

Reputation: 10
• Posts: 92
• Joined: 04-January 07

Posted 22 March 2009 - 10:33 PM

Good to know. I'll definitely be using this. I teach (informally) some VB.NET/ASP.NET, and this would make things clearer for some.

### #4 Steven.James

Reputation: 1
• Posts: 1
• Joined: 24-May 09

Posted 24 May 2009 - 01:14 AM