Is it possible to create an optional parameter for a procedure in LotusScript like you can do in Visual Basic. There doesn’t seem to be an “Optional” keyword.
MJ
Is it possible to create an optional parameter for a procedure in LotusScript like you can do in Visual Basic. There doesn’t seem to be an “Optional” keyword.
MJ
Subject: Opional Parameters
Not available in LotusScript. Short of writing an LSX (DLL which extends LotusScript), you can’t do variable parameters).
Subject: RE: Opional Parameters
Ben,
Not being a VB person, I am not sure what he was getting at?
If he means having a subroutine with set parameters that may or may not be passed, I usually accomodate that by passing in an empty value of some sort…
Subject: Talking about NotesUIWorkspace.DialogBox for example…
the only required parameter is the form$. eg:flag = NotesUIWorkspace.DialogBox(“YourForm”)
is valid, so is:
flag = workspace.DialogBox(“YourForm”,True,True,False,False,False,False,“Title”,doc)
That is what they meant by Optional Parameters.
Subject: RE: Talking about NotesUIWorkspace.DialogBox for example…
That is what I thought. So there are many ways to have similar functionality in script, just with a different syntax.
For example, this VB Procedure:
Sub OptionalArgs(strState As String, strRegion As String,strCountry As string)
If strRegion=“” And strCountry=“” Then
Debug.Print strState
ElseIf strCountry=“” Then
Debug.Print strState, strRegion
ElseIf strRegion=“” Then
Debug.Print strState, strCountry
Else
Debug.Print strState, strRegion, strCountry
End If
End Sub
is simply rewritten as
Sub OptionalArgs(strState As String, strRegion As String,strCountry As string)
If strRegion=“” And strCountry=“” Then
Print strState
ElseIf strCountry=“” Then
Print strState + "," + strRegion
ElseIf strRegion=“” Then
Print strState+","+ strCountry
Else
Print strState+","+ strRegion+","+
strCountry
End If
End Sub
and called as
Call OptionalArgs (“”,“”,“”)
Call OptionalArgs (“VA”,“”,“USA”)
etc etc and accomplish the same type funcytionality, no?
Subject: Sure you can, it just seems much cleaner to…
Call optionalArgs(“Parm1”)than
Call optionalArgs(“Parm1”,“”,“”,“”,“”,“”,“”)
for example. You can also use w/ that syntax:
Call optionalArgs(“Parm1”,“Parm7”)
Subject: Can’t pass Nothing for a NotesDocument parameter
I realize this is 4 years later, but this was the only post I could find that was relevant. I have a sub with a string and a NotesDocument as parameters. Sometimes I don’t want to pass a doc, so I send Nothing. If doc is Nothing, I want the sub to create one. The first thing I tried was “If doc Is Nothing then [create a doc],” but it always acted like that was False and would go on to the next line. The next thing I tried was an error routine with [create a doc], but nothing happens. In debug, it looks like it executes it, but the doc is not set.
Interestingly, if I dim a notesdoc object in the calling routine and pass the unset doc, there is no problem. But I want to avoid this dependency.
Listed here is the second version (with the On Error):
Sub AddLogDoc( subject$, logDoc As NotesDocument )
'If logDoc is nothing, create a log doc with subject$; Otherwise use given logDoc
On Error ErrObjectVariableNotSet Goto CreateNewLogDoc
logDoc.Form = "Log"
logDoc.LogDate = Now
...other similar lines...
logDoc.Save True, False
Exit Sub
CreateNewLogDoc:
Set logDoc = reqDb.CreateDocument
Resume 0
End Sub
I want to call this sub with
Call AddLogDoc( "some text", Nothing )
I also tried
Call AddLogDoc( "some text", )
but that won’t compile.
Subject: RE: Sure you can, it just seems much cleaner to…
Oh it is definitrly cleaner, no doubt about that. And it would save me (and others I am sure) the painw hen we forget a comma or something.
On the other hand, it makes for a good check in case we accidentally forget to put in a parameter tht really may be needed when we make the call.
Subject: RE: Sure you can, it just seems much cleaner to…
Optional ByVal Something As String = “Nothing” blows – give me Overloads or give me death!
Subject: The other good thing about optional parms is that you can extend your function…
like notesDocument.Save(False, False, True) adding the third parameter. But old code that did not have that parameter when compiled still works OK.
Subject: RE: Talking about NotesUIWorkspace.DialogBox for example…
Yeah, but for example in Midas, we have an AppendTable method. The arguments are
GeniiRTChunk.AppendTable(rows%, columns% [, table-properties [, col-1 [, col-2 … [, col-20 ]]]])
Now, if you wanted a method like that for LotusScript, you would have to use 23 parameters, every time. Since it is an LSX, you can have:
Call rtchunk.AppendTable(3,4)
or
Call rtchunk.AppendTable(3,4, “TableWidth=Fixed”)
and so on, but you don’t have to stuff in all those parameters. On the other hand, when the parameters are necessary, they come in very handy. It has also been very handy for adding additional paremeters in later versions without breaking code. I definitely wish you could put in variable parameters, but you can… at least not yet.
Subject: RE: Opional Parameters
Yes, your work-around is fine for “translating” VB to script. There is an “Optional” keyword in VB, which can be used as a modifier against a read-in parameter – that’s what Michael is getting at.
–
Subject: RE: Opional Parameters
Too bad. Lots of uses for that. Oh well, thanks anyway.
MJ
Subject: Example Please?