Using Input Boxes

You can use input boxes to gather single pieces of information from the user. By using an If structure linked to the value the input box returns, you can determine whether the user has entered valid information and direct program flow appropriately. The syntax for an input box is as follows:

InputBox(Prompt, Title, Default, XPos, YPos, Helpfile, HelpContext)

Prompt is a required string argument that specifies the text prompt to be displayed in the input box.

Title is an optional string argument that specifies the text for the title bar of the input box. As with MsgBox, if you don’t specify a Title argument, VBA will display “Visual Basic” in the title bar of the input box.

Default is an optional string argument that specifies the default text to display in the text box inside the input box. Often, you’ll want to omit the Default argument. At other times, you may want to use a Default argument to provide text likely to be suitable for the user (for example, the current user name in an input box asking for the user’s name) or text that may need adjustment.

XPos and YPos are measurements in twips (a twip is 1/1440") that specify the horizontal and vertical positioning of the input box onscreen. It’s usually best to omit these arguments and have VBA use the default positioning for the input box, which is centered horizontally and one-third of the way down the screen.

As for MsgBox, Helpfile, and Context are optional arguments specifying the Help file and topic to use. When you specify Helpfile and Context, VBA adds a Help button to the input box.

To display an input box and return the text string that the user enters, declare a variable for it and set the value of the variable to the result of the input box:

Dim strUserName as String strUserName = InputBox("Enter your name.", "User Name") 

You can then check the value of the variable (here, strUserName) to make sure that it is not an empty string (""), which will result if the user either clicks the Cancel button in the input box or clicks the OK button without entering any text in the text box. Figure 26.9 shows this input box.

click to expand
Figure 26.9: Use an input box to request a single piece of information.

start sidebar
More About Project Programming: Beyond VBA

VBA isn’t the only way to program Microsoft Project. For example, you can use Dynamic HTML (DHTML) to create custom Project Guides for your organization. You can also use Microsoft’s .NET Framework to develop XML web services that incorporate Project data and functionality.

If you’re interested in learning more about Project application development, Microsoft has many useful resources available online, including

  • Microsoft Developer’s Network (MSDN) at msdn.microsoft.com

  • Microsoft TechNet at www.microsoft.com/technet/

  • Microsoft Visual Basic for Applications home page at www.msdn.microsoft.com/vba/

end sidebar



Mastering Microsoft Project 2002
Mastering Microsoft Project 2002
ISBN: 0782141471
EAN: 2147483647
Year: 2006
Pages: 241

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net