View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Arvi Laanemets Arvi Laanemets is offline
external usenet poster
 
Posts: 99
Default Excel2000: How to check for Optional parameter=Nothing

Hi

I can drop this for 3rd parameter, but I'm not sure I can do same for 4th
one. And how behaves TypeName() check when the parameter is omitted?


Arvi Laanemets


"Bob Phillips" wrote in message
...
Then why bother with the =Nothing?

--
HTH

Bob Phillips

"Arvi Laanemets" wrote in message
...
Hi again

It looks like I get it to work in this way:
------
Public Function EnchWorkdaysN(StartDate As Date, _
EndDate As Date, _
Optional Holidays As Variant = Nothing,

_
Optional Weekends As Variant = Nothing)


Dim arrayH As Variant, arrayW As Variant
...

If TypeName(Holidays) = "Variant()" _
Or (VarType(Holidays) < 8 And Holidays 0) Then
arrayH = Holidays
ElseIf VarType(Holidays) = 8204 Then
arrayH = Holidays.Value
Else
arrayH = Null
End If
If VarType(arrayH) = 8204 Then
' Sort arrayH
SelectionSort arrayH
End If
If VarType(arrayH) 0 Then
' Remove double entries
' Remove empty elements
' Replace non-integer values with integers
End If
.....
End Function
-------

--
When sending mail, use address arvil<attarkon.ee
Arvi Laanemets



"Bob Phillips" wrote in message
...
Arvi,

If you don't set a default, you can test for missing. You can also

test
what
type of variable is passed.

Public Function EnchWorkdaysN(StartDate As Date, _
EndDate As Date, _
Optional Holidays As Variant, _
Optional Weekends As Variant)
If IsMissing(Holidays) Then
MsgBox "No holidays"
ElseIf TypeName(Holidays) = "Range" Then
MsgBox "Range"
ElseIf IsArray(Holidays) Then
MsgBox "Array"
ElseIf IsDate(Holidays) Then
MsgBox "Date variable"
Else
MsgBox "Erroer"
End If
End Function