473,320 Members | 1,744 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,320 software developers and data experts.

Named vs Un-Named arguments in code

PhilOfWalton
1,430 Expert 1GB
@zmbd

What is there an advantage of using your syntax instead of:-

Expand|Select|Wrap|Line Numbers
  1. DoCmd.CloseObject acForm, Me.Name, acSaveNo
Phil
Aug 11 '18 #1
3 1441
zmbd
5,501 Expert Mod 4TB
named arguments vs un-named arguments
- Mainly a personal preference and for simple commands perhaps a bit redundant; however, for me I find that:
1) The order doesn't matter doesn't matter
+ DoCmd.Close ObjectName:=Me.Name, ObjectType:=acForm, Save:=acSaveNo
+ DoCmd.Close Save:=acSaveNo, ObjectType:=acForm,ObjectName:=Me.Name
+ DoCmd.Close ObjectType:=acForm,ObjectName:=Me.Name Save:=acSaveNo

Can't count the number of times when I've been in a hurry that I've started with the Title for a msgbox because that was what I was thinking about at that moment in time.
As of late I've been using the err.Raise method in my code so that my error-handler will take care of messages and drop to the clean-up if certain conditions are not handled so I have a Select-Case in these types of error traps with things like:
Expand|Select|Wrap|Line Numbers
  1. zStrMsg = Err.Number & vbcrlf & Err.Source & vbcrlf & Err.Description
  2. '(...)
  3. zStrMsg = zStrMsg & vbcrlf & "Do you want to override and commit action? (default [No])"
  4. '
  5. MsgBox Title:="Oh No Action is Prohibited!", Prompt:= zStrMsg, Buttons:= vbCritical+vbYesNo+vbDefaultButton2
I like to start with the title as it's an abstract of what the MsgBox is for in that context without having to dig back through my code for "(vbObjectError + 1)".

2) It makes it clear what your intent is/was (i.e: Err.Raise/MsgBox) for anyone following you for code maintenance without having to find the syntax reference for more complex code (I work with a lot of individuals that do not know nor care to learn any programing language - I'm a chemist by trade/training with a bit of math, (chem/civil)engineering, and compsci tossed in for spice)

3) You can do this:
DoCmd.OpenForm FormName:="SomeFrmName",OpenArgs:="StringHere"

Instead of
DoCmd.OpenForm "SomeFrmName",,,,,,"StringHere"
is The String a WhereCondition or a Open arguments
For example
DoCmd.OpenForm "SomeFrmName",,,,,,"Monkey=Chimp"
vs
DoCmd.OpenForm "SomeFrmName",WhereCondition:="Monkey='Chimp'"
While in one you could be troubleshooting for a "Month" if you thought you were passing a WhereCondtion clause in the second the intent is clear AND you know you need that extra set of quotes (yes, I've seen this done - extra/missing comma makes a difference - have you accidently deleted a comma and the code that was working stopped - ARRRGH)! Also, IMVHO, it makes the code cleaner by removing all of those placeholders.

4)When explaining syntax to a inexperience user without the benefit of face-to-face it prevents any ambiguity in the explanation.
Aug 11 '18 #2
PhilOfWalton
1,430 Expert 1GB
Yes, that makes a lot of sense, especially the OpenForm and equally when passing optional arguments to functions.

Never too old to learn?????

Thanks for that,

Phil
Aug 11 '18 #3
NeoPa
32,556 Expert Mod 16PB
Very big fan of using named arguments in my code. There are some exceptions - principally when the variables used in the calling code already match those in the called procedure definition, but also extremely common procedures with only one, or maybe two at most, parameters.

It's particularly helpful when working on here as it's explicit. Most of those who are still learning need explicit. They don't need to fall over those missing or extra commas (,) so prevalent in positional parameter code.
Aug 11 '18 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sheila King | last post by:
Here is something that surprised me tonight: >>> def myfunc(x, y, a='A', *mylist): print x print y print a for item in mylist: print item
1
by: Fuzzyman | last post by:
A colleague and I have built a Validator object for use with ConfigObj and other general schema situations. A config file is used to store a schema that specifies how to test a value that it is...
2
by: Fuzzyman | last post by:
Sorry if this is a duplicate - I use the google interface and sometiems it screws up (not showing stuff you've posted *or* not posting it). Before you ask it's because at work I have no NNTP and...
10
by: Agent Mulder | last post by:
Hi group, Almost 3 weeks ago I posted a short question here and in comp.std.c++ and I got exactly 1 respons, from Kevin Goodsell. He said he didn't want it. I post it here again, this time in a...
1
by: python101 | last post by:
class double: def __ini__(self,x1,y2): self._x=x1 self._y=y2 def result(self): return (self._x)*(self._y) def...
1
by: jmvidalvia | last post by:
Hi everybody! My first post here...hope to learn quickly. I just mounted a debian server and start to run some few scripts. They "seem" to run, but sometimes (5% of times) I am getting this error...
2
ADezii
by: ADezii | last post by:
When a call is made to a Sub or Function Procedure, you can supply Arguments in the exact order they appear in the Procedure's definition, or you can supply them in any position by name. To...
0
by: Netwatcher | last post by:
Hi guys, i have recently managed to crash my computer *cheers* so... i have encountered a little problem while trying to run py2exe, every time i run it it gives the following error:(notice the...
2
by: Dave Smith | last post by:
Hi everyone again. I’m working on making my database roll with each month that changes. Below is what I have so far, and was hoping someone could help me with the rest. The error message I’m...
0
by: allynm | last post by:
Hello everyone, I am trying to network over a small wireless LAN a Windows 7 box and a Windows XP (SP3) box. I have written an application that uses Windows named pipes. The code appears to be...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.