" style="fo...">

Why is my boolean not assigned the correct value?

I have 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 logical value of IsNewBusiness, load one or the other of a pair of elements into an html selector.

However, the same logic is always true ("not IsNewBusiness"), and the first two elements ("Existing" and "Organic Growth") are always the ones that fill the selected item.

Code that assigns a value:

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 shows, there are some cases where the value must be true (it is true if NewBiz is not 0):

enter image description here

"-1" , "" " " select, "" "".

- ?

UPDATE

. , :

Wscript.Echo "Like this?" ' bogus
IsNewBusiness = TRUE 'default (if record not found)

... , :

"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 

2

false, , :

IsNewBusiness = adoRS.Fields.Item(0).Value <> 0

... adoRS.Fields.Item(0).Value 0

, IsNewBusiness TRUE, , .

3

- - :

currentYear = 2525 'Year(Now)

( )

... - "" " " - , select.

4

Response.Writes, JonP, html:

enter image description here

... , , , VBScript:

enter image description here

, , :

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 

html, View Source:

Response.Write "<!-- Is New Biz = " . IsNewBusiness . "-->" 

... . - , ...

5

Jon P: , :

<% Response.Write "<!-- Is New Biz before select elements assigned = " . IsNewBusiness . "-->" %>

... IsNewBusiness, ( ):

<script language="VB" runat="Server">
. . .
Dim IsNewBusiness As Boolean

... (, ), ​​ :

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 

6

:

<% Response.Write("<!-- Is New Biz = " . IsNewBusiness . "-->") %>

... :

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

... , "IsNewBusiness" , ?

7

:

<% Response.Write("<!-- Is New Biz = " . CStr(IsNewBusiness) . "-->") %>

... : "BC30456:" CStr " " String ".

:

<% Response.Write("<!-- Is New Biz = " . Convert.ToString(IsNewBusiness) . "-->") %>

... : "BC30456:" " " String ".

8

, , , :

<%
Response.Write("<!-- Is New Biz = " & CStr(IsNewBusiness) & "-->")
Unit = Request.QueryString.Item("Unit")
. . .

... . , - ""? F12, ...

+4
1

"debug msg" MCND " ", . :

<%
. . .   
'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
. . .
+3

Source: https://habr.com/ru/post/1671163/


All Articles