【问题标题】:How to add the input from InputBox into MsgBox如何将 InputBox 的输入添加到 MsgBox
【发布时间】:2018-01-26 19:32:58
【问题描述】:

我想将输入的文本从 MsgBox 添加到 Msgbox 我得到了这个,但它不起作用。谁能帮帮我?

Dim x
x = MsgBox("Welcome to this software. Are you new with this?", vbYesNo + 
vbQuestion, "Welcome!")
Dim f
f = strMessage =Inputbox("First enter your name","The software")
Dim z
z = MsgBox(Welcome strMessage!)

【问题讨论】:

  • z = MsgBox("Welcome " & strMessage & "!")

标签: windows vbscript inputbox msgbox


【解决方案1】:

这里有几个问题。我会一一介绍。

f = strMessage = InputBox("First enter your name","The software")

我假设您正在尝试将用户输入到InputBox 的值存储到某个变量中——fstrMessage,或者两者兼而有之。 VBScript 不允许以您编写的方式进行多次赋值。相反,VBScript 正在测试存储在strMessage(您尚未声明或初始化)中的值是否等于用户输入的值。该测试的值(可能为 True 或 False)然后存储在 f 中。

如果您尝试将用户的输入仅存储在 f 中,这将起作用:

f = InputBox("First enter your name","The software")

如果你想将它存储在fstrMessage 中,你需要两个赋值语句:

Dim strMessage
f = InputBox("First enter your name","The software")
strMessage = f

接下来,这些行有几个问题:

Dim z
z = MsgBox(Welcome strMessage!)

首先,只有一个参数的MsgBox 将始终返回 1,因此使用变量 z 并没有真正的用处。

接下来,您没有在MsgBox 的第一个参数周围加上引号。结果,Welcome strMessage! 混淆了解释器,并引发错误。如果您改为添加引号 "Welcome strMessage!",则会解决该错误。

不过,我希望您希望将用户的输入显示给他们。在这种情况下,您不能只将变量放在引号内——您需要使用& 将其连接起来。因此,您应该:

MsgBox("Welcome, " & f & "!")

最后,重要的一点是,您拥有的变量名称(xfstrMessagez)并不是特别具有描述性。考虑一些有用的名称,例如isUserNewuserName。通过这些更改,您可以:

Dim isUserNew
Dim userName

isUserNew = MsgBox("Welcome to this software. Are you new with this?", vbYesNo, "Welcome!")
userName = Inputbox("First enter your name","The software")
MsgBox("Welcome, " & userName & "!")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-15
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    相关资源
    最近更新 更多