VB.net InputBox Cancel/Closed

Hi

I use the following code to ask a user to enter a row number. If the user clicks the Cancel
button or just closes the box, how will I handle this incode

Dim S As string
 S = Globals.ThisAddIn.Application.InputBox(Prompt:="Please enter a row")
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
Checking for a blank string won't tell you if the user clicked Cancel, or actually entered a blank string.

According to the documentation InputBox will return False if Cancel is clicked:
Dim S As Variant
S = Globals.ThisAddIn.Application.InputBox(Prompt:="Please enter a row")

If S = False Then
   '// Use clicked "Cancel" rather than actually entering a blank string
End If

Open in new window

0
 
JoseBarrosoCommented:
Dim sText = InputBox(Prompt:="Please enter a row")

        If sText = "" Then
            MsgBox("Cancel or Null")
        Else
            MsgBox(sText)
        End If
0
 
KimputerCommented:
Because S is a string,

S = "" when canceled or closed.
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Found that out too. Thanks
0
All Courses

From novice to tech pro — start learning today.