School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,152 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,689 people online right now. Registration is fast and FREE... Join Now!




Understanding Input Boxes

 
Reply to this topicStart new topic

> Understanding Input Boxes

firebolt
Group Icon



post 10 May, 2009 - 12:53 AM
Post #1


An input box displays a prompt in a dialog box and asks the user to input text and returns a string with the contents of the text box. The syntax for an input box is setup like so:

stringvariable = InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context])

Each part of the function can be explained in detail. We say some string variable, which we have declared, is equal to the value of the text within the input box. But as you can see, the input box has many parts to it.

Prompt, which is required, is the text which is displayed to the user. Note, when typing in the code, we place a double quotation mark around the prompt.

Title, which is optional, is the string expression displayed in the title of the dialog box. Note, when typing in the code, we place a double quotation mark around the title.

Default, which is optional, is the string expression displayed in the text box as the default response if no other input is provided.

Xpos and Ypos are both optional, which are numeric expressions that specify custom positioning of the box on screen (the default is the center of the screen).

Helpfile and context are also both optional, which can be used if a help file has been set up for the application (note if one is used, the other must also be used).

If the user clicks OK, the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string ("").

To show the meaning of the input box in action, this example can be used.
vb

Dim name As String
name = InputBox("Enter your name:", "Example")


I have omitted the default, xpos, ypos, and the helpfile and context as these are not of beginner levels. Right now, this code displays an input box which asks the user, Enter your name, and also displays the heading Example.
To make this code applicable, we need to give an output function.

To test this code, we can add this piece of code. Create a command button called cmdExample and place the code in the form and start.
vb

Private Sub cmdExample_Click()
Dim name As String

name = InputBox("Enter your name:", "Example")
Print "Hello " & name & ". My name is Firebolt."

End Sub

Now the code outputs/prints the string, Hello name. My name is Firebolt, onto the form.
Thanks.

This post has been edited by firebolt: 14 May, 2009 - 05:49 AM
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 04:39PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month