Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default What type is vbCancel?

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?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default What type is vbCancel?

Hi Shatin,

It's an integer. As you want a date, declare it as variant to handle both
types.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Shatin" wrote in message
...
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?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default What type is vbCancel?

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
  #4   Report Post  
Posted to microsoft.public.excel.programming
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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default What type is vbCancel?

Chip Pearson wrote:

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




Technically, you are correct for 32 bit systems.
However, Help still states that it returns an Integer.
Plus, I didn't want to confuse the issue by introducing the Long versus
Integer discussion.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default What type is vbCancel?


vbCancel is an integer, but that's a red herring here.
You get an integer returned from MsgBox if you use it with
buttons, and that is what vbCancel is for.

For an inputbox, if you press the Cancel button, it reurns
an empty string. So you only need the test for empty
string, which you already have.

Do
myDate = InputBox("Please enter your name.")
If myDate = "" Then
MsgBox ("You didn't enter anything. Please try
again.")
End If
Loop While myDate = ""

HTH
Helen


-----Original Message-----
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?


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
EXIT SUB UPON VBCANCEL FARAZ QURESHI Excel Discussion (Misc queries) 2 April 9th 09 12:38 PM
how to convert date type to text type Steffen Excel Discussion (Misc queries) 3 July 17th 07 11:32 AM
how to change all the words of one type(Gunsuh type)to another metumevlut Excel Discussion (Misc queries) 2 November 11th 05 03:29 PM
Adding new 'Type' to Format->Number->Time->Type Chip Pearson Excel Discussion (Misc queries) 5 September 26th 05 08:45 PM
vbCancel Robin Clay[_3_] Excel Programming 6 October 24th 03 12:03 PM


All times are GMT +1. The time now is 06:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"