VB Replace function Error

Discussion in 'ASP General' started by Richard Gutery, Jan 19, 2005.

  1. 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, Jan 19, 2005
    #1
    1. Advertising

  2. Richard Gutery

    McKirahan Guest

    "Richard Gutery" <> wrote in message
    news:ejmBCal$...
    > 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]]])
     
    McKirahan, Jan 19, 2005
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > "Richard Gutery" <> wrote in message
    > news:ejmBCal$...
    >> 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]]])
    >
    >
     
    Richard Gutery, Jan 19, 2005
    #3
  4. 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/archive/2003/09/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.
     
    Bob Barrows [MVP], Jan 19, 2005
    #4
  5. 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]" <> wrote in message
    news:efsO6nl$...
    > 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/archive/2003/09/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.
    >
    >
     
    Richard Gutery, Jan 19, 2005
    #5
  6. 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.
     
    Bob Barrows [MVP], Jan 19, 2005
    #6
  7. Richard Gutery

    Rob Meade Guest

    "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
     
    Rob Meade, Jan 19, 2005
    #7
  8. Richard Gutery

    Evertjan. Guest

    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)
     
    Evertjan., Jan 19, 2005
    #8
  9. Richard Gutery

    Roland Hall Guest

    "Richard Gutery" wrote in message
    news:Omh9mml$...
    : 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
     
    Roland Hall, Jan 20, 2005
    #9
  10. Thanks to all. Problem fixed.

    RG

    "Evertjan." <> 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)
    >
     
    Richard Gutery, Jan 20, 2005
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Blais
    Replies:
    1
    Views:
    406
    Bruno Desthuilliers
    Jun 27, 2006
  2. Greg Ewing
    Replies:
    2
    Views:
    372
    Dieter Maurer
    Jun 29, 2006
  3. Alun
    Replies:
    3
    Views:
    4,649
    Masudur
    Feb 18, 2008
  4. Prasad S
    Replies:
    2
    Views:
    256
    Dr John Stockton
    Aug 27, 2004
  5. V S Rawat
    Replies:
    5
    Views:
    345
    Richard Cornford
    Jul 3, 2007
Loading...

Share This Page