VB.NET Inputbox - How to identify when the Cancel Button is pressed?
input = InputBox("Text:")
If input <> "" Then
' Normal
Else
' Cancelled, or empty
End If
From MSDN:
If the user clicks Cancel, the function returns a zero-length string ("").
Here is what I did and it worked perfectly for what I was looking to do:
Dim StatusDate As String
StatusDate = InputBox("What status date do you want to pull?", "Enter Status Date", " ")
If StatusDate = " " Then
MessageBox.Show("You must enter a Status date to continue.")
Exit Sub
ElseIf StatusDate = "" Then
Exit Sub
End If
This key was to set the default value of the input box to be an actual space, so a user pressing just the OK button would return a value of " " while pressing cancel returns ""
From a usability standpoint, the defaulted value in the input box starts highlighted and is cleared when a user types so the experience is no different than if the box had no value.