473,703 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Use of "Optional" parameters in a Sub/Function?

I've dabbled in "Optional" over the last few days and think I'm coming down
against using it.

Seems to me like it makes the code harder to read and more complicated.

Instead of using Optional, I'm making the parm a Variant and passing Null when
it's not used.... then checking for "If Len(theParmValu e & "") > 0... to see if
it is present.

That way I can eliminate checks for IsMissing(thePa rmValue)...
Anybody else have thoughts on this?
--
PeteCresswell
Nov 13 '05 #1
5 9501
Sorry, but I fail to see how If Len(theParmValu e & "") > 0 is any easier to
read than If IsMissing(thePa rmValue).

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"(Pete Cresswell)" <x@y.z> wrote in message
news:td******** *************** *********@4ax.c om...
I've dabbled in "Optional" over the last few days and think I'm coming down against using it.

Seems to me like it makes the code harder to read and more complicated.

Instead of using Optional, I'm making the parm a Variant and passing Null when it's not used.... then checking for "If Len(theParmValu e & "") > 0... to see if it is present.

That way I can eliminate checks for IsMissing(thePa rmValue)...
Anybody else have thoughts on this?
--
PeteCresswell

Nov 13 '05 #2
Chuck Grimsby <c.*******@worl dnet.att.net.in valid> wrote in
news:t7******** *************** *********@4ax.c om:
Use the Optional keyword with a = "setting" if there isn't a
input. For example:

Public Function GetASetting( _
SettingToGet As String, _
Optional TableName As String = "USYS_tblSettin gs", _
Optional whatDB As DAO.Database = Nothing) _
As Variant

If whatever calls this function doesn't supply a TableName,
"USYS_tblSettin gs" is used by default.

Saves all that nasty checking for IsMissing... You do still have
to check for invalid stuff passed to your function or sub however!


I've often added optional arguments to version 2 of a commonly-used
function/sub. In that case, it's pretty important to use it, as
otherwise, existing code will break.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #3

"(Pete Cresswell)" <x@y.z> wrote in message
news:td******** *************** *********@4ax.c om...
I've dabbled in "Optional" over the last few days and think I'm coming
down
against using it.

Seems to me like it makes the code harder to read and more complicated.

Instead of using Optional, I'm making the parm a Variant and passing Null
when
it's not used.... then checking for "If Len(theParmValu e & "") > 0... to
see if
it is present.

That way I can eliminate checks for IsMissing(thePa rmValue)...
Anybody else have thoughts on this?
--
PeteCresswell

If there were no such thing as optional parameters, think how different your
coding would look. Some of the things you could no longer write would
include:
DoCmd.Close (You now write DoCmd.Close Null, Null, Null)
DoCmd.OpenForm "frmWhateve r" (You now write DoCmd.OpenForm "frmWhateve r",
Null, Null, Null, Null, Null, Null)
OK, these are methods of built-in objects, not your custom functions, but
doesn't the same principal apply? I don't see how forcing users of your
functions (yourself?) to always provide every parameter would increase
readability or fail to irritate. Perhaps, though, you are thinking of a
specific function and whether parameters should be optional in that
particular case.
Nov 13 '05 #4
The "Optional Parameter" is a hang-over from the way a couple
of dudes implemented their macro-assembler on a PDP mini-computer
decades ago. It is indeed a nifty feature, even if it did
fall out of a historical accident, but it is incompatible with
most current ideas about computer language design (Pearl excepted:
the designer of Perl is strongly supportive of irregular forms
for common verbs like DoCmd.OpenForm) .

Ironic isn't it, that VB got optional parameters by aping C,
but C++ and OLE don't really have optional parameters any more?

In Access, optional parameters should default to Null, not
Missing (think about it!), but the fact is that Null is not
and cannot be a defined concept: we often wish Null to map
to 0 and "" and Empty and Error and Missing, and we often
wish Null to /NOT/ map to 0 or "" or Empty or Error or Missing:

there is no universal answer to some questions.

(david)
"(Pete Cresswell)" <x@y.z> wrote in message
news:td******** *************** *********@4ax.c om...
I've dabbled in "Optional" over the last few days and think I'm coming down against using it.

Seems to me like it makes the code harder to read and more complicated.

Instead of using Optional, I'm making the parm a Variant and passing Null when it's not used.... then checking for "If Len(theParmValu e & "") > 0... to see if it is present.

That way I can eliminate checks for IsMissing(thePa rmValue)...
Anybody else have thoughts on this?
--
PeteCresswell

Nov 13 '05 #5
(Pete Cresswell) wrote:
I've dabbled in "Optional" over the last few days and think I'm coming down
against using it.

Seems to me like it makes the code harder to read and more complicated.

Instead of using Optional, I'm making the parm a Variant and passing Null when
it's not used.... then checking for "If Len(theParmValu e & "") > 0... to see if
it is present.

That way I can eliminate checks for IsMissing(thePa rmValue)...
Anybody else have thoughts on this?


I think it's (optional) useful and allows a default value to be passed
in rather than the usual nulls, zeros, zero length strings, etc.

--
This sig left intentionally blank
Nov 13 '05 #6

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

Similar topics

3
1583
by: Paramesh | last post by:
Hello friends, My friend asked me this question: This question regards proprietary software (of which I am one of the developers), so I cannot post actual code for this question. I will try to use illustrative examples. I have two libraries for distribution; one is an essential library and the other is an add-on (providing specialized extensions and
18
2247
by: Clark Nu | last post by:
It seems that when I define a fuction,I can set a default value to some of the peremeters.When I call the fuction without some of them,the fuction will use the default value automaticlly then continue to work.But I'v fogot how to use,even I'v fogot whether I can use it in C# or not. Help me.
2
11936
by: Oenone | last post by:
In our applications, we use the special value of DateTime.MinValue to represent "null dates" throughout all our code. We recently ran into an issue where we wanted an optional date parameter for a procedure. We weren't able to declare it with DateTime.MinValue as its default value, as MinValue is a read-only property rather than a constant. To work around, we had to use a "magic date" that we checked for later on. I was never very happy...
2
2016
by: Steve | last post by:
Kind of a strange question... I have a VB.NET 2.0 solution containing a main project (my EXE) and a number of other projects (class DLLs) that are "plug-ins" to the main app. These plugins get installed depending on each user's requirements. I'd like to implement a function in one plugin that only executes if another plugin is present. Typically, for one plugin to access a second plugin, I need to set a reference at design-time to the...
1
3014
by: Sinex | last post by:
Hi, I have a webmethod. It takes an int parameter. I want this to get serialized as an XMLAttribute...so I used the XMLAttributeAttribute decoration and it works fine. Now, I want to specify that this attribute is optional (in the schema it should show up as Use = "Optional"). How do I do this. And how will my method function if the client doesnt pass the parameter?
6
5821
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, how?: Sub ResolveArrays(ByVal array1() As String, ByVal valueX As String, _ Optional ByVal array2() As String = {""}, Optional ByVal retry As Boolean = False) ' Code to take array1 and compare each value to valueX, ' if no value is...
3
3186
by: Rincevent | last post by:
Hi, I'm trying to process a large number of files, each with a very small size (about 500 chars maximum). I need to retrieve multiple information from each file, and some of these are optional. So to "simplify" the process, I undefed $/ (variable contains the full file). The current regular expression that I know works (with all mandatory matches) is the following: /\{2:+(\d{6})\d{4}.\}.*^:25:(.+?$).*^:13D:(\d{6})/sm as can be seen,...
0
1121
by: shai.halevi | last post by:
I'm looking for a simple template with the following property: I want to have in the resulting page something like this (say): <div> This is some text that never changes: ]] This is some more text that never changes </div> The crux is that if the calling code never initializes the variable,
6
2401
by: .rhavin grobert | last post by:
hello;-) i frequently need the following construction: ReturnParam § Function() § { /...do something.../ someType var § = something; /...do something.../ return something;
0
8667
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9249
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7860
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6585
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4428
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2445
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2063
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.