4

I don't know why this code doesn't work:

Dim a
a = InputBox("What time do you want?")
If InStr(a, "pm") Then
  (Replace(a, "pm", ""))
  a = a + 12
  c = MsgBox(a, 0, Time)
  WScript.Quit
Else
End If
b = MsgBox(a & form, 0, "L")

Whenever I try to start it, it responds with:

"Error: Expected Statement"

Is it because the Replace statement isn't right or because there's a mistake in the rest of the script?

2
  • To fix the error fix line 4 - a = Replace(a, "pm","") which is the cause of the error. Replace() has to return something, (Replace(a, "pm","")) is not a valid statement without a return value. Commented Mar 14, 2017 at 0:29
  • @JosephSanders I wasn't being condescending, you didn't mention you had attempted to use Replace() or show any code, how was I supposed to know? Plus Stack Overflow is about creating a canonical library of questions and answers not answering the same question in various ways over and over. Hopefully, the answer here will help understand how to use the Replace() function. Also, why leave you're comment here when you could have left it on the question you're referring to? Commented Feb 28 at 14:33

1 Answer 1

10

When you try to run that code you should get the following error

Microsoft VBScript compilation error: Expected statement
Line 4

which will lead you to the culprit which is

(Replace(a, "pm",""))

which isn't a valid statement in VBScript hence the error.

Based on what you are trying to do the script needs to return the result of the Replace() function call, something like this

a = Replace(a, "pm","")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.