VB替换功能错误 [英] VB Replace function Error

查看:114
本文介绍了VB替换功能错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP页面中有这段代码:replace(strRootDir," \"," /", - )


当我运行时脚本我得到:

Microsoft VBScript编译(0x800A0414)

调用Sub时不能使用括号


II删除括号然后我得到:

Microsoft VBScript编译(0x800A0401)

预期声明结束


我在网上找到的内容(和在Studio帮助中)表示

" REPLACE(String,ToFind,With,Count)"是对的。


我做错了什么???


我打赌我有点蠢!


RG

I have this piece of code in an ASP page: replace (strRootDir, "\", "/", -1)

When I run the script I get:
Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub

II remove the parenthese then I get:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement

Everthing that I found on the web (and in Studio help) indicates that
"REPLACE (String, ToFind, With, Count)" is correct.

What am I doing wrong???

Something stupid I bet!

RG

推荐答案

" Richard Gutery" < RG ***** @ mentorits.com>在留言中写道

新闻:ej ************** @ TK2MSFTNGP09.phx.gbl ...
"Richard Gutery" <rg*****@mentorits.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
我有这块ASP页面中的代码:replace(strRootDir," \",
" /", - 1)
当我运行脚本时,我得到:
Microsoft VBScript编译( 0x800A0414)
在调用Sub时不能使用括号

II删除括号然后我得到:
Microsoft VBScript编译(0x800A0401)
预期结束语句

我在网上(以及在Studio帮助中)发现的内容表示
REPLACE(String,ToFind,With,Count)"是对的。

我做错了什么???

我敢打赌这个蠢事吧!

RG
I have this piece of code in an ASP page: replace (strRootDir, "\", "/", -1)
When I run the script I get:
Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub

II remove the parenthese then I get:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement

Everthing that I found on the web (and in Studio help) indicates that
"REPLACE (String, ToFind, With, Count)" is correct.

What am I doing wrong???

Something stupid I bet!

RG




你不能从-1开始。


替换(表达式,查找,替换为[,start [,count [,compare]]])



You can''t start at -1.

Replace(expression, find, replacewith[, start[, count[, compare]]])


不是根据这些链接:
http://host16.webserver1010.com:5100...e_function.htm

http://asp.nfrance.com/docs/Ch08-VBScript-113.htm


VS在线帮助中也有详细说明(搜索REPLACE FUNCTIO)。 COUNT

指定数字或替换,-1表示所有出现。


话虽如此,还有什么可能是错的???

" McKirahan" <氖** @ McKirahan.com>在消息中写道

news:k6 ******************** @ comcast.com ...
Not according to these links:
http://host16.webserver1010.com:5100...e_function.htm

http://asp.nfrance.com/docs/Ch08-VBScript-113.htm

Which is also detailed in VS Online help (search for REPLACE FUNCTIO). COUNT
specifies the number or replacements, with -1 meaning ALL occurrances.

Having said that, what else could be wrong???
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:k6********************@comcast.com...
" ; Richard Gutery < RG ***** @ mentorits.com>在消息中写道
新闻:ej ************** @ TK2MSFTNGP09.phx.gbl ...
"Richard Gutery" <rg*****@mentorits.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
我在ASP中有这段代码page:replace(strRootDir," \",
I have this piece of code in an ASP page: replace (strRootDir, "\",


" /", - 1)


"/", -1)


当我运行脚本时,我得到:
Microsoft VBScript编译(0x800A0414)
调用Sub时不能使用括号

II删除括号然后我得到:
Microsoft VBScript编译(0x800A0401)预期的结束声明

我在网上(以及在Studio帮助中)发现的内容表明
REPLACE(String,ToFind,With,Count)"是对的。

我做错了什么???

我敢打赌这个蠢事吧!

RG

When I run the script I get:
Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub

II remove the parenthese then I get:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement

Everthing that I found on the web (and in Studio help) indicates that
"REPLACE (String, ToFind, With, Count)" is correct.

What am I doing wrong???

Something stupid I bet!

RG


<你不能从-1开始。

替换(表达,查找,替换[,start [,count [,compare]]])



You can''t start at -1.

Replace(expression, find, replacewith[, start[, count[, compare]]])



Richard Gutery写道:
Richard Gutery wrote:
我在ASP页面中有这段代码:replace(strRootDir," \",
" /", - 1)

当我运行脚本时,我得到:
Microsoft VBScript编译(0x800A0414)
调用Sub时不能使用括号

我删除了括号然后我得到:
Microsoft VBScript编译(0x800A0401)
预期声明结束

我在网上找到的翻译(以及Studio帮助)表示
REPLACE(String,ToFind,With,Count)"是对的。

我做错了什么???

我敢打赌这个蠢事吧!

RG
I have this piece of code in an ASP page: replace (strRootDir, "\",
"/", -1)

When I run the script I get:
Microsoft VBScript compilation (0x800A0414)
Cannot use parentheses when calling a Sub

II remove the parenthese then I get:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement

Everthing that I found on the web (and in Studio help) indicates that
"REPLACE (String, ToFind, With, Count)" is correct.

What am I doing wrong???

Something stupid I bet!

RG




Replace()是一个返回值的函数。它返回的值是替换操作产生的

字符串。你正在调用它,好像它是一个Sub,即一个运行并执行它的程序而没有返回

值的程序。要使用多个参数调用Sub,或者调用函数,就好像它是一个Sub,你不能在参数列表周围使用括号(除非你使用
正在使用Call语句。


使用Replace的正确方法是:

strRootDir = replace(strRootDir," \"," /" ;,-1)


见?你将函数返回的值赋给你的变量。


如果你感兴趣的话,还有以下内容:
http://blogs.msdn.com/ericlippert/ar ... / 15/52996。 aspx

Bob Barrows


-

Microsoft MVP - ASP / ASP.NET

请回复新闻组。我的From

标题中列出的电子邮件帐户是我的垃圾邮件陷阱,因此我不经常检查它。通过发布到新闻组,您将获得更快的回复。



Replace() is a function that returns a value. The value it returns is the
string that results from the replace operation. You are calling it as if it
was a Sub, i.e. a procedure that runs and does its thing without returning a
value. To call a Sub with multiple arguments, or to call a function as if it
was a Sub, you must not use parentheses around the argument list (unless you
are using the Call statement).

The correct way to use Replace is:
strRootDir=replace (strRootDir, "\", "/", -1)

See? You assign the value returned from the function to your variable.

Here''s more in case you are interested:
http://blogs.msdn.com/ericlippert/ar.../15/52996.aspx
Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don''t check it very often. You will get a
quicker response by posting to the newsgroup.


这篇关于VB替换功能错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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