Optional X as Boolean = ??? to detect missing argument?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe HM

    Optional X as Boolean = ??? to detect missing argument?

    Hello -

    I realize that there is no more IsMissing function in VB.NET but how
    can I have a boolean argument that is optional and in the code I need
    to determine whether it was passed it or not?

    I use the Single.NaN to set the default values for some of my optional
    single arguments so that I can determine whether an argument was passed
    it ... but that does not work for booleans.

    Any suggestions?

    Thanks!
    Joe

  • Melissa Nava

    #2
    Re: Optional X as Boolean = ??? to detect missing argument?

    Are you working with checkboxes?

    If you are you can use a threestate property - it would put it to
    checked, unchecked or indeterminate.. .

    Gets or sets a value indicating whether the CheckBox will allow three check states rather than two.


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Optional X as Boolean = ??? to detect missing argument?

      Joe,
      In the case of needing "missing" value types (Single, Integer, Boolean) I
      normally overload the method instead of using optional parameters.

      Public Sub Something()
      ' Boolean parameter not passed
      End Sub

      Public Sub Something(flag As Boolean)
      ' Boolean parameter was passed
      End Sub

      Depending on how the extra parameter is used, I may call the first from the
      second or visa versa.

      I reserve Optional parameter when I have a clear default value.

      Public Sub SetDirty(Option al flag As Boolean = True)
      ' defaults to setting Dirty to true
      End Sub

      SetDirty() ' set the object to dirty

      SetDirty(False) ' the object is now clean...

      --
      Hope this helps
      Jay B. Harlow [MVP - Outlook]
      ..NET Application Architect, Enthusiast, & Evangelist
      T.S. Bradley - http://www.tsbradley.net


      "Joe HM" <unixverse@yaho o.com> wrote in message
      news:1147126201 .046986.137760@ v46g2000cwv.goo glegroups.com.. .
      | Hello -
      |
      | I realize that there is no more IsMissing function in VB.NET but how
      | can I have a boolean argument that is optional and in the code I need
      | to determine whether it was passed it or not?
      |
      | I use the Single.NaN to set the default values for some of my optional
      | single arguments so that I can determine whether an argument was passed
      | it ... but that does not work for booleans.
      |
      | Any suggestions?
      |
      | Thanks!
      | Joe
      |


      Comment

      • Joe HM

        #4
        Re: Optional X as Boolean = ??? to detect missing argument?

        Hello Jay -

        Thanks for the input ... I guess that is probably the best way to go.

        Joe

        Comment

        • Joe HM

          #5
          Re: Optional X as Boolean = ??? to detect missing argument?

          Hello Melissa -

          Thanks for you response. I am not dealing with checkboxes but that is
          something I should look into.

          Thanks!
          Joe

          Comment

          Working...