上一期,我给大家讲了msgbox,这一期我们来研究获取输入的inputbox
相比于msgbox,inputbox要简单很多。
下面是基本格式:
inputbox 1,2,3
1
和msgbox一样,inputbox的第一个参数是将要询问的问题或者说输入值的意义,也就是一个字符串。
代码示例
Dim x
x=inputbox ("Are you reading my blog?Yes or No")
if x="Yes" then msgbox "Oh,thank you."
if x="No" then msgbox "You'd better read it."
效果如下:


2
和msgbox一样,第二个是标题,是一个字符串类型的参数。
Dim x
x=inputbox ("Are you reading my blog?Yes or No","blog helper")
if x="Yes" then msgbox "Oh,thank you."
if x="No" then msgbox "You'd better read it."
效果如下:

3
最后一个是自动填充要回答的问题,所以也是字符串类型
代码如下:
Dim x
x=inputbox ("Are you reading my blog?Yes or No","blog helper","Yes")
if x="Yes" then msgbox "Oh,thank you."
if x="No" then msgbox "You'd better read it."
实际效果:

END
彩蛋:
恶搞代码!
do
Set ws=WScript.CreateObject("wscript.shell")
ws.SendKeys "%{F4}"
loop
谨慎使用

本文详细介绍了VBScript中的InputBox函数,通过示例代码展示了如何使用该函数来获取用户输入,并讨论了其三个参数:问题提示、对话框标题和默认输入值。在文章末尾还提供了一个趣味性的恶搞代码示例。
&spm=1001.2101.3001.5002&articleId=104543011&d=1&t=3&u=233034eb5eda44529b21e431ce6ca682)
534

被折叠的 条评论
为什么被折叠?



