|
-
Dec 28th, 2001, 04:43 AM
#1
Thread Starter
Lively Member
ismissing
Private Sub Command1_Click()
f1
End Sub
Private Sub Command2_Click()
f2
End Sub
Private Sub f1(Optional a As Variant)
MsgBox IsMissing(a)
End Sub
Private Sub f2(Optional a As Integer)
MsgBox IsMissing(a)
End Sub
the function only works with the variant type
is there another way to use this
-
Dec 28th, 2001, 05:07 AM
#2
PowerPoster
hi
use this:
Code:
in the Ismissing function just add this:
if isnumeric(a) then
a= cstr(a)
end if
'further your code
-
Dec 28th, 2001, 05:09 AM
#3
FROM MSDN :
IsMissing(argname)
The required argname argument contains the name of an optional Variant procedure argument.
Maybe something like this : (If this doesn't do it, let me know the data type you want other than th variant)
Code:
Private Sub f1(Optional a As String)
If IsNull(a) Then Msgbox "Not Here"
End Sub
-
Dec 28th, 2001, 05:26 AM
#4
PowerPoster
-
Dec 28th, 2001, 05:36 AM
#5
Thread Starter
Lively Member
It doesnt work i changed the code a bit
Private Sub Command1_Click()
f1
End Sub
Private Sub Command2_Click()
f2
End Sub
'Private Sub f1(Optional a As Variant)
' MsgBox IsMissing(a)
'End Sub
Private Sub f1(Optional a As String)
If IsNull(a) Then MsgBox "Not Here"
End Sub
Private Sub f2(Optional a As Integer)
MsgBox TypeName(a)
MsgBox IsNull(a)
If IsNull(a) Then
MsgBox "tis null"
End If
MsgBox IsMissing(a)
End Sub
when i press button 1 the functions should show the msgbox with the text not here but nothing appears ...
-
Dec 28th, 2001, 05:40 AM
#6
Addicted Member
because you are DECLARING the optional variable, it is initialized to its default value.
so if you are using a variant, it can have an 'ismissing' value.
but a string is initialized as "" (empty 'string').
so to check this, instead of 'ismissing' use
Code:
if a = "" then
msgbox "is missing"
else
msgbox "is not missing (" & a & ")"
end if
-
Dec 28th, 2001, 05:44 AM
#7
That's why I asked the data type - if it's a string, you can check for a vbnullstring value.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|