Multiple value options in a sub routine

Use this board to post your code snippets - tips and tricks
5 posts Page 1 of 1
Contributors
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

This will show you how to let the user select one of a few value sets in a Function routine.
Untitled.png
Normally You would have something like this:
Code: Select all
Function MakeRect(ByVal _Location As Point, ByVal _Size As Size)
    Return New Rectangle(_Location, _Size)
End Function
To Have multiple choices of values, you create multiple functions by the same name, but with different values
Code: Select all
Function MakeRect(ByVal _Location As Point, ByVal _Size As Size)
    Return New Rectangle(_Location, _Size)
End Function

Function MakeRect(ByVal _X As Integer, ByVal _Y As Integer, ByVal _Size As Size)
    Return New Rectangle(New Point(_X, _Y), _Size)
End Function

Function MakeRect(ByVal _Location As Point, ByVal _Width As Integer, ByVal _Height As Integer)
    Return New Rectangle(_Location, New Size(_Width, _Height))
End Function

Function MakeRect(ByVal _X As Integer, ByVal _Y As Integer, ByVal _Width As Integer, ByVal _Height As Integer)
    Return New Rectangle(New Point(_X, _Y), New Size(_Width, _Height))
End Function
Feel free to ask for more help!
You do not have the required permissions to view the files attached to this post.
Last edited by Cheatmasterbw on Sun Dec 12, 2010 9:55 pm, edited 1 time in total.
http://www.megaapps.tk/
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

you can also add optional values


Function MakeRect(ByVal _Location As Point, ByVal _Width As Integer,optional ByVal _Height As Integer = 20)
Return New Rectangle(_Location, New Size(_Width, _Height))
End Function

so you can make
Makerect(2451,5428 , 30)
or
Makerect(2451, 5428)
if you fill in nothing it will return 'optional ByVal _Height As Integer = 20'

add this to your snip :P
http://vagex.com/?ref=25000
Lewis
Coding God
Coding God
Posts: 1564
Joined: Sun Dec 20, 2009 2:12 pm

YourSocksRoxx, That is a nice code and to the OP that is a great way of doing it :P
Image
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Nice addition!
http://www.megaapps.tk/
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

I have to agree, YourSocksRoxx, nice bit of code.
Image
5 posts Page 1 of 1
Return to “Quick Snips”