WARNING #6022

    The CommonDialog CancelError property is not supported in Visual Basic .NET.

    Description 

    The property CommonDialog.CancelError is not currently supported by VBUC, nevertheless it is possible get a similar behavior or functionality by using .NET properties. 

    Recommendations 

    Understand how the CommonDialog.CancelError property is used in the VB6 source code and apply a manual change in order to emulate the behavior in the .NET platform. 

    In .NET, the CommonDialog.ShowDialog() method shows the Dialog and after the dialog is closed, returns the information of the Dialog button that was pressed by the user. This returning value must be compared against the members of the System.Windows.Forms.DialogResult Enumeration 

    Sample VB6 

    Private Sub cmdColour_Click()
        On Error GoTo errhandler
        CommonDialog1.CancelError = True

        ' Display the Colour dialog box
        CommonDialog1.ShowColor
        ' Set the forms background colour to the one selected
        Me.BackColor = CommonDialog1.Color
        Exit Sub
    errhandler:
        Select Case Err
        Case 32755 ' Dialog Canceled
             MsgBox "You canceled the dialog box"
        Case Else
             MsgBox "Unexpected error. Err " & Err & " : " & Error
        End Select
    End Sub

    Target VB.NET 

    PrivateSub cmdColour_Click(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles cmdColour.Click 
    OnErrorGoTo errhandler 
    'UPGRADE_WARNING: (6022) The CommonDialog CancelError property is not supported in Visual Basic .NET. 
    CommonDialog1.CancelError = True 
    ' Display the Colour dialog box 
    CommonDialog1Color.ShowDialog()
    ' Set the forms background colour to the one selected 
    Me.BackColor = CommonDialog1Color.Color 
    ExitSub 
    errhandler:
    SelectCase Information.Err().Number 
    Case 32755 ' Dialog Canceled 
    MessageBox.Show("You canceled the dialog box", Application.ProductName) 
    CaseElse 
    MessageBox.Show("Unexpected error. Err " & Information.Err().Number & " : " & Conversion.ErrorToString(), Application.ProductName) 
    EndSelect 
    EndSub 

    Expected VB.NET 

    PrivateSub cmdColour_Click(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) Handles cmdColour.Click
    OnErrorGoTo errhandler
    'UPGRADE_WARNING: (6022) The CommonDialog CancelError property is not supported in Visual Basic .NET.
    'CommonDialog1.CancelError = True
    ' Display the Colour dialog box
    'CommonDialog1Color.ShowDialog()
    If (System.Windows.Forms.DialogResult.Cancel <> CommonDialog1Color.ShowDialog()) Then
    ' Set the forms background colour to the one selected
    Me.BackColor = CommonDialog1Color.Color
    ExitSub
    EndIf
    errhandler:
    SelectCase Information.Err().Number
    Case 32755 ' Dialog Canceled
    MessageBox.Show("You canceled the dialog box", Application.ProductName)
    CaseElse
    MessageBox.Show("Unexpected error. Err " & Information.Err().Number & " : " & Conversion.ErrorToString(), Application.ProductName)
    EndSelect
    EndSub

    Target C# 

    privatevoid cmdColour_Click( Object eventSender, EventArgs eventArgs)
    {
    try
    {
    //UPGRADE_WARNING: (6022) The CommonDialog CancelError property is not supported in Visual Basic .NET.
    CommonDialog1.CancelError = true;
    // Display the Colour dialog box
    CommonDialog1Color.ShowDialog();
    // Set the forms background colour to the one selected
    this.BackColor = CommonDialog1Color.Color;
    }
    catch
    {
    //UPGRADE_WARNING: (1041) Err.Number has a new behavior.
    switch(Information.Err().Number)
    {
    case 32755 : // Dialog Canceled
    MessageBox.Show("You canceled the dialog box", Application.ProductName);
    break;
    default:
    //UPGRADE_WARNING: (1041) Err.Number has a new behavior.
    MessageBox.Show("Unexpected error. Err " + Information.Err().Number.ToString() + " : " + Conversion.ErrorToString(), Application.ProductName);
    break;
    }
    }
    }

    Expected C# 

    privatevoid cmdColour_Click( Object eventSender, EventArgs eventArgs)
    {
    try
    {
    //UPGRADE_WARNING: (6022) The CommonDialog CancelError property is not supported in Visual Basic .NET.
    //CommonDialog1.CancelError = true;
    // Display the Colour dialog box
    //CommonDialog1Color.ShowDialog();
    if (System.Windows.Forms.DialogResult.Cancel != CommonDialog1Color.ShowDialog())
    {
    // Set the forms background colour to the one selected
    this.BackColor = CommonDialog1Color.Color;
    }
    }
    catch
    {
    //UPGRADE_WARNING: (1041) Err.Number has a new behavior.
    switch(Information.Err().Number)
    {
    case 32755 : // Dialog Canceled
    MessageBox.Show("You canceled the dialog box", Application.ProductName);
    break;
    default:
    //UPGRADE_WARNING: (1041) Err.Number has a new behavior.
    MessageBox.Show("Unexpected error. Err " + Information.Err().Number.ToString() + " : " + Conversion.ErrorToString(), Application.ProductName);
    break;
    }
    }
    }


    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