Differentiate b/w False and 0 with InputBox fn

M

Marcotte A

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
 
J

Juan Pablo González

If always use

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

--
Regards

Juan Pablo González

Marcotte A said:
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
 
K

kkknie

Another solution (Juan Pablo is always a bit quicker...).

Change from:

If vCost = False

To:

If CStr(vCost) = "False"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top