I'm adding a bit of functionality to an old ("old" as in "olde"; as in Rip-van-Winkle olde) website that uses VBScript.
The upshot of my problem is that certain logic seems to always equate to a single result (IsNewBusiness is always apparently assigned a value of FALSE), whereas it should sometimes equate to the opposite, that logic being:
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
End If
So, since the logic is always equating to false, I have to assume that this line:
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
...is being reached, and that adoRS.Fields.Item(0).Value is always 0
As you can see in the above code, the IsNewBusiness Boolean is set to TRUE to start with, but never remains true, although it should be (reset) to TRUE on some occasions (the query result should, given certain parameters, return a value of "-1" rather than 0).
This question is related to but really separate from a question I asked here:
So, to get to the crux of the biscuit, I want to make absolutely certain that the if block shown above is being reached, by writing out a "debug msg" to the console or something similar.
Based on legacy code in this site, I made this attempt to partner with javascript to those ends:
ReturnMsg = "Made it to IsNewBusiness logic"
Response.Write("<script type=""text/javascript"">" & vbCrLf)
Response.Write("alert ('" & ReturnMsg & "');" & vbCrLf)
Response.Write("</script>" & vbCrLf)
...but it doesn't seem to work - I never see that msg.
I also tried this:
Response.Write("window.alert(ReturnMsg);")
...and this:
Response.Write("console.log(ReturnMsg);")
...with no difference in results. All that I see in my console is:
How can I accomplish an "alert" or a console log msg, or some such, using either VBScript, or javascript, or whatever?
UPDATE
I even tried some inline javascript, like so:
adoRS.Close()
<script language="javascript">
window.alert("Made it past the IsNewBusiness logic");
</script>
...but it blew up...
UPDATE 2
I tried the trick mentioned by Kul-Tigin, but it didn't seem to work for me.
I changed this code:
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0 'Is this ever reached?
End If
adoRS.Close()
...to this:
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
ReturnMsg = "Before the If Not adoRS.EOF block"
Response.Write("<script type=""text/javascript"">" & vbCrLf)
Response.Write("<!--" & vbCrLf)
Response.Write("alert ('" & ReturnMsg & "');" & vbCrLf)
Response.Write("-->" & vbCrLf)
Response.Write("</script>" & vbCrLf)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0 'Is this ever reached?
ReturnMsg = "Entered the If Not adoRS.EOF block"
Response.Write("<script type=""text/javascript"">" & vbCrLf)
Response.Write("<!--" & vbCrLf)
Response.Write("alert ('" & ReturnMsg & "');" & vbCrLf)
Response.Write("-->" & vbCrLf)
Response.Write("</script>" & vbCrLf)
End If
adoRS.Close()
...ran the site to get to that page, selected View Source, searched for "the If Not adoRS.EOF block", and there were no matches. Am I doing it wrong?
UPDATE 3
I also tried this (the above was based on existing code in the page, the below is based on the commenter's snippet):
Response.Write("<!-- Before the If Not adoRS.EOF block -->")
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0 'Is this ever reached?
Response.Write("<!-- After the If Not adoRS.EOF block -->")
End If
UPDATE 4
The only way I was able to get the debug msg I added to show up in the View Source was to insert some javascript that threw an error. Adding this javascript:
<script language="javascript">
window.alert("Before the If Not adoRS.EOF block js");
</script>
In some context:
Response.Write("<!-- Before the If Not adoRS.EOF block -->")
<script language="javascript">
window.alert("Before the If Not adoRS.EOF block js");
</script>
If Not adoRS.EOF Then
...caused this to appear on the page:
Server Error in '/EMS/customerreportingnet' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30636: '>' expected.
Source Error:
Line 129: IsNewBusiness = TRUE 'default (if record not found)
Line 130: Response.Write("<!-- Before the If Not adoRS.EOF block -->")
Line 131: <script language="javascript">
Line 132: window.alert("Before the If Not adoRS.EOF block js");
Line 133: </script>
Source File: C:EnhancedMonthlySalesReportingcustomerreportingnetcustomerreportingnetpagescustmaint_entry.aspx Line: 131
...and this in the View Source:
Line 129: IsNewBusiness = TRUE 'default (if record not found)
Line 130: Response.Write("<!-- Before the If Not adoRS.EOF block -->")
<font color=red>Line 131: <script language="javascript">
</font>Line 132: window.alert("Before the If Not adoRS.EOF block js");
Line 133: </script></pre></code>
...so I'm still swimming upstream in Leviathan-infested waters, it seems.
See Question&Answers more detail:
os