Tuesday, November 22, 2011

InputBox Function VB Script

InputBox Function
Description
The InputBox function displays a dialog box containing a label, which prompts the user about the data you expect them to input, a text box for entering the data, an OK button, a Cancel button, and optionally, a Help button. When the user clicks OK, the function returns the contents of the text box

Syntax
InputBox(prompt,title,default,xpos, ypos, helpfile, context)
Arguments
Constant  Description
prompt The message in the dialog box.
title  The title-bar of the dialog box.
default  String to be displayed in the text box on loading.
xpos  The distance from the left side of the screen to the left side of the dialog.
ypos  The distance from the top of the screen to the top of the dialog box.
helpfile  The Help file to use if the user clicks the Help button on the dialog box.
context  The context number to use within the Help file specified in helpfile.

Notes
1.  InputBox returns a string containing the contents of the text box from the
Input-box dialog.
2.  If the user clicks Cancel, a zero-length string (" ") is returned.
3.  prompt can contain approximately 1,000 characters, including nonprinting
characters like the intrinsic vbCrLf constant. 
4.  If you don't use the default parameter to specify a default entry for the text
box, the text box is shown empty; a zero-length string is returned if the
user doesn't enter anything in the text box prior to clicking OK. 
5.  xpos and ypos are specified in twips. A twip is a device-independent unit of
measurement that equals 1/20 of a point or 1/1440 of an inch. 
6.  If the xpos parameter is omitted, the dialog box is centered horizontally. 
7.  If the ypos parameter is omitted, the top of the dialog box is positioned
approximately one-third of the way down the screen. 
8.  If the helpfile parameter is provided, the context parameter must also be
provided, and vice versa. 
9.  In VBScript, when both helpfile and context are passed to the InputBox
function, a Help button is automatically placed on the InputBox dialog,
allowing the user to click and obtain context-sensitive help.

sString = InputBox("Enter it now", , "Something", ,  , "help.hlp", 321321)

Example
The following example uses the InputBox function to display an input box and
assign the string to the variable Input:

Option Explicit
Dim sPrompt, sTitle, sHelpFile, sRes
Dim vDef
Dim nYPos, nXPos, nContext
sPrompt = "Where do you live?" : sTitle = "Personal Data"
vDef = "Israel"
nXPos = 100 : nYPos = 100 : nContext = 1001
sHelpFile = "C:\WINDOWS\system32\winhelp.hlp"
sRes = InputBox(sPrompt, sTitle, vDef, nXPos, nYPos, sHelpFile, nContext)

No comments:

Post a Comment