How to use Replace function in VBScript

2020-04-11 11:09发布

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?

1条回答
等我变得足够好
2楼-- · 2020-04-11 11:47

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","")
查看更多
登录 后发表回答