IsMissing Support

    The IsMissing function does not exist in .NET. However VBUC can support the conversion of IsMissing by implementing certain conversion patterns.

    The VBUC starts by recognizing the IsMissing cases that will never return true. These cases are converted to the literal boolean “false”. Other cases are converted by using a specific conversion that provides the same behavior in .NET. It includes optional parameters to overloadings, default values deduction, specific parameter types to general types (nullable for value-types and object for references) and auxiliary local variables generation.

    The following basic example illustrates this specific conversion:

    Original VB6 Code:

    Sub TestIsMissing(Optional i1, Optional f)
       If IsMissing(i1) Then
          MsgBox "i1 is Missing"
       End If
       If IsMissing(f) Then
          MsgBox "f is Missing"
       End If
    End Sub
    Sub Main()
       Dim f As Form
       TestIsMissing 1000, f
       TestIsMissing 1000
    End Sub

    Resulting VB.NET Code:

    Sub TestIsMissing(ByRef i1_optional As Nullable(Of Integer), ByRef f_optional As Object)
        Dim i1 As Integer = 0
        If i1_optional.HasValue Then i1 = i1_optional.Value
        Dim f As Form = Nothing
        If f_optional Is Nothing OrElse Not f_optional.Equals(Type.Missing) Then f = TryCast(f_optional, Form)
        If Not i1_optional.HasValue Then
            MessageBox.Show("i1 is Missing", Application.ProductName)
        End If
        If Not (f_optional Is Nothing) AndAlso f_optional.Equals(Type.Missing) Then
            MessageBox.Show("f is Missing", Application.ProductName)
        End If
    End Sub
    Sub TestIsMissing(ByRef i1_optional As Nullable(Of Integer))
        Dim tempRefParam As Object = Type.Missing
        TestIsMissing(i1_optional, tempRefParam)
    End Sub
    Sub TestIsMissing()
        Dim tempRefParam2 As Nullable(Of Integer) = Nothing
        Dim tempRefParam3 As Object = Type.Missing
        TestIsMissing(tempRefParam2, tempRefParam3)
    End Sub
    Public Sub Main()
        Dim f As Form
        TestIsMissing(1000, f)
    End Sub

    Resulting C#.NET Code:

    static public void  TestIsMissing( int? i1_optional, object f_optional)
        int i1 = ((i1_optional == null) ? 0: i1_optional.Value);
        Form f = ((f_optional == Type.Missing) ? null: f_optional as Form);
        if (i1_optional == null)
            MessageBox.Show("i1 is Missing", Application.ProductName);
        if (f_optional == Type.Missing)
            MessageBox.Show("f is Missing", Application.ProductName);
    static public void  TestIsMissing( int? i1_optional)
        TestIsMissing(i1_optional, Type.Missing);
    static public void  TestIsMissing()
        TestIsMissing(null, Type.Missing);
    static public void  Main()
        Form f = null;
        TestIsMissing(1000, f);

    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration