Sam,
VB.IIf is a function that accepts two Object values & returns an Object
value, you need to cast the return value back to DialogResult to use it:
| Me.DialogResult = DirectCast(IIf(m_UserWeb.AddUserWeb(Data),
DialogResult.OK,
| DialogResult.Abort), DialogResult).
Because of the "awkwardness" of the above DirectCast I normally avoid IIf in
VB.NET 2003 & 2003
With VB.NET 2005 one can define a Generic version of IIf that does not need
the above DirectCast, plus it avoids any potential boxing issues.
' VS.NET 2005 syntax
Public Function IIf(Of T)(ByVal expression As Boolean, _
ByVal truePart As T, ByVal falsePart As T) As T
If expression Then
Return truePart
Else
Return falsePart
End If
End Function
The generic IIf(Of T) function avoids the need (the "awkwardness") of the
DirectCast. I would consider using the Generic IIf as it may simplify some
expressions...
You can use IIf(Of T) as you would VB.IIf, the compiler is able to infer the
parameter for T.
Either:
Me.DialogResult = IIf(m_UserWeb.AddUserWeb(Data), _
DialogResult.OK, DialogResult.Abort)
Or:
Me.DialogResult = IIf(Of DialogResult)(m_UserWeb.AddUserWeb(Data), _
DialogResult.OK, DialogResult.Abort)
However! the "problem" with both the VB.IIf & my IIf(Of T) is that both
operands are evaluated which may have undesired side effects.
Hope this helps
Jay
| Hi,
| I don't understand that:
|
| Me.DialogResult = IIf(m_UserWeb.AddUserWeb(Data), DialogResult.OK,
| DialogResult.Abort)
|
| (m_UserWeb.AddUserWeb(Data) returns a boolean)
|
| gives : Option Strict On disallows implicit conversions from
| 'System.Object' to 'System.Windows.Forms.DialogResult'.
|
| What should I do ?
|
| Thx
|