VisualBasic InputBox Cancel

Quick question:

I use Microsoft.VisualBasic.Interaction.InputBoxin my C # code so that users can add websites to the list, but I do not want them to enter an empty string, so I provide a popup with an error in case this happens. However, an error will also appear if the user clicks cancel, which I don’t want.

Reading the documentation on it says that clicking "cancel" returns an empty string, so it causes an error. Is there a way to determine if the user can click "okay" with an empty line or "cancel"?

Thanks in advance,

-Peter

+4
source share
2 answers

. MSDN

"", .

    Dim result As String = Microsoft.VisualBasic.InputBox("Enter some text")
    If result.Length > 0 Then
        Debug.WriteLine("Something entered and OK Clicked")
    Else
        Debug.WriteLine("Cancel Button Clicked OR Blank String Entered and OK Clicked")
    End If

- DialogResult

+7
string a;
            a = Interaction.InputBox("message", "title");
            if (a.Length > 0)
            {
                comboBox2.Items.Add(a);
                // ok
            }
            else
            {
                // cancel
            }
-4

All Articles