Sams Teach Yourself Visual Basic 6 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Introduction
- Who Should Read This Book
- What This Book Will Do for You
- Can This Book Really Teach Visual Basic in 24 Hours?
- What You Need
- Files on the Visual Basic Distribution CD-ROM
- Conventions Used in This Book
- Enough! Time Is Ticking!
- Part I: Introducing Visual Basic
- Hour 1. Visual Basic at Work
- Hour 2.Analyzing Visual Basic Programs
- Hour 3.Controls and Properties
- Hour 4.Examining Labels, Buttons, and Text Boxes
- Part II: Coding the Details
- Hour 5.Putting Code into Visual Basic
- Hour 6.Message and Input Boxes
- Hour 7.Making Decisions
- Hour 8.Visual Basic Looping
- Part III:Putting Code to Work
- Hour 9.Combining Code and Controls
- Hour 10.List Boxes and Data Lists
- Hour 11.Additional Controls
- Hour 12.Dialog Box Basics
- Part IV:Programming with Data
- Hour 13.Modular Programming
- Hour 14.Built-In Functions Save Time
- Hour 15.Visual Basic Database Basics
- Hour 16.Printing with Visual Basic
- Part V:Sprucing Up Programs
- Hour 17.Menus and Visual Basic
- Hour 18.The Graphic Image Controls
- Hour 19.Toolbars and More Graphics
- Hour 20.Writing Correct Applications
- Part VI:Advancing Visual Basic Applications
- Hour 21.Visual Basic and ActiveX
- Hour 22.Object Basics
- Hour 23.Distributing Your Applications
- Hour 24.Online Visual Basic
- Part VII:Appendixes
- Appendix A.Operator Precedence
- Appendix B.Answers
- Appendix C.Using the CD-ROM
Examining InputBox()
You'll find that the InputBox() function is easy because it acts much like the MsgBox() function. The InputBox() function receives answers that are more complete than the MsgBox() function can get. Whereas MsgBox() returns one of seven values that indicate the user's command button press, the InputBox() function returns a string data value that holds the answer typed by the user.
Here is the format of the InputBox() function:
strVariable = InputBox( strPrompt [, [strTitle] [, strDefault] [, intXpos, intYpos]]])
strPrompt works a lot like the strmsg value in a MsgBox() function. The user sees strPrompt inside the input box displayed onscreen. strTitle is the title inside the input box's title bar. strDefault is a default string value that Visual Basic displays for a default answer, and the user can accept the default answer or change the default answer.
The intXpos and intYpos positions indicate the exact location where you want the input box to appear on the form. The intXpos value holds the number of twips from the left edge of the Form window to the left edge of the input box. The intYpos value holds the number of twips from the top edge of the Form window to the top edge of the input box. If you omit the intXpos and intYpos values, Visual Basic centers the message box on the form.
The following statement displays an input box that asks the user for a company name. The user either enters a response to the prompt or clicks the Cancel command button to indicate that no answer is coming:
strCompName = InputBox("What is the name of the company?", "Company Request", "XYZ, Inc.")
Figure 6.7 contains the message box displayed from this InputBox() function.
Figure 6.7 The InputBox() function is used to ask a question from the user.
Summary | Next Section

Account Sign In
View your cart