473,385 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

VB Replace function Error

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
Jul 22 '05 #1
9 7885
"Richard Gutery" <rg*****@mentorits.com> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
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]]])
Jul 22 '05 #2
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> wrote in message
news:ej**************@TK2MSFTNGP09.phx.gbl...
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]]])

Jul 22 '05 #3
Richard Gutery wrote:
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/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.
Jul 22 '05 #4
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
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:ef**************@TK2MSFTNGP09.phx.gbl...
Richard Gutery wrote:
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/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.

Jul 22 '05 #5
Richard Gutery wrote:
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
--
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.
Jul 22 '05 #6
"Richard Gutery" wrote ...
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
Jul 22 '05 #7
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"

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #8
"Richard Gutery" wrote in message
news:Om**************@TK2MSFTNGP10.phx.gbl...
: 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???

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

Jul 22 '05 #9
Thanks to all. Problem fixed.

RG

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn*******************@194.109.133.29...
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"

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so...
5
by: adrian zaharia | last post by:
Hello, Is it possible to use Replace function in a query against an excel file? I am trying this test code and gives me an error: Set cnnExcel = Server.CreateObject("ADODB.Connection")...
6
by: Séverine Donnay | last post by:
Hello, I try to use the replace function with a very long text and I have this error : error '80020009' Exception occurred. Do you have any idee to resolve this problem ? Thanks
9
by: Not Me | last post by:
Hi, I'm having bother with the replace function in access 2002, a while back I remember not being able to get it to work... then suddenly the next time I tried it did work. Now it doesn't...
3
by: asd987 | last post by:
Hi, Can anyone tell me if "replace" is supported by Access 97? I use the Dutch version and get the errormessage "sub or function not supported". Or is the Professional Edition needed? Thanks.
5
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char*...
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
16
by: BBM | last post by:
This is so bizarre I hesitate to post it, but I need to get this working. My code looks like this... Private Const cmdTestResourcesSel = "SELECT * FROM TResources" & _ " WHERE Scenario =...
1
by: JAG | last post by:
I am getting an error using the replace method in one of my functions. I am using the replace method in the mail document function in my frameset .hta to change forward slashes to back slashes in...
1
by: neovantage | last post by:
Hey all, I am using a PHP script which creates headings at run time in a sense at page execution. I am stuck a with a very little problem which i am sure i will have the solution from experts. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.