Thanks Mike. Well done.
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.
VB:Dim userInput As New thingInputForm
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.
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.VB:Sub passwordDemo() Dim passCode As New thingInputForm Dim inputButton As String inputButton = passCode.InputForm(Prompt:="Type, friend, and enter.", _ Title:="Password Check", _ dataType:=2, _ PasswordChar:=True) If inputButton = "False" Then Exit Sub If LCase(passCode.Value) = "friend" Then MsgBox "Welcome, friend, you pass." Else MsgBox "Wrong password entered." End If End Sub
The default button needs better bolding and the validation function typeOK is not too clean.
I hope someone finds this useful.
Last edited by mikerickson; June 23rd, 2007 at 18:50.
Thanks Mike. Well done.
Excel MVP 2011-2014
For more Excel memes: visit http://www.wimgielis.be ==> English articles ==> Excel memes
-- Topics without [CODE] tags or a meaningful topic title, will be neglected by me (and probably many others as well) --
I’m getting numerous Compile Errors when clicking on the “demo” button. Error is always “Can’t find project or library”
this code is highlighted in yellow
VB:Property Get InputForm(Prompt As String, _ Optional Buttons As Variant, _ Optional Title As String, _ Optional Default As String, _ Optional dataType As Long, _ Optional PasswordChar As String) As Variant
and the word Chr$ is selected in this line of code
I get them with simple code such as where Left$ is selected:VB:If CStr(PasswordChar) = "True" Then PasswordChar = Chr$(165)
Removing the $ has no effect, same compile errors.VB:PasswordChar = Left$(PasswordChar, 1)
I’m using xl2000 on the old dog windows98
I get compile errors as well, with Chr$() and LTrim(). Yet when I unload the worksheet, both functions work in the Immediate window. And also on
VB:Dim Form As UserForm
Entia non sunt multiplicanda sine necessitate.
MS MVP - Excel
The RefEdit library needs to be open as does the Microsoft Visual Basic for Applications Extensibility library.
I've found another problem. Every time a userform is created and destroyed, the file takes up a little more space. Excel doesn't complely clear all the memory when a userform is deleted. A temporary userform will make a file grow with each use. A version with permenant userform would be better.
I now have these libraries referenced and got past the initial compile errors. Now have a compile error “Expected user-defined type, not project.”The RefEdit library needs to be open as does the Microsoft Visual Basic for Applications Extensibility library.
BillVB:Private Sub makeRawForm(newComp As Object, _ Prompt As String, _ ByVal Buttons As Long, _ Title As String, _ Default As String, _ PasswordChar As String) Dim newForm As UserForm Dim refEditBox As RefEdit ‘ <<< This line gives the error
There are currently 1 users browsing this thread. (0 members and 1 guests)