ASP CInt CLNG scope and prevent CInt and clng Overflow Solution Encyclopedia _ Application Techniques

Source: Internet
Author: User
Tags abs

The first thing we need to know is

CInt Range-32,768 to 32,767.
CLng Range-2,147,483,648 to 2,147,483,647.

CInt and clng meaning:

Can force an expression to be converted to a data type

CInt and clng The scope of processing data:

CInt integer-32,768 to 32,767, fractional part rounded.
CLng long-2,147,483,648 to 2,147,483,647, fractional part rounded.

The so-called overflow refers to the scope of processing data, the following code is to handle data to prevent overflow code, you can see for yourselves:

' Detect if it is a short integer

Copy Code code as follows:

Sub Is_int (String)
If Len (ABS (String)) >10 then Response.Write "Data Overflow": Response.End
If InStr (String, "-") <1 Then
If CInt (string,4) >3276 and CInt (right (string,1)) >7 then "Data Overflow": Response.Write
Else
If CInt (Left (ABS (String), 4)) >3276 and CInt (right (string,1) >8 then "Data Overflow": Response.Write
End If
End Sub


' Detect if it is a long integer
Copy Code code as follows:

Sub Is_lng (String)
If Len (ABS (String)) >10 then Response.Write "Data Overflow": Response.End
If InStr (String, "-") <1 Then
If CLng (string,9) >214748364 and CLng (right (string,1)) >7 then "Data Overflow": Response.Write
Else
If CLng (Left (ABS (String), 9)) >21478364 and CLng (right (string,1) >8 then "Data Overflow": Response.Write
End If
End Sub


here are some test functions that need to be consulted by a friend:

First type:
First, detect if it is not an integer
Copy Code code as follows:

function Is_int (A_STR)
If not IsNumeric (A_STR) or Len (str) > 5 Then
Is_int = False
Exit function
ElseIf len (str) < 5 Then
Is_int = True
Exit function
End If
If CInt (left (A_STR, 4)) > 3276 Then
Is_int = False
Exit function
ElseIf CInt (A_STR, 4) = 3276 and CInt (right (A_STR, 1)) > 7 Then
Is_int = False
Exit function
Else
Is_int = True
Exit function
End If
End Function




Second, detect it is not a long integer

Copy Code code as follows:

function Is_lng (A_STR)
If not IsNumeric (A_STR) or Len (str) > Then
IS_LNG = False
Exit function
ElseIf len (str) < Then
IS_LNG = True
Exit function
End If
If CLng (left (A_STR, 9)) > 214748367 Then
IS_LNG = False
Exit function
ElseIf CLng (a_str, 9) = 214748367 and CLng (right (A_STR, 1)) > 7 Then
IS_LNG = False
Exit function
Else
IS_LNG = True
Exit function
End If
End Function

If we only need to count the number of children, other things, can be replaced by empty, below this is the cloud Habitat Community Webmaster wrote a regular, replace the non-digital regular
Copy Code code as follows:

function Replacestr (str)
Dim re
Set Re=new regexp
Re.ignorecase=true
Re.global=true
Re.pattern= "\d"
Str=re.replace (str, "")
Replacestr=str
Set re=nothing
End Function

The following is the calling method above
Copy Code code as follows:

ID=REPLACESTR (ID)
If Len (ID) >5 then id=left (id,5)
If id<> "" then ID=CLNG (ID)
If err.number<>0 Or id= "0" then Response.Redirect "Http://www.jb51.net"
Dim rs
Set Rs=conn.execute ("SELECT ID from News where id=" &id& ")

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.