Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Input Box Vs Cancel
Hello All:
I have a code that will give me a input box to add name to the list. newName = Application.InputBox("Type new student name:", "Add Student", "New Student", Type:=2) If newName = "" Or newName = "FALSE" Then Exit Sub End If My problem is that the input box has OK, Cancel and the X windows default close option in top upper right corner. If I add a name and press OK all is fine. However the cancel and close window option will create a name called FALSE. How would I make it exit sub once those to functions are pressed. Regards Ardy |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Input Box Vs Cancel
Change "FALSE" to "False" and it should work.
Ed On Sep 5, 9:33 am, Ardy wrote: Hello All: I have a code that will give me a input box to add name to the list. newName = Application.InputBox("Type new student name:", "Add Student", "New Student", Type:=2) If newName = "" Or newName = "FALSE" Then Exit Sub End If My problem is that the input box has OK, Cancel and the X windows default close option in top upper right corner. If I add a name and press OK all is fine. However the cancel and close window option will create a name called FALSE. How would I make it exit sub once those to functions are pressed. Regards Ardy |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Input Box Vs Cancel
On Sep 5, 10:31 am, Ed from AZ wrote:
Change "FALSE" to "False" and it should work. Ed On Sep 5, 9:33 am, Ardy wrote: Hello All: I have a code that will give me a input box to add name to the list. newName = Application.InputBox("Type new student name:", "Add Student", "New Student", Type:=2) If newName = "" Or newName = "FALSE" Then Exit Sub End If My problem is that the input box has OK, Cancel and the X windows default close option in top upper right corner. If I add a name and press OK all is fine. However the cancel and close window option will create a name called FALSE. How would I make it exit sub once those to functions are pressed. Regards Ardy Ed: Great, So Simple..... Could you explain a bit what is the difference between the two. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Input Box Vs Cancel
The difference is simply the use of all caps (FALSE) or Title Case
(False). As you step through your code with F8, you can mouse over variables and see what they contain. When I moused over newName, it contained "False", which does not match "FALSE", so it didn't get caught in your If statement. I also hope you have an error trap at some point to catch the person who hits Enter too quickly and gives you "New Student", since that's your default for the InputBox. Ed On Sep 5, 10:52 am, Ardy wrote: On Sep 5, 10:31 am, Ed from AZ wrote: Change "FALSE" to "False" and it should work. Ed On Sep 5, 9:33 am, Ardy wrote: Hello All: I have a code that will give me a input box to add name to the list. newName = Application.InputBox("Type new student name:", "Add Student", "New Student", Type:=2) If newName = "" Or newName = "FALSE" Then Exit Sub End If My problem is that the input box has OK, Cancel and the X windows default close option in top upper right corner. If I add a name and press OK all is fine. However the cancel and close window option will create a name called FALSE. How would I make it exit sub once those to functions are pressed. Regards Ardy Ed: Great, So Simple..... Could you explain a bit what is the difference between the two.- Hide quoted text - - Show quoted text - |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Input Box Vs Cancel
Just to add to Ed's explanation...
VBA is case sensitive when you're comparing text (unless you tell the module not to be). So "False" is different from "FALSE" is different from "FaLsE"... And I bet you declared newName as a string--so the boolean False was changed to the string "False". I may have used: dim newName as variant newname = application.inputbox(...) if newname = "" _ or newname = False then ' this checks for the boolean false--not a string. ... But I would have really used Inputbox (without application.inputbox). dim NewName as string newname = inputbox(...) if trim(newname) = "" then 'they canceled else 'they didn't end if I guess I don't see the benefit of using application.inputbox(type:=2) to return a text string. Ardy wrote: On Sep 5, 10:31 am, Ed from AZ wrote: Change "FALSE" to "False" and it should work. Ed On Sep 5, 9:33 am, Ardy wrote: Hello All: I have a code that will give me a input box to add name to the list. newName = Application.InputBox("Type new student name:", "Add Student", "New Student", Type:=2) If newName = "" Or newName = "FALSE" Then Exit Sub End If My problem is that the input box has OK, Cancel and the X windows default close option in top upper right corner. If I add a name and press OK all is fine. However the cancel and close window option will create a name called FALSE. How would I make it exit sub once those to functions are pressed. Regards Ardy Ed: Great, So Simple..... Could you explain a bit what is the difference between the two. -- Dave Peterson |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Input Box Vs Cancel
On Sep 5, 7:50 pm, Dave Peterson wrote:
Just to add to Ed's explanation... VBA is case sensitive when you're comparing text (unless you tell the module not to be). So "False" is different from "FALSE" is different from "FaLsE"... And I bet you declared newName as a string--so the boolean False was changed to the string "False". I may have used: dim newName as variant newname = application.inputbox(...) if newname = "" _ or newname = False then ' this checks for the boolean false--not a string. ... But I would have really used Inputbox (without application.inputbox). dim NewName as string newname = inputbox(...) if trim(newname) = "" then 'they canceled else 'they didn't end if I guess I don't see the benefit of using application.inputbox(type:=2) to return a text string. Ardy wrote: On Sep 5, 10:31 am, Ed from AZ wrote: Change "FALSE" to "False" and it should work. Ed On Sep 5, 9:33 am, Ardy wrote: Hello All: I have a code that will give me a input box to add name to the list. newName = Application.InputBox("Type new student name:", "Add Student", "New Student", Type:=2) If newName = "" Or newName = "FALSE" Then Exit Sub End If My problem is that the input box has OK, Cancel and the X windows default close option in top upper right corner. If I add a name and press OK all is fine. However the cancel and close window option will create a name called FALSE. How would I make it exit sub once those to functions are pressed. Regards Ardy Ed: Great, So Simple..... Could you explain a bit what is the difference between the two. -- Dave Peterson- Hide quoted text - - Show quoted text - Thanks Guys..... I Think I will roll out the file as is, But I relly like Dave's option of not using Application.InputBox. I need to play with this and make this a bit more bulet proof. as of now there are some holes in the applet, which I need to work on. I must have to admit it is really good learning while doing an practical project. My many thanks to all of you. Ardy |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Input Box Vs Cancel
On Sep 5, 11:42 pm, Ardy wrote:
On Sep 5, 7:50 pm, Dave Peterson wrote: Just to add to Ed's explanation... VBA is case sensitive when you're comparing text (unless you tell the module not to be). So "False" is different from "FALSE" is different from "FaLsE"... And I bet you declared newName as a string--so the boolean False was changed to the string "False". I may have used: dim newName as variant newname = application.inputbox(...) if newname = "" _ or newname = False then ' this checks for the boolean false--not a string. ... But I would have really used Inputbox (without application.inputbox). dim NewName as string newname = inputbox(...) if trim(newname) = "" then 'they canceled else 'they didn't end if I guess I don't see the benefit of using application.inputbox(type:=2) to return a text string. Ardy wrote: On Sep 5, 10:31 am, Ed from AZ wrote: Change "FALSE" to "False" and it should work. Ed On Sep 5, 9:33 am, Ardy wrote: Hello All: I have a code that will give me a input box to add name to the list. newName = Application.InputBox("Type new student name:", "Add Student", "New Student", Type:=2) If newName = "" Or newName = "FALSE" Then Exit Sub End If My problem is that the input box has OK, Cancel and the X windows default close option in top upper right corner. If I add a name and press OK all is fine. However the cancel and close window option will create a name called FALSE. How would I make it exit sub once those to functions are pressed. Regards Ardy Ed: Great, So Simple..... Could you explain a bit what is the difference between the two. -- Dave Peterson- Hide quoted text - - Show quoted text - Thanks Guys..... I Think I will roll out the file as is, But I relly like Dave's option of not using Application.InputBox. I need to play with this and make this a bit more bulet proof. as of now there are some holes in the applet, which I need to work on. I must have to admit it is really good learning while doing an practical project. My many thanks to all of you. Ardy- Hide quoted text - - Show quoted text - Hau guys what happen to the star ratings.......... |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Input Box Cancel | Excel Discussion (Misc queries) | |||
Input Box - CANCEL | Excel Worksheet Functions | |||
Input Box - Hit cancel | Excel Programming | |||
Input box to cancel sub when Cancel is clicked. | Excel Programming | |||
cancel input | Excel Discussion (Misc queries) |