Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 77,143 times

Contents

Related Categories

Input Box function - Usage

Usage

The code below displays the dialog box we saw in the introduction.

InputBox "Please enter the documents title","Enter Title", "Document 1"

However, we need to know what the user entered! The InputBox function returns a string, which is the text the user entered in the Input Box.

DocName As String
DocName = InputBox ("Please enter the documents title", _
                  "Enter Title", "Document 1")
Msgbox "The documents title is " & DocName

This displays an input box asking the user for a documents title. When the user clicks OK then a Message Box will be displayed showing the text the user entered. You will notice that if you press cancel, the message box is still displayed. When the cancel button is pressed, the InputBox returns an empty string. You can edit the code so the message box is not displayed if the user presses cancel, or does not type anything:

DocName As String
DocName = InputBox ("Please enter the documents title", _
                  "Enter Title", "Document 1")
' If DocName is not empty, display the message box
If Not DocName = "" Then Msgbox "The documents title is " & DocName

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • can i custumise the input dialog box?

    Posted by smp on 22 Mar 2004

    Hi
    I want to reduce the width of text box on InputBox & to change the location of the Buttons & textbox,
    is it possible?

    Regards
    Mahesh

  • Posted by becman on 25 Dec 2003

    what i want is a login form, but i cant get it to keep focus like when you have a messagebox or inputbox open you cant click the main form, how do i do that??:confused:

  • Posted by HyperHacker on 28 Jul 2003

    Suppose they just don't put anything in the box and click OK?

  • Posted by HyperHacker on 28 Jul 2003

    Unfortunately the input box isn't all the flexible. (You can't even hide the Cancel button.) You should use a custom form, it looks neater for getting 2 pieces of info anyway. :D

  • Input Box tp collect password field

    Posted by tirthankar.biswas on 25 Jun 2003

    :confused: Can u use Input Box to also collect password (ie starred input) also.
    I have a requirement whereby the program has to wait for input of userid and password . Input box works fine but I am...