如何在VBScript中使用Replace函数 [英] How to use Replace function in VBScript

查看:31
本文介绍了如何在VBScript中使用Replace函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么这段代码不起作用:

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:

错误:预期语句"

是因为 Replace 语句不正确还是因为脚本的其余部分有错误?

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

推荐答案

当您尝试运行该代码时,您应该收到以下错误

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

Microsoft VBScript 编译错误:预期语句
第 4 行

Microsoft VBScript compilation error: Expected statement
Line 4

这将导致您找到罪魁祸首

which will lead you to the culprit which is

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

这不是 VBScript 中的有效语句,因此是错误.

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

根据您尝试执行的操作,脚本需要返回 Replace() 函数调用的结果,类似这样

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

这篇关于如何在VBScript中使用Replace函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆