Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > VB Replace function Error

Reply
Thread Tools

VB Replace function Error

 
 
Richard Gutery
Guest
Posts: n/a
 
      01-19-2005
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


 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      01-19-2005
"Richard Gutery" <(E-Mail Removed)> wrote in message
news:ejmBCal$(E-Mail Removed)...
> 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]]])


 
Reply With Quote
 
 
 
 
Richard Gutery
Guest
Posts: n/a
 
      01-19-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Richard Gutery" <(E-Mail Removed)> wrote in message
> news:ejmBCal$(E-Mail Removed)...
>> 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]]])
>
>



 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      01-19-2005
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.


 
Reply With Quote
 
Richard Gutery
Guest
Posts: n/a
 
      01-19-2005
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]" <(E-Mail Removed)> wrote in message
news:efsO6nl$(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      01-19-2005
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.


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      01-19-2005
"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


 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      01-19-2005
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)

 
Reply With Quote
 
Roland Hall
Guest
Posts: n/a
 
      01-20-2005
"Richard Gutery" wrote in message
news:Omh9mml$(E-Mail Removed)...
: 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



 
Reply With Quote
 
Richard Gutery
Guest
Posts: n/a
 
      01-20-2005
Thanks to all. Problem fixed.

RG

"Evertjan." <(E-Mail Removed)> wrote in message
news:Xns95E42DAF9A6Eeejj99@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)
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Replace /n with a XHTML <br /> using string.replace Alun ASP .Net 3 02-18-2008 05:52 AM
how to make replace function replace globally in a string V S Rawat Javascript 5 07-03-2007 08:02 PM
Re: [Pyrex] pyrex functions to replace a method (Re: replace a method Greg Ewing Python 2 06-29-2006 05:25 PM
pyrex functions to replace a method (Re: replace a method in class:how?) Brian Blais Python 1 06-27-2006 12:13 PM
help with string replace - for doing selective replace Prasad S Javascript 2 08-27-2004 03:22 PM



Advertisments