You can use the IsMissing function to check whether an optional parameter has been specified when passing parameters to a function. If the parameter is specified or if the specified variable is not an optional parameter, the function returns False, otherwise True.
Syntax | ||||
IsMissing(Variable) | ||||
Return value | ||||
Type |
Description | |||
Boolean |
True if the variable was not specified during parameter transfer | |||
Parameter | ||||
Use |
Name |
Type |
Passing |
Description |
Required |
Variable |
Variable |
ByVal |
Variable |
The following example uses the optional Gloss parameter. If this is not specified when the function is called, this is detected using the IsMissing function. In the further sequence, the RGB color values of the passed RAL code are determined.
SetColor(3001)
Function SetColor(ByVal RALCode As Long, Optional ByVal Gloss As Long) As Void
If IsMissing(Gloss) Then
Gloss := 1
End If
Dim Col As New TCEGDIP.GDIPColor, ARGB As Long
ARGB := Col.RALtoARGB(RALCode)
Col.Value := ARGB
MsgBox(Col.Red & " " & Col.Green & " " & Col.Blue & " Gloss " & Gloss)
End Function
Alternatively, a default value can be specified for optional parameters: In this example, the check with IsMissing can be omitted.
Function SetColor(ByVal RALCode As Long, Optional ByVal Gloss As Long := 1) As Void
Dim Col As New TCEGDIP.GDIPColor, ARGB As Long
ARGB := Col.RALtoARGB(RALCode)
Col.Value := ARGB
MsgBox(Col.Red & " " & Col.Green & " " & Col.Blue & " Gloss " & Gloss)
End Function