Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inputbox question 3

Status
Not open for further replies.

johnnyv

Programmer
Jul 13, 2001
216
0
0
CA
Hello all

I am playing around with the inputbox function. As far as I can tell if I do not put in a default value then the user clicking ok without entering a value provides the same return as if the user clicks cancel? is this correct? and if so how can I tell the difference between the 2 actions. My one thought was to provide a default value = " "
putting this in is flawed in that if the user deletes this default value and does not replace it with something then I am no further ahead.

Thanks in advance for any responses
 
Let me answer my own question....

I did another seach of this forum after posting the above question and found the following.
(yes I know look before you ask!!)
Anyways here it is



If you thought there was no way to tell the difference if the user pressed Cancel or OK on an InputBox, you're wrong.

You see, if the user presses cancel, vbNullString is returned. However if they press OK, the empty string ("") is sent back.

But in Visual Basic, vbNullString equates to an empty string, so you can't compare the two - even though in reality, they're completely different.

However you can use StrPtr to evaluate the difference between the two.

If the user had pressed Cancel StrPtr of the returned string is 0, else it is some value > 0.



I will have to go back to the post that I copied this from and provide a big fat star!!
 
I found this out quite a bit ago myself.

Private Sub Command1_Click()
Dim JobNumber As String
JobNumber = InputBox("Enter the job number:")
If StrPtr(JobNumber) = 0 Then
MsgBox "Cancel pressed!", vbInformation
ElseIf JobNumber = vbNullString Then
MsgBox "You must enter a valid job number!", vbInformation + vbOKOnly
Else
MsgBox JobNumber
End If
End Sub

Swi
 
I always like to see someone answer their own question. I just thought I would post an example.

Swi
 
Using a Inputbox, how do you make part of the display message to be bold. I know I've seen it before somewhere, maybe using Chr() function?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top