Page 1 of 1

Understanding Input Boxes Rate Topic: -----

#1 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Post icon  Posted 10 May 2009 - 01:53 AM

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.
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.
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 - 06:49 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1