Differentiate between False and Zero for Input Box return?

C

Chadersmith

Hi Everyone,

I've got an input box that asks a question and I have the default set for
zero. I'd like to write some follow up logic that reverts back to the
beginning if the cancel button is chosen, but I'd like to keep the zero value
as true. Is there anyway to do this? I've included the code below. As always
I really appreciate the help.

Dim Sulfur As String
Sulfur = Application.InputBox("If you do not have any of this isotope in
your lab, please enter 0 and press OK", "35S", 0)
Range("G33") = Sulfur
If Sulfur = False Then
MsgBox "You clicked Cancel. Please try again.", 64, "Cancel was
clicked."
GoTo Sulfur
ElseIf Sulfur = 0 Then
GoTo P32
Else
GoTo P32
End If


Thanks,
Chad
 
P

Peter T

Sub test()
Dim vResult As Variant

vResult = Application.InputBox("input or cancel")
If VarType(vResult) = vbBoolean Then
MsgBox "user cancelled"
Else: MsgBox vResult
End If

End Sub

Regards,
Peter T
 
C

Chadersmith

Thanks Peter!

Peter T said:
Sub test()
Dim vResult As Variant

vResult = Application.InputBox("input or cancel")
If VarType(vResult) = vbBoolean Then
MsgBox "user cancelled"
Else: MsgBox vResult
End If

End Sub

Regards,
Peter T




.
 
C

Chip Pearson

Try

Dim S As String
S = InputBox("prompt", "title", 0)
If StrPtr(S) = 0 Then
Debug.Print "cancel"
Else
Debug.Print S
End If

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]
 

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