-4

I have an if statement containing a <table> with two rows, like so:

<%
    ...
    If Not Request("InsertPlacement") <> "" Then
%>

<table width="100%" border="0">
    <tr>
        <td>
            <!-- #include file="UserHeader.asp" -->
        </td>
    </tr>
    <tr>
        <td>
            ...
        </td>
    </tr>
</table>
<% End If %>

Now I have a whole bunch of compile errors saying things like "if must end with matching end if" (which it does) and "statement cannot appear outside of a method body" (huh? it's in a <%%> tag) and "declaration expected" (makes no sense at all).

If I delete both of the <tr> tags inside the <table>, or delete the whole <table>, the compile errors go away. However - if I delete one or the other <tr> tag, doesn't matter which, the errors do not go away. So which <tr> tag is causing the error? It's like the dual slit experiment - the error comes through either <tr> tag regardless of which I delete! What the heck could be going on here?!

user692942
  • 16,398
  • 7
  • 76
  • 175
ekolis
  • 6,270
  • 12
  • 50
  • 101
  • It’s called a Heisenbug: https://en.wikipedia.org/wiki/Heisenbug - whereas a “quantum” bug would be irreducible. – Dai Jan 08 '20 at 19:40
  • This is Classic ASP code, not ASP.NET. Please correct the title and tags of this question. – Dai Jan 08 '20 at 19:41
  • @Dai It's both. The page itself is ASP.NET, but the include file is classic ASP. (Apparently you can actually do that?) – ekolis Jan 08 '20 at 19:43
  • 1
    no, you can’t. That’s probably part of the problem. Also, your `If` statement has a double-negative. – Dai Jan 08 '20 at 19:44
  • Your HTML table markup won’t be involved even if this page is being run through ASP.NET or Classic ASP because neither attempt to parse HTML - they treat all runs of HTML as a giant string literal (except when ASP.NET encounters `runat=“server”`- or if you’re using Razor. – Dai Jan 08 '20 at 19:46
  • Oh, I didn't think that was the problem, because if I delete the first row, containing the include statement, the errors persist. As for the double negative, I would "fix" that but I'm hesitant to break some weird edge case since VB does all sorts of automatic type casting in the background... – ekolis Jan 08 '20 at 19:54
  • 1
    I think you should post the entire file rather than just a fragment of it - please post both the file in-question *and* the `UserHeader.asp` file. – Dai Jan 08 '20 at 20:10
  • `... since VB does all sorts of automatic type casting in the background`. One example? – djv Jan 08 '20 at 21:20
  • _since VB does all sorts of automatic type casting in the background_ is called LET Coercion. EG `msgbox 1 + 2` will print a string containing the character 3. The rules are specified in implementation detail here https://msdn.microsoft.com/en-us/library/dd361851.aspx and contractually in the help. The actual functions are in OLEAUT32.DLL. `Msgbox 2 / 1.5` will start with 2 as an integer, then it will be converted to a double, and devided by a double of 1.5. You could use strings instead of integers and doubles and the strings will be converted to doubles. –  Jan 09 '20 at 00:49
  • @Mark Classic ASP uses VBScript, not VB, VBA etc. Yes they are very similar but VBScript unlike it's cousins is Typeless, all data types are a subtype of `Variant`. – user692942 Jan 09 '20 at 00:56
  • I also can't think of a single language that doesn't auto coerce numbers to strings when you print them. –  Jan 09 '20 at 00:56
  • And each of those variants need to be coerced as well. A variant is not typeless (vbscript is) but contains the type. ` A = 3` and `A = "3"` the first gives you a variant with a type of integer (let coercion rules) the second as a string as vartype shows. –  Jan 09 '20 at 01:06
  • @Mark don't need a lesson in coerce, was referring more to this specifically related to VBScript - See [Integer and String comparison conflict in VBScript](https://stackoverflow.com/a/40466467/692942) – user692942 Jan 09 '20 at 01:24
  • If you want the include to be self-contained, you can run `Server.Execute("UserHeader.asp")` instead of using an `include` statement. Then there should be no risk of cross contamination. However, depending on your setup this may not be feasible. Despite being within an if-statement, the include will load, whether or not the if statement is true. – Daniel Nordh Jan 10 '20 at 14:52

1 Answers1

2

Your UserHeader.asp file will contain a mismatched or broken control-flow statement.

Server-side-includes are evaluated before the VBScript interpreter runs.

(Compared with PHP where require/include are evaluated when executed)

Dai
  • 141,631
  • 28
  • 261
  • 374
  • That can't be the problem, because if I delete the table row containing that include statement, the errors don't go away. – ekolis Jan 08 '20 at 19:54
  • Oh wait, I spoke too soon - if I delete the table row containing the include statement, *then* close and reopen the file, I get some more reasonable looking errors! – ekolis Jan 08 '20 at 20:10
  • 1
    I bet, if you remove the `If` block in your page but leave the include in tact it will work. Likelihood is you have a `Function` or `Sub` defined inside the include file which can't exist inside a control-flow statement like an `If`. Which makes the error pretty self explanatory. – user692942 Jan 09 '20 at 00:42
  • 1
    @Lankymart What amazes me the most is that someone is actually doing a Classic ASP project in 2020 - that's almost 18 years since it was officially replaced with ASP.NET WebForms (not that WebForms was an improvement either...) – Dai Jan 09 '20 at 00:47
  • 1
    @Dai can't say I'm a fan of WebForms but Classic ASP will always hold a special place in my heart. It's very easy to do wrong but also very robust when done right. Moved on to ASP.Net MVC now though and skipped WebForms altogether. – user692942 Jan 09 '20 at 00:50
  • 2
    @Lankymart You missed out on a lot :D https://stackoverflow.com/a/51391202/159145 – Dai Jan 09 '20 at 00:59