VB Replace function Error

R

Richard Gutery

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
 
M

McKirahan

Richard Gutery said:
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

You can't start at -1.

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

Richard Gutery

Not according to these links:
http://host16.webserver1010.com:5100/caspdoc/html/vbscript_replace_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 said:
Richard Gutery said:
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

You can't start at -1.

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

Bob Barrows [MVP]

Richard said:
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() 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/archive/2003/09/15/52996.aspx


Bob Barrows
 
R

Richard Gutery

My bad. I didn't paste the assignment portion. The actual code is:

httpPath = replace strRootDir, "\", "/", -1)

In any case, I still get the same error, even after retyping the entire
line.

???
Rg
 
B

Bob Barrows [MVP]

Richard said:
My bad. I didn't paste the assignment portion. The actual code is:

httpPath = replace strRootDir, "\", "/", -1)

Well, in this case, you left out the opening parenthesis. It should be:
httpPath = replace(strRootDir, "\", "/", -1)

Bob BArrows
 
R

Rob Meade

...
My bad. I didn't paste the assignment portion. The actual code is:

httpPath = replace strRootDir, "\", "/", -1)

In any case, I still get the same error, even after retyping the entire
line.

Hi Richard,

It's your START value that is the problem:

Syntax
Replace(string,find,replacewith[,start[,count[,compare]]])

Parameter Description
string Required. The string to be searched
find Required. The part of the string that will be replaced
replacewith Required. The replacement substring
start Optional. Specifies the start position. Default is 1
count Optional. Specifies the number of substitutions to perform.
Default value is -1, which means make all possible substitutions
compare Optional. Specifies the string comparison to use. Default is 0
Can have one of the following values:

a.. 0 = vbBinaryCompare - Perform a binary comparison
b.. 1 = vbTextCompare - Perform a textual comparison



Example:

<%
strRootDir = "C:\Files Hidden From The Wife\pr0n"

strHttpPath = Replace(strRootDir, "\", "/", 1)

Response.Write "strRootDir = " & strRootDir
Response.Write "<br>"
Response.Write "httpPath = " & strHttpPath
%>

Returns:

strRootDir = C:\Files Hidden From The Wife\pr0n
httpPath = C:/Files Hidden From The Wife/pr0n

You can get exactly the same result by dropping the START altogether:

<%
strRootDir = "C:\Files Hidden From The Wife\pr0n"

strHttpPath = Replace(strRootDir, "\", "/")

Response.Write "strRootDir = " & strRootDir
Response.Write "<br>"
Response.Write "httpPath = " & strHttpPath
%>

I think you might have misread your info and mixed the START parameter up
with the COUNT parameter, if you want to use COUNT you must specify the
START parameter first.

Regards

Rob
 
E

Evertjan.

Richard Gutery wrote on 19 jan 2005 in
microsoft.public.inetserver.asp.general:
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!

You win !

repace() can only exist with a result, not as a statement:

result = replace ("abcdea","a","Z")

this will fill the variable result with "ZbcdeZ"
 
R

Roland Hall

in message
: Not according to these links:
:
http://host16.webserver1010.com:5100/caspdoc/html/vbscript_replace_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???

That!

Yes, -1 can be used for count but your -1 is in the start field.

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

And, count is optional and only needed if you want less than all.

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

but this is all you need if you want them all and if you want to start at
the beginning.

httpPath = replace(strRootDir, "\", "/")

In the syntactical expression [ and ] signify optional.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
R

Richard Gutery

Thanks to all. Problem fixed.

RG

Evertjan. said:
Richard Gutery wrote on 19 jan 2005 in
microsoft.public.inetserver.asp.general:


You win !

repace() can only exist with a result, not as a statement:

result = replace ("abcdea","a","Z")

this will fill the variable result with "ZbcdeZ"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top