A simple inputbox & responding msgbox coding

F

FARAZ QURESHI

I sure woul oblige for the simplest piece of code for an inputbox as:

"Enter Your Name"

1. If nothing is entered and OK is pressed:
msgbox("Nothing has been entered. Please RETRY")

2. If Cancel is pressed:
msgbox("You have cancelled the operation")

3. If something is entered and OK is pressed:
msgbox("You are " & Nme)

I have also found that codes do not work similarly enough in respect of the
TYPE of the inputbox to be Text or Cell Reference/Range Based, i.e. for
Type:=2 or Type:=8 any reference for relevant material on net.

Thanx in advance.
 
J

Jacob Skaria

Can you explain the issue referring to the example below...

Sub TestInputBox()
Dim varInput As Variant
InputBox:
varInput = Application.InputBox("Enter your name", Type:=2)
If varInput = False Then
MsgBox "You have cancelled the Operation": Exit Sub
ElseIf varInput = "" Then
MsgBox "Nothing has been entered. Please RETRY": GoTo InputBox
Else
MsgBox "You are " & varInput
End If
End Sub


If this post helps click Yes
 
F

FARAZ QURESHI

Thanx Jacob,

I don't understand why my previous reply didn't appear, however, would only
a Variant Data Type be used even when a String is expected as an input?
 
J

Jacob Skaria

Application.InputBox returns a Boolean for Cancel. So dimensioning the
variable as Variant equips the variable to handle both scenarios.

On the otherhand InputBox returns a vbNullString ("")

If this post helps click Yes
 
J

Jacob Skaria

Dear Faraz

Your reply has gone to the post just below...It happens with me too quite
often...

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top