Solved

VB.net InputBox Cancel/Closed

Posted on 2014-04-08
4
307 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.NET tools for adding thread safety to a web app? 3 49
cannot connect to sqlserver 8 35
Store results in vb.net 3 25
System.net.Sockets Error 5 28
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

821 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