rekam Posted October 24, 2003 Posted October 24, 2003 Hello, there ! I have a sub which have some arguments. One of the is optional. The problem is that this optional argument is a System.Windows.Form.Button... If I declare the sub like this, it doesn't work : private sub createNew(Byval text as string, byval number as integer, optional byval buttonSelected as System.Windows.Form.Button = ??????) ... ... end sub I don't know how to put instead of the ????? Someone has an idea ? Thanks! Quote
*Experts* mutant Posted October 24, 2003 *Experts* Posted October 24, 2003 A better way, and a .NET way would be to make overloads. Here is an example: Private Overloads Sub createNew(ByVal text As String, ByVal number As Integer, ByVal buttonSelected As System.Windows.Form.Button) 'do whatever you need to when the button is instance is passed in End Sub Private Overloads Sub createNew(ByVal text As String, ByVal number As Integer) 'do whatever you need to when a button is not passed in End Sub Quote
rekam Posted October 25, 2003 Author Posted October 25, 2003 Hello mutant, This way is quite interesting, but my sub is very very long. And it's only a very small thing which change if we give button in argument. So I have to write 2 times all the code, and modify it 2 times if I need to (and I surely have to...;) ). But well, since I or someone find the "optional" solution, i'll try with your method, thanks! Quote
Administrators PlausiblyDamp Posted October 27, 2003 Administrators Posted October 27, 2003 Quick re-hash of mutans suggestion follows.... Private Overloads Sub createNew(ByVal text As String, ByVal number As Integer, ByVal buttonSelected As System.Windows.Form.Button) 'do whatever you need to when the button is instance is passed in End Sub Private Overloads Sub createNew(ByVal text As String, ByVal number As Integer) 'Call the full method but provide a default button parameter createNew (text, number, new button) 'Replace the last parameter with whatever the default should be End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.