ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Input Box Vs Cancel (https://www.excelbanter.com/excel-programming/396910-input-box-vs-cancel.html)

Ardy

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


Ed from AZ

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




Ardy

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.


Ed from AZ

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 -




Dave Peterson

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

Ardy

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


Ardy

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..........



All times are GMT +1. The time now is 08:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com