Solved

VB.net InputBox Cancel/Closed

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

785 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