I've got this ASP.Net code:
<select name="subcategory" color="<%=Session("TextColor")%>" style="font: 8pt arial" onchange="UpdateFlag=true;">
<% if not IsNewBusiness then %>
<option value="0">Existing
<option value="1">Organic Growth
<% else %>
<option value="0">New
<option value="1">Assumed
<% end if %>
</select>
...which should, based on the value of the Boolean IsNewBusiness, load one or the other of a pair of items to the html select element.
However, the same logic always equates to true ("not IsNewBusiness"), and the first two items ("Existing" and "Organic Growth") are always the ones that populate the select element.
The code that assigns the value is:
Dim IsNewBusiness As Boolean
. . .
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
End If
As the "NewBiz" column in the query results below show, there are some cases where the value should be true (it's true where NewBiz is not 0):
But even when I choose one of the "-1" Units in my site, I still get "Existing" and "Organic Growth" in the select element, not "New" and "Assumed".
Is there something wrong with my logic?
The query code is being reached. I know that because I put a line of bogus code there:
Wscript.Echo "Like this?" ' bogus
IsNewBusiness = TRUE 'default (if record not found)
...and when I ran it, I got:
"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: BC30451: Name 'Wscript' is not declared.
Source Error:
Line 127: SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
Line 128: adoRS.Open(SQLString, adoCon)
Line 129: Wscript.Echo "Like this?"
Line 130: IsNewBusiness = TRUE 'default (if record not found)
Line 131: If Not adoRS.EOF Then
Source File: C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx Line: 129
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
So IsNewBusiness is set to TRUE to start with, but never remains true, although it should on some occasions.
Now here's something really bizarre - when I change the assignment to the year to a manifestly bogus one:
currentYear = 2525 'Year(Now)
(there are no entries for that year in the table)
...I still get the same results - "Existing" and "Organic Growth" are the two values that fill the select element.
When I add the Response.Writes recommended by JonP, it looks fine by the html:
...but doesn't seem to be wanted when in the VBScript:
In fact, when I run it, I get this:
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: BC30800: Method arguments must be enclosed in parentheses.
Source Error:
Line 127: SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
Line 128: adoRS.Open(SQLString, adoCon)
Line 129: Response.Write "<!-- Is New Biz = " . IsNewBusiness . "-->"
Line 130: IsNewBusiness = TRUE 'default (if record not found)
Line 131: If Not adoRS.EOF Then
Source File: C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx Line: 129
As for the one added amidst the html, I can see it in View Source:
Response.Write "<!-- Is New Biz = " . IsNewBusiness . "-->"
...but that doesn't do me much good. The value is not in the console or anywhere else that I can see...
Jon P: When I try that, like so:
<% Response.Write "<!-- Is New Biz before select elements assigned = " . IsNewBusiness . "-->" %>
...IsNewBusiness, which is declared here (at the top of the file):
<script language="VB" runat="Server">
. . .
Dim IsNewBusiness As Boolean
...is red (indicating that it is viewed by the compiler as a foreign antibody), and I get the runtime error:
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: BC30800: Method arguments must be enclosed in parentheses.
Source Error:
Line 722: </td>
Line 723: </tr>
Line 724: <% Response.Write "<!-- Is New Biz before select elements assigned = " . IsNewBusiness . "-->" %>
Line 725: <tr>
Line 726: <td nowrap align="left" valign="top">
Source File: C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx Line: 724
With the syntax tweak recommended:
<% Response.Write("<!-- Is New Biz = " . IsNewBusiness . "-->") %>
...it still fails:
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: BC30456: 'IsNewBusiness' is not a member of 'String'.
Source Error:
Line 723: </tr>
Line 724: <%--<% Response.Write "<!-- Is New Biz before select elements assigned = " . IsNewBusiness . "-->" %>--%>
Line 725: <% Response.Write("<!-- Is New Biz = " . IsNewBusiness . "-->") %>
Line 726: <tr>
Line 727: <td nowrap align="left" valign="top">
...possibly because "IsNewBusiness" is a Boolean, and needs to be converted to a string?
I tried this:
<% Response.Write("<!-- Is New Biz = " . CStr(IsNewBusiness) . "-->") %>
...and got, "BC30456: 'CStr' is not a member of 'String'."
I also tried:
<% Response.Write("<!-- Is New Biz = " . Convert.ToString(IsNewBusiness) . "-->") %>
...and got, "BC30456: 'Convert' is not a member of 'String'."
Even when I put it in a place I know is getting reached:
<%
Response.Write("<!-- Is New Biz = " & CStr(IsNewBusiness) & "-->")
Unit = Request.QueryString.Item("Unit")
. . .
...I see nothing. I'm not sure exactly what to expect - an "alert"? I hit F12, and there is nothing in the Console...
Once I used the "debug msg" code from MCND and moved the database code above the "Save Action" it works just fine. Here it is in a little context:
<%
. . .
'determine whether this unit is a new business
currentYear = Year(Now)
SQLString = "Select NewBiz from MasterUnitsprojSales where CYear = " & currentYear & " and Unit = '" & Unit & "'"
adoRS = New ADODB.Recordset
adoRS.Open(SQLString, adoCon)
IsNewBusiness = TRUE 'default (if record not found)
If Not adoRS.EOF Then
IsNewBusiness = adoRS.Fields.Item(0).Value <> 0
Response.Write("<!-- IsNewBusiness after NOT EOF = " & CStr(IsNewBusiness) & "-->")
End If
adoRS.Close()
If Request.Form.Item("Action") = "Save" Then
. . .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With