VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



TriState InputBox

by ULLI (93 Submissions)
Category: String Manipulation
Compatability: VB Script
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (14 Votes)

With the InputBox you cannot distinguish between the cases
a:- Cancel clicked
b:- nothing entered and OK clicked
because in both cases the returned string is a vbNullString
There is a simple trick however as is shown here

Rate TriState InputBox

'With the InputBox you cannot distinguish between the cases
'
'  a:- Cancel clicked
'  b:- nothing entered and OK clicked
'
'because in both cases the returned string is a vbNullString
'
'There is a simple trick however as is shown in this little code snippet:
 Dim UserInput As String
  UserInput = InputBox("Please type in nothing or some text and click OK or Cancel", "Distinguish")
  Select Case True
   Case StrPtr(UserInput) = 0
    MsgBox "You clicked Cancel"
   Case Len(UserInput)
    MsgBox "You typed """ & UserInput & """ and clicked OK"
   Case Else
    MsgBox "You typed nothing and clicked OK"
  End Select
End Sub

Download this snippet    Add to My Saved Code

TriState InputBox Comments

No comments have been posted about TriState InputBox. Why not be the first to post a comment about TriState InputBox.

Post your comment

Subject:
Message:
0/1000 characters