IsMissing without using Variant data type

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
No, I don't believe so. According to the language spec, if the default value for an optional argument that is not a Variant is not specified, it is treated as being the default value for the relevant data type. So a value is always provided, it's just that Variant allows the use of the Missing type.
 
Upvote 0
Seems doubtful.

I think a missing (optional, per force) variable is passed on the stack with the default value (e.g., 0 for a number, Empty with the IsMissing flag for a Variant) just like any value passed ByVal (versus the address of a variable being on the stack if passed ByRef).
 
Upvote 0
Thanks .. I was thinking maybe the function stack size would differ if no arg was supplied but like you said, vb coerces the missing arg to the default value for the relevant data type so the size would always be the same.

One tacky workaround I can think of is to set the default value as unlikely value .. Something like this :

Code:
Function Test(Optional arg As Double = -0.1152254411411) As String

If arg = -0.1152254411411 Then MsgBox "Arg missing" Else MsgBox "You passed : " & arg
 
Upvote 0
If I were going to use a particular number, it would be the biggest a Double can contain:

Code:
Const dBig = 9E+307 + 8.97693134862315E+307 + 6E+292

Function test1(Optional d As Double = dBig) As Double
  test1 = d
End Function

... because it can't be entered from the UI, and it's hard to arrive at as a result of a calculation.
 
Upvote 0
If I were going to use a particular number, it would be the biggest a Double can contain:

Code:
Const dBig = 9E+307 + 8.97693134862315E+307 + 6E+292

Function test1(Optional d As Double = dBig) As Double
  test1 = d
End Function

... because it can't be entered from the UI, and it's hard to arrive at as a result of a calculation.

Yes I agree
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top