一些个人常用的函数

<
''-------------------------------------------------------------------
'
'创建一个可以更新的RS对象
'
function GetRS(conn,table,where,orderby)
'
'测试objRS是否有纪录,有就返回true
'
function ChkRS(objRS)
'
'根据条件Where返回指定表table的属性Attribute的值
'
function GetAttr(conn,table,where,attribute)
'
'截取字符串
'
Function LeftStr(ByVal Str, ByVal MaxLength)
'
'得到字符长度
'
Function CountLength(Str)
'
'安全获取ID
'
function RstInt(strID)
'
'-------------------------------------------------------------------

'创建一个可以更新的RS对象
function GetRS(conn,table,where,orderby)
    
set rs=server.CreateObject("adodb.recordset")
    
if orderby<>"" then orderby=" order by "&orderby
    
if where<>"" then where=" where "&where
    rs.open 
"select * from "&table&where&orderby,conn,1,3
    
set GetRS=rs
end function

'测试objRS是否有纪录,有就返回true
function ChkRS(objRS)
    
if not objRS.bof and not objRS.eof then
        ChkRS
=true
    
else
        ChkRS
=false
    
end if
end function

'根据条件Where返回指定表table的属性Attribute的值
function GetAttr(conn,table,where,attribute)
    
if where<>"" then where=" where "&where
    
set rsAttr=conn.execute("select "&attribute&" from "&table&where)
    
if not rsAttr.bof and not rsAttr.eof then
        GetAttr
=rsAttr(attribute)
    
else
        GetAttr
="-1"
    
end if
end function

'截取字符串
Function LeftStr(ByVal Str, ByVal MaxLength)
    
Dim Output,i
    
If IsNull(Str) Then Str = ""
    Output 
= ""
    
If LenB(Str) <= MaxLength Then
        Output 
= Str
    
Else
        
For i = 1 To Len(Str)
            Output 
= Output & Mid(Str,i,1)
            
If CountLength(Output)+3 = MaxLength Then
                Output 
= Output & "..."
                
Exit For
            
ElseIf CountLength(Output)+3 > MaxLength Then
                Output 
= Left(Output,Len(Output)-1& "..."
                
Exit For
            
End If
        
Next
    
End If
    LeftStr 
= Output
End Function

'得到字符长度
Function CountLength(Str)
    
Dim output,ThisChar,i
    output 
= 0
    
For i = 1 To Len(Str)
        ThisChar 
= Mid(Str,i,1)
        
If Asc(ThisChar) < 0 Then
            output 
= output + 2
        
Else
            output 
= output + 1
        
End If
    
Next
    CountLength 
= output
End Function

'安全获取ID
function RstInt(strID)
    
Dim regex              ' 声明变量
    Set regex = New RegExp ' 创建对象
    ID=request(strID)
    regex.Pattern 
= "^[0-9]+$"
    
If regex.Test(ID) Then
        RstInt
=ID
    
Else
        RstInt
=-1
    
End If
end function
%
>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值