一些個人常用的函數

<
''-------------------------------------------------------------------
'
'創建一個可以更新的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
%
>
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章