3. InputBox函数
弹出对话框,等待用户输入内容或点击按钮。返回值是输入的内容。
Ø 语法
InputBox(prompt[, title][, default][, xpos][, ypos][, helpfile, context])
Ø Arguments
prompt 将在对话框中显示的信息。最大长度为1024字符。如果内容有多行,可以用(Chr(13))来表示回车符,或用(Chr(10))表示换行符,或用(Chr(13) & Chr(10))表示回车-换行符。
title 弹出框的标题,将显示在标题栏。
default 输入框的默认值。
Ø 例
Dim Input
Input = InputBox("Enter your name")
MsgBox ("You entered: " & Input)
4. WshSell对象的Popup Method
在一个弹出框中显示文本信息。
Ø 语法
intButton = object.Popup(strText,[nSecondsToWait],[strTitle],[nType])
Ø Arguments
object WshShell对象.
strText 希望在弹出框中显示的文本信息。
nSecondsToWait 可选。希望弹出框保持显示的最长时间。(单位秒)。
strTitle 弹出框的标题
nType 一个数值,代表希望在弹出框中显示的按钮或图标。这个值决定了如何使用信息框。
IntButton 返回值。表示用户点击的按钮值。
Ø 注意
无论which host executable file is running (Wscrīpt.exe or Cscrīpt.exe),Popup method都会弹出信息框。
如果nSecondsToWaitis 为0,弹出框一直等到用户干预才关闭。如果nSecondsToWaitis 大于0,如果没有用户干预,则弹出框一直等到nSecondsToWaitis时间后自动关闭。
如果不设置“strtitle”,则弹出框的标题默认为"Windows scrīpt Host."。
“nType”的意思与MessageBox function的ntype相同。
按钮值
值 |
描述 |
0 |
显示OK按钮. |
1 |
显示OK及Cancel按钮。 |
2 |
显示Abort, Retry, 及Ignore按钮。 |
3 |
显示Yes, No, 及Cancel按钮。 |
4 |
显示Yes及 No按钮。 |
5 |
显示 Retry 及 Cancel按钮。 |
图标类型值
值 |
描述 |
16 |
显示"Stop Mark"图标。 |
32 |
显示 "Question Mark"图标。 |
48 |
显示 "Exclamation Mark"图标。 |
64 |
显示"Information Mark"图标。 |
返回值
如果用户没有在窗口等待的时间范围内(nSecondsToWait)点击按钮,则返回-1。
值 |
描述 |
1 |
OK按钮 |
2 |
Cancel 按钮 |
3 |
Abort 按钮 |
4 |
Retry 按钮 |
5 |
Ignore 按钮 |
6 |
Yes 按钮 |
7 |
No 按钮 |
Ø Example
[VBscrīpt]
Dim WshShell, BtnCode
Set WshShell = Wscrīpt.CreateObject("Wscrīpt.Shell")
BtnCode = WshShell.Popup("Do you feel alright?", 7, "Answer This Question:", 4 + 32)
Select Case BtnCode
case 6 Wscrīpt.Echo "Glad to hear you feel alright."
case 7 Wscrīpt.Echo "Hope you're feeling better soon."
case -1 Wscrīpt.Echo "Is there anybody out there?"
End Select