Latest web development tutorials

VBScript InputBox function

VBScript Reference Complete VBScript Reference

InputBox function displays a dialog box where the user can enter text and / or click on a button. If the user clicks click the OK button or press the ENTER key on the keyboard, the InputBox function returns the text in the textbox. If the user clicks the Cancel button, the function returns an empty string ( "").

Note: If you specified helpfile and context parameters, it will add a Help button to the dialog box.

Tip: See the MsgBox function.

grammar

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

参数 描述
prompt 必需。显示在对话框中的消息。prompt 的最大长度大约是 1024 个字符,这取决于所使用的字符的宽度。如果 prompt 中包含多个行,则可在各行之间用回车符(Chr(13))、换行符(Chr(10))或回车换行符的组合(Chr(13) & Chr(10))来分隔各行。
title 可选。对话框的标题。默认是应用程序的名称。
default 可选。一个在文本框中的默认文本。
xpos 可选。数值表达式,用于指定对话框的左边缘与屏幕左边缘的水平距离(单位为 twips*)。如果省略 xpos,则对话框会在水平方向居中。
ypos 可选。数值表达式,用于指定对话框的上边缘与屏幕上边缘的垂直距离(单位为 twips*)。如果省略 ypos,则对话框显示在屏幕垂直方向距下边缘大约三分之一处。
helpfile 可选。字符串表达式,用于标识为对话框提供上下文相关帮助的帮助文件。必须与 context 参数一起使用。
context 可选。数值表达式,用于标识由帮助文件的作者指定给某个帮助主题的上下文编号。必须与 helpfile 参数一起使用。

* Twip unit of measure is the same as in the visual display of the system.
1 twip of 1/1440 inch.

Examples

Example 1

<script type="text/vbscript">

Function myFunction()
fname=InputBox("Enter your name")
End Function

</script>

try it"

Example 2

The prompt box with the title:

<script type="text/vbscript">

Function myFunction()
fname=InputBox("Enter your name","Userinput")
End Function

</script>

try it"

Example 3

The default prompt box with input box text:

<script type="text/vbscript">

Function myFunction()
fname=InputBox("Enter your name",,"Donald Duck")
End Function

</script>

try it"

Example 4

700 twips * in a position from the left edge of the screen displays the prompt box.

<script type="text/vbscript">

Function myFunction()
fname=InputBox("Enter your name",,,700)
End Function

</script>

try it"

Example 5

Tip from a box on the edge of the screen 500 twips * position display.

<script type="text/vbscript">

Function myFunction()
fname=InputBox("Enter your name",,,,500)
End Function

</script>

try it"

VBScript Reference Complete VBScript Reference