Results 1 to 10 of 10

Thread: VB - An InputBox Form

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    VB - An InputBox Form

    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.

    VB Code:
    1. '   frmInputBox.ButtonClicked   ' Returns vbOK or vbCancel
    2.                                 ' depending on the button clicked
    3. '   frmInputBox.Default         ' Returns/sets the initial value
    4.                                 ' for user input
    5. '   frmInputBox.Display         ' Show the form modally
    6. '   frmInputBox.PasswordProtect ' Returns/sets whether characters
    7.                                 ' typed by the user are protected
    8.                                 ' by asterisks. (If this is set to True,
    9.                                 ' it doesn't make sense to set the Default
    10.                                 ' property.
    11. '   frmInputBox.Prompt          ' Set the InputBox Prompt value
    12. '   frmInputBox.Title           ' Set the InputBox Caption value

    Usage

    VB Code:
    1. frmInputBox.Title = "Value Entry"          
    2. frmInputBox.Prompt = "Please enter a value"    
    3. frmInputBox.Display  
    4.  
    5. If vbCancel = frmInputBox.ButtonClicked  Then
    6.     MsgBox "You pressed Cancel"
    7. End If
    Attached Files Attached Files

  2. #2
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    Just being pedantic here, but is there any way of giving the OK button the 'raised' look?



    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.
    Attached Images Attached Images  

  3. #3

  4. #4
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    Not quite. This is what I meant.
    These images are on first load.



    See how the real one has a darker outline?
    Attached Images Attached Images  

  5. #5

  6. #6
    Lively Member Phantom1's Avatar
    Join Date
    Nov 2011
    Posts
    64

    Re: VB - An InputBox Form

    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.

    Code:
    Select Case Index
        Case btnOK
            ButtonClicked = vbOK
        Case btnCancel
            ButtonClicked = vbCancel
    End Select
    Last edited by Phantom1; Dec 28th, 2011 at 02:05 PM.
    Learning to Program on Earth until I go into Outer Space...

  7. #7

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB - An InputBox Form

    Quote Originally Posted by Phantom1 View Post
    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.
    Quote Originally Posted by Phantom1
    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
    Code:
    If ButtonClicked = 0 Then ButtonClicked = vbCancel
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  9. #9

  10. #10
    Lively Member Phantom1's Avatar
    Join Date
    Nov 2011
    Posts
    64

    Re: VB - An InputBox Form

    Quote Originally Posted by MartinLiss View Post
    ButtonClicked is a Property that you can check from another form. For example in Form1

    MsgBox frmInputBox.ButtonClicked
    Quote Originally Posted by LaVolpe View Post
    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.

    Learning to Program on Earth until I go into Outer Space...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width