Multiple value options in a sub routine
Use this board to post your code snippets - tips and tricks
5 posts
Page 1 of 1
This will show you how to let the user select one of a few value sets in a Function routine.
Normally You would have something like this:
Code: Select all
To Have multiple choices of values, you create multiple functions by the same name, but with different values
Function MakeRect(ByVal _Location As Point, ByVal _Size As Size)
Return New Rectangle(_Location, _Size)
End Function
Code: Select all
Feel free to ask for more help!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
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.
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
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
YourSocksRoxx, That is a nice code and to the OP that is a great way of doing it :P
I have to agree, YourSocksRoxx, nice bit of code.
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023