PDA

Click to See Complete Forum and Search --> : VB - An InputBox Form


MartinLiss
Feb 18th, 2003, 12:33 PM
The attached form looks exactly like the standard input box except that since it is a form you have full control over what you do with it. I've added the following properties to the form.

' frmInputBox.ButtonClicked ' Returns vbOK or vbCancel
' depending on the button clicked
' frmInputBox.Default ' Returns/sets the initial value
' for user input
' frmInputBox.Display ' Show the form modally
' frmInputBox.PasswordProtect ' Returns/sets whether characters
' typed by the user are protected
' by asterisks. (If this is set to True,
' it doesn't make sense to set the Default
' property.
' frmInputBox.Prompt ' Set the InputBox Prompt value
' frmInputBox.Title ' Set the InputBox Caption value


Usage

frmInputBox.Title = "Value Entry"
frmInputBox.Prompt = "Please enter a value"
frmInputBox.Display

If vbCancel = frmInputBox.ButtonClicked Then
MsgBox "You pressed Cancel"
End If

agmorgan
Dec 5th, 2003, 09:17 AM
Just being pedantic here, but is there any way of giving the OK button the 'raised' look?

http://www.vbforums.com/attachment.php?s=&postid=1574639

In frmInputBox when you select the OK button it gets raised, but then has
the dotted line around it. If you subsequently select the text box it goes flat again.
Unlike the real one.

MartinLiss
Dec 5th, 2003, 11:17 AM
It looks to me as if the real input box behaves the same way.

agmorgan
Dec 5th, 2003, 11:33 AM
Not quite. This is what I meant.
These images are on first load.

http://www.vbforums.com/attachment.php?s=&postid=1574770

See how the real one has a darker outline?

MartinLiss
Dec 5th, 2003, 11:39 AM
Oh. Go to frmInputBox and change the Default property of cmdButton(0) to True.

Phantom1
Dec 28th, 2011, 12:41 PM
An InputBox form is a great idea. However, what is the point of ButtonClicked? It does not seem to do anything to unload the form. One's own code must be added. The Index of the CommandButtons could be used directly instead of having the variables btnOK and btnCancel and checking their integers. The following looks pointless.

Select Case Index
Case btnOK
ButtonClicked = vbOK
Case btnCancel
ButtonClicked = vbCancel
End Select

:confused:

MartinLiss
Dec 28th, 2011, 03:01 PM
ButtonClicked is a Property that you can check from another form. For example in Form1

MsgBox frmInputBox.ButtonClicked

LaVolpe
Dec 28th, 2011, 03:16 PM
However, what is the point of ButtonClicked? It does not seem to do anything to unload the form. One's own code must be added.
From the code of that form, it appears that inputbox form is hidden during cmdButton_Click. The routine that calls the frmInputBox.Display should also unload frmInputBox in my opinion.
The Index of the CommandButtons could be used directly instead of having the variables btnOK and btnCancel and checking their integers. I think this is for convenience. You see Ok & Cancel buttons on the form, it makes sense to return a vbOk or vbCancel value instead of 0 or 1 for example. Just my opinion

For Martinliss. Suggest adding this to the Form_Unload event. Should a user unload the form by clicking the (X) close button, it will be registered as a cancel action
If ButtonClicked = 0 Then ButtonClicked = vbCancel

MartinLiss
Dec 28th, 2011, 03:19 PM
Thanks to you both for your suggestions and comments but this is just a template that you can to with as you want.

Phantom1
Dec 31st, 2011, 06:17 AM
ButtonClicked is a Property that you can check from another form. For example in Form1

MsgBox frmInputBox.ButtonClicked

I think this is for convenience. You see Ok & Cancel buttons on the form, it makes sense to return a vbOk or vbCancel value instead of 0 or 1 for example.

I understand now.

I do not use all the properties, so I use a simpler InputBox form of my own. Nevertheless, I would not have thought of a form acting as InputBox without this thread.

:thumb: