An error by ASP, see different languages: ASP & Java

Source: Internet
Author: User

View the Web page source code today, inadvertently found that the source code trailer throws ASP error information, but not displayed on the Web page.

If you do not see the source code, you have not found the ASP running code error.

In the general case, in ASP, there is a variable to represent the user's current capacity, note that this variable is a string, format such as: 20.3M, 50.6G

The last character is either M or G

The program needs to make a judgment, if the user uses more than 50G of capacity, the pop-up message, the relevant code is as follows:

12345678910111213 <%str = "59.3G"if right(str,1) = "G" and cdbl(replace(str,"G","")) > 50 then     response.write("> 50G")     else     response.write("< 50G")    end if%>

Run output result: > 50G

When str = "600.3M", the program throws an error:

Microsoft VBScript Run-time error (0X800A000D)

Type mismatch: ' CDbl '

And did not output what I expected: < 50G

We use the same logic to rewrite it using Java:

12345678910 Stringstr = "59.3G";        if(str.endsWith("G") && Double.parseDouble(str.replaceAll("G""")) > 50){    System.err.println("> 50G");}  else{    System.err.println("< 50G");}

Results of the output:

> 50G

If String str = "630.3M";

Results of the output:

< 50G

Summarize:

From the above two kinds of code, in ASP, when judging multiple conditions (and), when the first condition is not established, will continue to determine whether the next condition is true:

Another validation code:

123456789101112131415161718192021 <%function abc()    response.write("abc()...<br>")    abc = trueend functionstr = "59.3M" int x if right(str,1) = "G" and abc then     response.write("> 50G")     else     response.write("< 50G")    end if%>

Output:

ABC () ...

< 50G

In Java code, when a number of conditions (and, &) are judged, when the first condition is not set, the following criteria will not be judged, no longer execute the following judgment code.

2014-04-02

An error by ASP, see different languages: ASP & Java

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.