How to use Replace function in VBScript

限于喜欢 提交于 2020-01-30 07:44:07

问题


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:


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","")


来源:https://stackoverflow.com/questions/42775373/how-to-use-replace-function-in-vbscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!