ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Differentiate b/w False and 0 with InputBox fn (https://www.excelbanter.com/excel-programming/300762-differentiate-b-w-false-0-inputbox-fn.html)

Marcotte A[_2_]

Differentiate b/w False and 0 with InputBox fn
 
I'm using an InputBox to get info from the user. I am getting 5 numbers and strings associated with a product. Some of the numbers can be zero. I would like to have the user be able to hit cancel anytime before entering in the 5th variable to cancel the whole operation. IE, put the old info back in and prompt the user to select a new product. This works fine unless they enter 0 for a number. Here is a snippet of the code: (note: the variables are Variants so that I can test for a FALSE return from InputBox. Seperate question: could my number variables be singles instead?) TI

'This is inside a larger Do..Loop that covers entering all five variables. All five variables have loops like this below to test the input from the user

D
vOldCost = .Cells(RowNum, 16).Value 'Capture the old Cost dat
vCost = Application.InputBox(prompt:="Enter material cost.",
Type:=1
If vCost = False Then 'problem is here...user enters in 0 for cost and the If gets executed
CancelProdInput vOldProduct, vOldCost,
vOldType, vOldTime, vOldPrice, RowNum ' CancelProdInput puts the 'Old' data back in the correct cell
GoTo LoopBegin 'go back to beginning....ask user to select product
End I
.Cells(RowNum, 16) = vCos
Loop Until vCost = 0

Juan Pablo González

Differentiate b/w False and 0 with InputBox fn
 
If always use

If TypeName(vCost) = "Boolean" Then
'It's False
End If

--
Regards

Juan Pablo González

"Marcotte A" wrote in message
...
I'm using an InputBox to get info from the user. I am getting 5 numbers

and strings associated with a product. Some of the numbers can be zero. I
would like to have the user be able to hit cancel anytime before entering in
the 5th variable to cancel the whole operation. IE, put the old info back
in and prompt the user to select a new product. This works fine unless they
enter 0 for a number. Here is a snippet of the code: (note: the variables
are Variants so that I can test for a FALSE return from InputBox. Seperate
question: could my number variables be singles instead?) TIA

'This is inside a larger Do..Loop that covers entering all five variables.

All five variables have loops like this below to test the input from the
user.

Do
vOldCost = .Cells(RowNum, 16).Value 'Capture the old Cost data
vCost = Application.InputBox(prompt:="Enter material cost.", _
Type:=1)
If vCost = False Then 'problem is here...user enters in 0 for cost

and the If gets executed.
CancelProdInput vOldProduct, vOldCost, _
vOldType, vOldTime, vOldPrice, RowNum '

CancelProdInput puts the 'Old' data back in the correct cells
GoTo LoopBegin 'go back to beginning....ask user to

select product
End If
.Cells(RowNum, 16) = vCost
Loop Until vCost = 0




kkknie[_145_]

Differentiate b/w False and 0 with InputBox fn
 
Another solution (Juan Pablo is always a bit quicker...).

Change from:

If vCost = False

To:

If CStr(vCost) = "False"



--
Message posted from http://www.ExcelForum.com


Marcotte A[_2_]

Differentiate b/w False and 0 with InputBox fn
 
Cool, that seems to work.... thanks a lot.


All times are GMT +1. The time now is 04:06 PM.

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