Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
EXIT SUB UPON VBCANCEL | Excel Discussion (Misc queries) | |||
how to convert date type to text type | Excel Discussion (Misc queries) | |||
how to change all the words of one type(Gunsuh type)to another | Excel Discussion (Misc queries) | |||
Adding new 'Type' to Format->Number->Time->Type | Excel Discussion (Misc queries) | |||
vbCancel | Excel Programming |