include argument name in function call, eg ?longpathname(strfile:= "c:\file~1.txt") (1 Viewer)

nikalopolis

New member
Local time
Today, 01:23
Joined
Mar 5, 2008
Messages
6
include argument name in function call, eg ?longpathname(strfile:= "c:\file~1.txt")

i am not sure if i am making this up or not, but i thought it was possible to include the arguement name in a function call (to improve the readability of the code).

if a function longpathname takes 1 arguement strfile then i would like to write it as something like

retval = longpathname(strfile:= "c:\file~1.txt")

obviously the function that i am using has many more arguments, hence the need to make it a bit clearer (without having to right-click and Quick Info when i want to see the syntax

I have tried all variants that i can think if - am i tripping?
 

KenHigg

Registered User
Local time
Yesterday, 20:23
Joined
Jun 9, 2004
Messages
13,327
Doesn't intellisense provide help when doing this?
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 17:23
Joined
Jan 31, 2008
Messages
585
haha...Now you have me tripping!

That is exactly what you can do providing of course strfile is indeed declared within the Function:

retval = longpathname(strfile:= "c:\file~1.txt")

is legal code and should work just fine. What error are you getting?

.
 

boblarson

Smeghead
Local time
Yesterday, 17:23
Joined
Jan 12, 2001
Messages
32,059
Just curious but what are you trying to pass to longpathname?

If it is a function that returns the longpath name of the path "c:\file~1.txt" then the call would simply be:

retval = longpathname("c:\file~1.txt")

What does strfile:= have to do with it? I'm not sure what you are trying to accomplish with it. Plus the := is not typical Access VBA. It works for various things within it (for example when using Word or Excel object coding, although it isn't necessary then either), but it is not the norm for Access VBA.
 

nikalopolis

New member
Local time
Today, 01:23
Joined
Mar 5, 2008
Messages
6
i have a routine (sending outlook with loads of arguements, quite a few of which are boolean, so when you try and read the code you just see
sendmessage .......false, true, false, true etc
(I only used the filename example as it was much shorter and less confusing)


CyberLynx, cheers, you gave me enough encouragement to give it another try, and i've got it sorted now, maybe it was late when i was trying this last night!!!Not sure what i was doing wrong but it is working just fine now.

here is what i mean, here is the function definition
Code:
Public Sub SendMessage(strTo As Variant, strSubject As String, strBody As String, bolscreendump As Boolean, bolautosend As Boolean, bolSaveInOutbox As Boolean, Optional strAttachmentPath As String, Optional strCC As String)

i want to be able to call it like this, so that it is much easier to read the options when reviewing the code
Code:
SendMessage "joe@joe.com", "subject", "body text goes here", bolscreendump:=True, bolautosend:=False, bolSaveInOutbox:=False

I reckon i have worked out what the problem was - Once you specify one of the arguemennt names, eg bolscreendump, then you have to specify all the subsequent ones. You can just put the arguement name against one of them. It will not compile


i will put the code upto the repository when it is finished, should be quite useful, deals with signatures, error trapping within outlook and loads of other bits and bobs
 
Last edited:

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 01:23
Joined
Sep 12, 2006
Messages
15,660
i think you can only pass declared arguments in that way, if all the arguments are optional - otherwise you will get expected parameter errors

is that what is causing your problem

----------
eg with openform you get either (as an example - the syntax isnt right)

docmd.openform stdocname,,,,,,,true ----
docmd.openform formname: = stdocname , options:=true
 
Last edited:

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 17:23
Joined
Jan 31, 2008
Messages
585
nikalopolis is right. If you do one ya gotta do em all.

.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 01:23
Joined
Sep 12, 2006
Messages
15,660
this is incorrect

if ALL trhe parameters are optional, you can just pass in selected named parameters which is what nika wanted in the first place.

They do HAVE to ALL be optional though
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 17:23
Joined
Jan 31, 2008
Messages
585
Key words

They do HAVE to ALL be optional though.

.
 

Users who are viewing this thread

Top Bottom