-4

i have a Function with1 Parameter and 10 optional Parameters. The optional Parameters are all nothing. Now i want to check if a optional Parameter had changed his Value or the Function was started with an optional Parameter. Think of it that the Parameters can have the Value Nothing then the Function returns too. ty for your help. :D

JJonBacon
  • 3
  • 1
  • 2
    I'm not following your question. Why don't you actually look at providing sample code. Also consider using [Overloads](https://msdn.microsoft.com/en-us/library/ms973896.aspx) instead of optional parameters. – Bugs Feb 01 '17 at 14:53

3 Answers3

2

10 parameters.. that's a bit excessive... and hard to manage. You would be better passing a class or structure.

Checking the optional parameter is the default value is the usual method for this for determining if it is pre-set or not as in the previous answer.

You would need to pass an object by reference if you need to test if it changed while the routine was running, but if it was originally passed as "Nothing" that will not work.

Without more information on what your usage intent is, it is a little hard to answer this conclusively.

Trevor_G
  • 1,331
  • 1
  • 8
  • 17
0
If Parameter1 Is Nothing then
  'Parameter1 changed
EndIf
dmitry
  • 468
  • 1
  • 4
  • 18
0

If your other optional parameters is nothing I trust that their reference type is a string.

The following from MSDN to check if an optional argument is present -

A procedure cannot detect at run time whether a given argument has been omitted or the calling code has explicitly supplied the default value. If you need to make this distinction, you can set an unlikely value as the default. The following procedure defines the optional parameter office, and tests for its default value, QJZ, to see if it has been omitted in the call:

Sub notify(ByVal company As String, Optional ByVal office As String = "QJZ")
  If office = "QJZ" Then
      Debug.WriteLine("office not supplied -- using Headquarters")
      office = "Headquarters"
  End If
  ' Insert code to notify headquarters or specified office.

End Sub

Link can be found HERE

AlwaysConfused
  • 450
  • 4
  • 13