Considerations for multiple expression operations in an if Else statement in ASP

Source: Internet
Author: User

Let's take a look at an example:

The code is as follows Copy Code

<%
If fun1 () and fun2 () Then
Response.Write ("Yes" & "<br/>")
Else
Response.Write ("No" & "<br/>")
End If

Function fun1 ()
Response.Write ("Fun1" & "<br/>")
FUN1 = False
End Function

Function fun2 ()
Response.Write ("Fun2" & "<br/>")
Fun2 = True
End Function
%>

According to the figure above, FUN1 returns False when it also calls Fun2 (C # and other languages have done optimizations do not invoke fun2), so when the current expression has a relationship with the top of the writing program may be wrong:

The code is as follows Copy Code

<%
Dim number:number = "mzwu.com"
If IsNumeric (number) and Instr (number, ".") =0 and CInt (number) >=10 Then
Response.Write ("Yes")
Else
Response.Write ("No")
End If
%>

The first two expressions are used to determine that number is an integer, but CInt is still called, it is really maddening, there is no way, by design, change to if nested structure can be resolved:

The code is as follows Copy Code

<%
Dim number:number = "mzwu.com"
If IsNumeric (number) and Instr (number, ".") =0 Then
If CInt (number) >=10 Then
Response.Write ("Yes")
Else
Response.Write ("No")
End If
Else
Response.Write ("No")
End If
%>

Other operators also have the same problem, the program code to write must pay attention to.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.