Solved

VB.net InputBox Cancel/Closed

Posted on 2014-04-08
4
299 Views
Last Modified: 2014-04-11
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")
0
Comment
Question by:murbro
4 Comments
 
LVL 1

Expert Comment

by:JoseBarroso
ID: 39986077
Dim sText = InputBox(Prompt:="Please enter a row")

        If sText = "" Then
            MsgBox("Cancel or Null")
        Else
            MsgBox(sText)
        End If
0
 
LVL 35

Expert Comment

by:Kimputer
ID: 39986084
Because S is a string,

S = "" when canceled or closed.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39986281
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
 

Author Closing Comment

by:murbro
ID: 39995385
Found that out too. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now