Nachtrag
Ich habe mal bei Andrew Pitonyak nachgeforscht zum Thema "Optional" und
"IsMissing":
[1] Nach einem optionalen Parameter dürfen nur noch optionale Parameter
folgen.
[2] Man kann jeden optionalen Parameter weglassen, auch, wenn auf diesen
ein Komma folgt, aber:
BEZUG 1: Das funktioniert nur, wenn die optionalen Parameter vom Typ
"Variant" sind.
BEZUG 2: Pitonyak hat dieses Verhalten als BUG (der
"IsMissing"-Anweisung) eingestuft und gemeldet.
BEZUG 3: Apache OpenOffice (AOO) Bugzilla fühlt sich nicht zuständig,
weil es nichts mit StarBasic zu tun hat.
[3] Das Beispiel in der "LO BASIC-IDE Hilfe" zu "Optional" ist
fehlerfrei (BEZUG 4):
+ Es entspricht BEZUG 1.
+ Allerdings wäre es hilfreich, wenn darauf hingewiesen würde, dass auf
Grund eines noch bestehenden BUGs nur genau diese Variante (bezüglich
der Typ-Deklarationen) funktioniert.
[4] Auf Grund des noch bestehenden BUGs (wenn denn Pitonyak mit seiner
Einschätzung richtig liegt) tendiere ich persönlich zu Thomas' Vorschlag
"sauberer Programmierung" (keinen optionalen Parameter zwischen zwei
Kommas weglassen), da man zu leicht vergessen könnte, dass eine (in
allen Nutzungs-Varianten) funktionierende "IsMissing"-Anweisung zwingend
von der Typ-Deklaration "Variant" abhängt für alle optionalen Parameter.
Grüße
Hans-Werner
BEZUG 1: Andrew Pitonyak (04.2016 - S.55/56) -
http://www.pitonyak.org/OOME_3_0.odt
Optional arguments
You can declare arguments as optional by preceding them with the keyword
Optional. All of the arguments following an optional argument must also
be optional. Use the IsMissing function to determine if an optional
argument is missing.
Listing 30. Optional arguments.
REM Make test calls with optional arguments.
REM Calls with Integer and Variant arguments should yield the same
result.
REM Unfortunately, they do not.
Sub ExampleArgOptional()
Dim s$
s = "Variant Arguments () => " & TestOpt() & CHR$(10) &_
"Integer Arguments () => " & TestOptI() & CHR$(10) &_
"---------------------------------------------" & CHR$(10) &_
"Variant Arguments (,,) => " & TestOpt(,,) & CHR$(10) &_
"Integer Arguments (,,) => " & TestOptI(,,) & CHR$(10) &_
"---------------------------------------------" & CHR$(10) &_
"Variant Arguments (1) => " & TestOpt(1) & CHR$(10) &_
"Integer Arguments (1) => " & TestOptI(1) & CHR$(10) &_
"---------------------------------------------" & CHR$(10) &_
"Variant Arguments (,2) => " & TestOpt(,2) & CHR$(10) &_
"Integer Arguments (,2) => " & TestOptI(,2) & CHR$(10) &_
"---------------------------------------------" & CHR$(10) &_
"Variant Arguments (1,2) => " & TestOpt(1,2) & CHR$(10) &_
"Integer Arguments (1,2) => " & TestOptI(1,2) & CHR$(10) &_
"---------------------------------------------" & CHR$(10) &_
"Variant Arguments (1,,3) => " & TestOpt(1,,3) & CHR$(10) &_
"Integer Arguments (1,,3) => " & TestOptI(1,,3) & CHR$(10)
MsgBox s, 0, "Optional Arguments of Type Variant or Integer"
End Sub
REM Return a string that contains each argument. If the argument
REM is missing, then an M is used in its place.
Function TestOpt(Optional v1, Optional v2, Optional v3) As String
TestOpt = "" & IIF(IsMissing(v1), "M", Str(v1)) &_
IIF(IsMissing(v2), "M", Str(v2)) &_
IIF(IsMissing(v3), "M", Str(v3))
End Function
REM Return a string that contains each argument. If the argument
REM is missing, then an M is used in its place.
Function TestOptI(Optional i1%, Optional i2%, Optional i3%) As String
TestOptI = "" & IIF(IsMissing(i1), "M", Str(i1)) &_
IIF(IsMissing(i2), "M", Str(i2)) &_
IIF(IsMissing(i3), "M", Str(i3))
End Function
You can omit any optional arguments. Listing 30 demonstrates two
functions that accept optional arguments. The functions are the same
except for the argument types. Each function returns a string containing
the argument values concatenated together. Missing arguments are
represented by the letter “M” in the string. Although the return values
from TestOpt and TestOpt1 should be the same for the same argument
lists, they are not (see Figure 27). This is a bug.
TIP: The IsMissing function returns incorrect results for variables that
are not of type Variant when the missing argument is followed by a
comma.
Variant Arguments () => MMM
Integer Arguments () => MMM
---------------------------------------------
Variant Arguments (,,) => MMM
Integer Arguments (,,) => 448 448M
---------------------------------------------
Variant Arguments (1) => 1MM
Integer Arguments (1) => 1MM
---------------------------------------------
Variant Arguments (,2) => M 2M
Integer Arguments (,2) => 448 2M
---------------------------------------------
Variant Arguments (1,2) => 1 2M
Integer Arguments (1,2) => 1 2M
---------------------------------------------
Variant Arguments (1,,3) => 1M 3
Integer Arguments (1,,3) => 1 448 3
Figure 27. In rare cases, non-Variant optional arguments fail.
BEZUG 2: Andrew Pitonyak (06.2015 - S.399) -
http://www.pitonyak.org/AndrewMacro.odt
Warning
As of version 1.0.3.1, IsMissing will fail with Optional parameters if
the type is not Variant and the missing optional parameter is
represented by two consecutive commas. I first investigated this
behavior after speaking with Christian Anderson [ca@ofs.no]. This is
issue 11678 in issuezilla.
BEZUG 3: https://bz.apache.org/ooo/show_bug.cgi?id=11678
Unknown 2003-02-25 13:43:18 UTC
Misfiled, the framewwork/ scripting deals with the langauge independent
scripting framework, not Star Basic:
BEZUG 4: Test-Makros
Sub Calling_VARIANT
Dim A,B,C as String
A = "A" : B = "B" : C = "C" : D = "D"
Called_VARIANT(A,,,D)
End Sub
Sub Called_VARIANT(Optional AA as Variant,Optional BB as
Variant,Optional CC as Variant)
MsgBox("IsMissing(AA)=" & IsMissing(AA) & Chr(13) &_
"IsMissing(BB)=" & IsMissing(BB) & Chr(13) &_
"IsMissing(CC)=" & IsMissing(CC) & Chr(13) &_
"IsMissing(CC)=" & IsMissing(DD) & Chr(13))
End Sub
MsgBox-Ausgabe:
IsMissing(AA)=False
IsMissing(BB)=True
IsMissing(CC)=True
IsMissing(CC)=False
----------------------------------------------------------------------------------------
Sub Calling_INTEGER
Dim A,B,C as Integer
A = 1 : B = 2 : C = 3 : D = 4
Called_INTEGER(A,,,C)
End Sub
Sub Called_INTEGER(Optional AA as Integer,Optional BB as
Integer,Optional CC as Integer)
MsgBox("IsMissing(AA)=" & IsMissing(AA) & Chr(13) &_
"IsMissing(BB)=" & IsMissing(BB) & Chr(13) &_
"IsMissing(CC)=" & IsMissing(CC) & Chr(13) &_
"IsMissing(CC)=" & IsMissing(DD) & Chr(13))
End Sub
MsgBox-Ausgabe:
IsMissing(AA)=False
IsMissing(BB)=False
IsMissing(CC)=False
IsMissing(CC)=False
--
Liste abmelden mit E-Mail an: users+unsubscribe@de.libreoffice.org
Probleme? https://de.libreoffice.org/hilfe-kontakt/mailing-listen/abmeldung-liste/
Tipps zu Listenmails: https://wiki.documentfoundation.org/Netiquette/de
Listenarchiv: https://listarchives.libreoffice.org/de/users/
Alle E-Mails an diese Liste werden unlöschbar öffentlich archiviert
Context
- Re: [de-users] LO Makro Basic Option ''Optional'' - ''IsMissing'' immer ''False'' · OoOHWHOoO
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.