In another thread, I mentioned an inputbox with more than two buttons. Here it is. I call this thing an InputForm.
It's really a userform created on the fly. It is done by creating a new class, thingInputForm.
To call the form, a variable is declared as the new data class.
userInput.InputForm(Prompt,[Title],[Buttons],[Default],[dataType],[passwordChar]) calls the InputForm and the user makes their entry.
A thingInputForm hold the results of the last user interface in the properties .Value and .Pressed.
.Value is what was entered into the box with either the keyboard or mouse.
.Pressed ,with no index , returns the number of the button that was pressed at the last user entry.
.Pressed(i) returns a boolean value. True if button #i was the last pressed.
.InputForm displays a input box with up to three buttons. InputForm returns the number of the button pressed (same as .Pressed) or False if the user Cancels.
The arguments Prompt, Title, and Default are strings.
Buttons is an optional argument. Setting it to vbOKOnly, vbOKCancel, vbYesNoCancel determines how many buttons are shown.
Adding vbDefault1, 2 or 3 to that value changes the default. Those are the only button styles InputForm accepts.
vbOKCancel is the default.
dataType is as in an inputbox. 1-number,2-text,4-logical,8-range,16-error
passwordChar will mask the characters for password entry. If passwordChar = False characters entered are displayed normaly. If True, a bullet will mask each character entered. A custom masking character can be entered as a string.
This password demo shows the general syntax. The other demos in the attachment show other features.
- Sub passwordDemo()
- Dim passCode As New thingInputForm
- Dim inputButton As String
- inputButton = passCode.InputForm(Prompt:="Type, friend, and enter.", _
- Title:="Password Check", _
- dataType:=2, _
- If inputButton = "False" Then Exit Sub
- If LCase(passCode.Value) = "friend" Then
- MsgBox "Welcome, friend, you pass."
- MsgBox "Wrong password entered."
- End If
- End Sub
thingInputForm can easily be transmuted out of a class and into a function. The creeping feature creature prowls around a project like this. A fourth button and custom button caption arguments are a couple of features I rejected.
The default button needs better bolding and the validation function typeOK is not too clean.
I hope someone finds this useful.