1

I want to add the inputted text from an MsgBox into a Msgbox I got this but it don't work. Can anyone help me?

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!)

1 Answers1

0

There are a couple of issues with what you have here. I'll go through them one by one.

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

I assume you're trying to store the value the user entered into the InputBox into some variable--either f, or strMessage, or maybe both. VBScript does not allow multiple assignments in the way that you've written them. Instead, VBScript is testing whether the value stored in strMessage (which you haven't declared or initialized) is equal to the value the user entered. The value of that test (which will be either True or False) is then stored in f.

If you're trying to store the user's input in just f, this will work:

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

If you want to store it in both f and strMessage, you'll need two assignment statements:

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

Next, there are a couple issues with these lines:

Dim z
z = MsgBox(Welcome strMessage!)

First, MsgBox with only one argument will always return 1, so there's no real use in having variable z.

Next, you haven't put quotes around the first argument to MsgBox. As a result, Welcome strMessage! confuses the interpreter, and throws an error. If you instead add quotes, "Welcome strMessage!", that will resolve the error.

I expect, however, you want to display the user's input back to them. In that case, you can't just put the variable within the quotes--you need to concatenate it on, using &. Thus, you should come to:

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

Finally, an important note, the variable names you have (x, f, strMessage, and z) not particularly descriptive. Consider some helpful names, like isUserNew and userName. With those changes, you'd get to:

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 & "!")
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Guest5
  • 109
  • 2