syntax question

Results 1 to 3 of 3

Thread: syntax question

  1. #1
    Join Date
    Dec 1969

    Default syntax question

    Hi, I am relatively new to VBScript, and was hoping for some syntax clarification regarding built-in functions:<BR><BR>Response.write("hi") &#060;---- no error<BR>Response.write "hi" &#060;---- no error<BR><BR>Set oRS = oCon.Execute(sql,,1) &#060;---- no error<BR>oCon.Execute(sql,,1) &#060;---- ERROR<BR>oCon.Execute sql,,1 &#060;---- no error<BR><BR>How do I know when parenthesis are required? In some instances (with response.write) they are optional, and other times their use causes a syntax error.<BR><BR>Thank you,<BR>John

  2. #2
    Skippie Guest

    Default RE: syntax question

    If the function has more than one argument, then parenthesis<BR>cannot be used unless it&#039s returning a value.<BR><BR><BR>whatever(x) --&#062; no error<BR><BR>whatever(a,b,c) --&#062; error<BR><BR>x = whatever(a,b,c) --&#062; no error<BR><BR><BR>If you really want to use parenthesis, then have your <BR>function return True and set a dummy variable to it.<BR><BR><BR>-- Skippie<BR><BR>

  3. #3
    Join Date
    Dec 1969

    Default The finer points

    &nbsp;<BR>Just to make it more interesting...<BR><BR>Did you know that you can *NOT* use parentheses around your argument even with Response.Write?<BR><BR>"Liar, " you say, "Look here."<BR><BR>Response.write("hi") &#060;---- no error<BR><BR>Ah, but it&#039s a trick!<BR><BR>The rule is NO PARENS AROUND ARGS WHEN CALLING A SUB. And Response.Write is a Sub. <BR><BR>So why doesn&#039t it give an error?<BR><BR>Simple...Look at the definition of "expression" for the language:<BR><BR>expr := ( expr )<BR>expr := expr op expr<BR>expr := unaryop expr <BR>... etc. ...<BR><BR>The important point is the first line there: You an always enclose an expression in parents. And you often need to, for clarity:<BR><BR>3 * ( 4 + 7 ) gives 33<BR><BR>if you left out the parens<BR><BR>3 * 4 + 7 gives 19<BR><BR>So when you do<BR><BR>Response.Write (expr)<BR><BR>The VBS parser sees the parens as belong to the *expression*, not as belonging to the Sub!!<BR><BR>So the fact that it *looks* like you can use parens with a one-argument sub is, in fact, an illusion.<BR><BR><BR><BR>

Posting Permissions

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