Results 1 to 9 of 9

Thread: (Parentheses) v. No Parentheses

  1. #1
    idover
    Guest

    (Parentheses) v. No Parentheses

    well... i've run into another curiousioty with asp... for some unknown reason, i used parentheses around an argument with a redirect as such:

    Code:
    Response.Redirect("index.asp")
    This works fine ( as far as i can tell ), but it leaves the name of the page that calls it in the address bar, which happens to be called 'scripts.asp'... this troubled me... so i removed the parentheses:

    Code:
    Response.Redirect "index.asp"
    and 'index.asp' appears in the address bar... i have no clue why this is so... but would like to know why... any ideas?...

    because i always use vbscript when writing asp code, i never define the script language, maybe the asp engine sees the parentheses and determines that it's jscript, and possibly gets confused?...

    thanks in advance!

  2. #2
    Addicted Member csammis's Avatar
    Join Date
    Mar 2001
    Location
    /dev/null
    Posts
    226
    That could be. It could also be just a little quirk in VBScript/your browser/whatever...M$ is known for making little quirks without meaning to...they call their latest one Windows XP
    Things I've Said:
    "Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
    "Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
    "You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"

  3. #3
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    Placing an argument in () tells VB to evaluate the expression, and pass the result rather than the original expression. Any changes made to the passed argument will not change the orignal argument, unless of course it is an object. Why use them? I don't know. Why did you get "scripts.Asp". Beats me.
    It is not documented for VBScript but in regular VB is this.
    "Passing Arguments By Reference
    Passing arguments by reference gives the procedure access to the actual variable contents in its memory address location. As a result, the variable's value can be permanently changed by the procedure to which it is passed. Passing by reference is the default in Visual Basic.

    If you specify a data type for an argument passed by reference, you must pass a value of that type for the argument. You can work around this by passing an expression, rather than a data type, for an argument. Visual Basic evaluates an expression and passes it as the required type if it can.

    The simplest way to turn a variable into an expression is to enclose it in parentheses. For example, to pass a variable declared as an integer to a procedure expecting a string as an argument, you would do the following:

    Sub CallingProcedure()
    Dim intX As Integer
    intX = 12 * 3
    Foo(intX)
    End Sub

    Sub Foo(Bar As String)
    MsgBox Bar 'The value of Bar is the string "36".
    End Sub

    "

  4. #4
    Addicted Member csammis's Avatar
    Join Date
    Mar 2001
    Location
    /dev/null
    Posts
    226
    That's very true, but the opposite appears to be happening with idover's VBScript example. With parenthesis, no value is "returned" (the address bar is not updated), and without parenthesis, there is a "return" (the address bar is updated). Like I said, quirk between languages
    Things I've Said:
    "Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
    "Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
    "You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"

  5. #5
    idover
    Guest
    this makes a little sense... i guess it can be compared to using the execute method of a connection object...

    when populating a recordset using the execute method, you have to use the parentheses to have any values returned:
    Code:
    Set objRecordset = Server.Execute("select * from table1")
    but when no value needs to be returned, you would use without parentheses:

    Code:
    objConnection.Execute "drop table table1"
    so the response.redirect evaluates the code, which returns the value of the page 'index.asp'... this makes sense, but what is still confusing is why the address bar continues to show the url of the page that executed the response.redirect...

  6. #6
    Addicted Member csammis's Avatar
    Join Date
    Mar 2001
    Location
    /dev/null
    Posts
    226
    Like I said...bug/quirk
    Things I've Said:
    "Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
    "Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
    "You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"

  7. #7
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    CSSAMIS,
    A value WAS returned because he said the Redirect worked. There is still the "quirk" of the address bar.

  8. #8
    idover
    Guest

    Wink

    maybe someone should send an exterminator to microsoft... i believe that i recall that the same exact thing happened with server.transfer and server.execute... if it is a bug, it seems to be mighty consistent...

    by the way john, great forum design at vbgarage!... the only problem i discovered was the upper navigation wouldn't work with my nutscrape 4.7... but was beautiful in ie 5!... feel free to send the code my way

  9. #9
    Hyperactive Member
    Join Date
    Apr 2001
    Posts
    315
    GOT IT I think. Off the wall.

    Redirect will accept a Variant string OR a string but the Address bar wants a variant and just rejects it.
    Try
    RESPONSE.REDIRECT Cstr("index.asp")
    I think the parens caused a "real" string to be returned that the C++ code of Redirect could handle but went down as garbage to the IE address bar.

    I ran into something like this Variant 5hing with VB.

    Webb.navigate "WWW.VBCOMPARE.COM" 'Works

    Dim strURL as string
    strUrl = "WWW.VBCOMPARE.COM"
    Webb.Navigate strUrl ' Does not work. Wants Variant String

    Dim varURL as Variant
    varUrl = "WWW.VBCOMPARE.COM"
    Webb.Navigate varUrl ' Works

    WWW.VBCompare.COM is done in Front Page entirely.
    I did not know that Netscape had a problem. I will look into it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width