5

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):

enter image description here

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?

UPDATE

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 

UPDATE 2

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.

UPDATE 3

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.

UPDATE 4

When I add the Response.Writes recommended by JonP, it looks fine by the html:

enter image description here

...but doesn't seem to be wanted when in the VBScript:

enter image description here

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...

UPDATE 5

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 

UPDATE 6

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?

UPDATE 7

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'."

UPDATE 8

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...

user692942
  • 16,398
  • 7
  • 76
  • 175
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 2
    Add some debug dumps with Response.Write. Add one to check the value of `adoRS.EOF` before the If stamement. Add one inside the if statement to check `adoRS.Fields.Item(0).Value` . Add one after the if statmement to check the value of `IsNewBusiness`. Finally add one before your HTML select again checking the value of `IsNewBusiness `. Wrap use html comments in the `response.write` so users don't see the dumps. E.g `Response.Write ""` – Jon P Mar 01 '17 at 23:34
  • I've been trying to do that, but am not seeing those values being written anywhere, neither in the console nor via "View Source"; see http://stackoverflow.com/questions/42539024/how-can-i-write-a-debug-msg-to-the-console-or-elsewise-in-an-old-web-site – B. Clay Shannon-B. Crow Raven Mar 02 '17 at 00:07
  • 2
    YOu need to throw those dumps inside some asp delimiters, e.g: `<% Response.Write "" %>` – Jon P Mar 03 '17 at 00:07
  • 1
    Sorry my vbscript is rusty... try `<% Response.Write("") %>` . VbSript is annoying on when it wants () and when it doesn't. Apply the parentheses to all the dump `Response.Write` calls – Jon P Mar 03 '17 at 00:34
  • Update 6 continues the sad story. – B. Clay Shannon-B. Crow Raven Mar 03 '17 at 17:32
  • 1
    This is vbscript, string concatenation is done with `&` operator, not `.` – MC ND Mar 03 '17 at 17:55
  • @MCND: That (replacing the dots with ampersands) at least gets it to run without the err page, but I still don't see the response. That may be because that code is not being reached. I'll try it in some other places. Do you know if the Boolean will automatically be converted to a string, or do I need to use CStr() or something? – B. Clay Shannon-B. Crow Raven Mar 03 '17 at 18:01
  • 1
    Implicit type conversion depends on the method used to output the data. Sorry, but I don't remember (and I can not test it) what the `Response.Write` does. Just to be sure use `CStr(IsNewBusiness)`. On your update 8, you are writting an html comment, so, you need to look inside the page's html. – MC ND Mar 03 '17 at 18:13
  • @MCND: Great, finally a little progress! I do see "" via View Source - thanks! I still don't know why the Boolean value is always false, but this is a step in the right direction. – B. Clay Shannon-B. Crow Raven Mar 03 '17 at 18:27
  • 1
    So, do you get "FALSE" in that HTML comment when you pass in a year that doesn't exist in your table? If so, it suggests that the value "FALSE" is coming from somewhere besides the code posted. The check for `rsADO.EOF` insures that. – JNevill Mar 03 '17 at 19:12
  • It seems that code is not being reached; I put the "debug msgs" in there, and they don't appear in the View Source. I'll try putting that database logic elsewhere to see if it gets reached and recognized and respected. – B. Clay Shannon-B. Crow Raven Mar 03 '17 at 19:16
  • 1
    Yea it might be a good idea to dump that database code where the recordset is generated in the body of your page and have it dump the `rsADO.fields.item(0).value` somewhere so you can see what you are getting back from the database. Perhaps have it dump your sql to before execution so you can verify it's being written correctly too. – JNevill Mar 03 '17 at 19:22
  • @MCND: If one of you cats wants to add an answer (I added one, but don't want to and probably count give myself the bounty), I will gladly pour out the abundant wealth into your virtual pocketbook. – B. Clay Shannon-B. Crow Raven Mar 03 '17 at 19:40
  • @JNevill: If one of you cats wants to add an answer (I added one, but don't want to and probably count give myself the bounty), I will gladly pour out the abundant wealth into your virtual pocketbook. – B. Clay Shannon-B. Crow Raven Mar 03 '17 at 19:40
  • @MCND this is **NOT** VBScript, case in point `Dim IsNewBusiness As Boolean` would fail in VBScript and by extension Classic ASP. If you look at the compilation errors *(yes, that in itself is a giveaway!)* you notice the error is coming from `C:\EnhancedMonthlySalesReporting\customerreportingnet\customerreportingnet\pages\custmaint_entry.aspx` which is a ASP.Net file likely using VB.Net as it'sbase language. – user692942 Mar 29 '17 at 14:48

1 Answers1

4

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
. . .
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • Your using ASP.Net you debug on the fly, that type of debugging is reserved for Classic ASP. Next time, actually report what you are using not what you think you are. So much misinformation in this thread. – user692942 Mar 29 '17 at 14:50
  • Not sure what you mean by that; do I mention "Classic ASP.NET"? I cannot debug this in the usual way, as the code won't even compile. It has dozens of errors, but I am not to even try to fix it, just add this functionality. Anyway, it's working now. – B. Clay Shannon-B. Crow Raven Mar 29 '17 at 15:06
  • You go on about VBScript everywhere which if you start talking about *"compiling"* this clearly isn't, VBScript is only used server-side as a default scripting language for Classic ASP *(hence that reference)*. Let's be clear ASP.Net is one thing and Classic ASP is another there is no technology called *"Classic ASP.Net"* that shows you don't know what you are using. – user692942 Mar 29 '17 at 15:09
  • I'd also recommend you read [ASP.NET Data Access](https://msdn.microsoft.com/en-us/library/aa719548%28v=vs.71%29.aspx?f=255&MSPPError=-2147217396). ASP.Net has it's version of ADO at the moment you are shoehorning old ADODB code into ASP.Net which is not recommended. – user692942 Mar 29 '17 at 15:13
  • Again, where do I mention "Classic ASP.NET"? Maybe I did, I don't recall. My manager told me it was VBScript. Anway, it doesn't really matter any more. – B. Clay Shannon-B. Crow Raven Mar 29 '17 at 15:13
  • You [just did](http://stackoverflow.com/questions/42537661/why-is-my-boolean-not-being-assigned-the-correct-value/42587090?noredirect=1#comment73276071_42587090), whereas I haven't, you say I have, [but I haven't](http://stackoverflow.com/questions/42537661/why-is-my-boolean-not-being-assigned-the-correct-value/42587090?noredirect=1#comment73275151_42537661). – user692942 Mar 29 '17 at 15:21