View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default What type is vbCancel?

Just for the record, vbCancel and all other results of a MsgBox
are Longs, not Integers.


"Steven Fatzinger" wrote in message
...
Shatin wrote:
In the code fragment below, when I push the cancel button in

response to the
inputbox, I get a type mismatch error. What type is vbCancel?

Dim myDate as String

Do
myDate = InputBox("Please enter your name.")
If myDate = vbCancel Then
Exit Sub
ElseIf myDate = "" Then
MsgBox ("You didn't enter anything. Please try

again.")
End If
Loop While myDate = ""

In the same macro, I have these similar lines which work OK:

Dim myCheck as String

mycheck = MsgBox("Proceed?", vbYesNo)
If myCheck = vbNo Then
Exit Sub
End If

Why don't I get any type mismatch error with vbNo?


Believe it or not, you should always check the help file first.
The InputBox returns a String, MsgBox returns an Integer.
Both vbNo and vbCancel are Integers.
Your InputBox line places a string in myDate.
You then compare that string to vbNo, which is an Integer
It would be better to use the following test:
If Len(myDate)=0 Then Exit Sub