473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

May 8 '06 #1
4 5907
Are you working with checkboxes?

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

http://msdn2.microsoft.com/en-US/lib...hreestate.aspx

May 8 '06 #2
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(Optional 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" <un*******@yahoo.com> wrote in message
news:11**********************@v46g2000cwv.googlegr oups.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
|
May 8 '06 #3
Hello Jay -

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

Joe

May 10 '06 #4
Hello Melissa -

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

Thanks!
Joe

May 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: spammy | last post by:
Hi all, Im attempting to use a COM class in C# via .NET interop. The class has two modes - synhrounous and asynchronous. The mode is determined by the use (or not) of an optional out parameter:...
4
by: Gerry Abbott | last post by:
Hi All, Im trying to use thie combination but have not had success. Below is the function It tried the following myriskLevel(2,2) myrisklevel(0,0,2) and the ismissing(Three) alwasy...
4
by: MLH | last post by:
The following function declaration confuses me... Public Function IsEMailAddress(ByVal sEmail As String, Optional ByRef sReason As String) As Boolean I tried pasting it and its code into an...
13
by: William Ryan | last post by:
I just picked up a copy of John Robbins' debugging book and started to look at disassembled code. Anyway, I hate optional Parameters in VB, but I was checking them out to see what IL is created. ...
4
by: Yong Jiang | last post by:
I am trying to convert some vb code calling COM oboject methods to C#. Example shown as follows Dim Stream As New ADODB.Stream Call Stream.Open() Stream.Open has three optional parameters. ...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
10
by: deko | last post by:
In VB, I could do this: MyFuncrion(this As String, that As Integer, Optional otherThing As Boolean) do stuff here End Function In C#, I can use "out" to return multiple values from a method,...
6
by: Queez | last post by:
I've had a good look around and no-one seems to have mentioned this, which leads me to believe that I may be missing something simple. Basically, is there a way I can do the following, and if so,...
7
by: jamesclose | last post by:
My problem is this (apologies if this is a little long ... hang in there): I can define a function in VB.NET with optional parameters that wraps a SQL procedure: Sub Test(Optional ByVal Arg1...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.