首页 | 技巧收集 | 资源分享 | 网管文集 | 开发资料 | 生活点滴 | 轻松一下 | 原创作品 | 网海拾贝 
用户登陆
用户:
密码:
 

最新评论

文章搜索

 标题   内容

程序:我的助手 EXE文件关联修复器
晴天 常用ASP代码收集
[ 分类:开发资料 ]   [阅读:32091 ]   [ 日期:2004-11-2 ]   [ 来自:飘雪工作室 ]
一、过滤掉HTML代码的函数
Code:

Function FilterHTML(strToFilter)
Dim strTemp
strTemp = strToFilter
While Instr(1,strTemp,"<") AND Instr(1, strTemp, ">")
strTemp = Left(strTemp, Instr(1, strTemp, "<")-1) & Right(strTemp, Len(strTemp)-Instr(1,strTemp, ">"))
WEnd
FilterHTML = strTemp
End Function


二、检测整数和长整数的函数
检测字符串是否是整数
Code:

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(left(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


检测是否是长整数

Code:
function Is_Lng(a_str)
if not isnumeric(a_str) or len(str) > 10 then
Is_Lng = false
exit function 
elseif len(str) < 10 then
Is_Lng = true 
exit function 
end if 
if clng(left(a_str , 9)) > 214748367 then
Is_Lng = false
exit function
elseif clng(left(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


三、检查SQL字符串中是否有单引号,有则进行转化

Code:
function CheckStr(str)
       dim tstr,l,i,ch
   l=len(str)
   for i=1 to l
       ch=mid(str,i,1)
       if ch="'" then
      tstr=tstr+"'"
   end if
   tstr=tstr+ch
   next
   CheckStr=tstr
   end function



四、计算文件下载时间


Code:
Function DownloadTime(intFileSize, strModemType)
Dim TimeInSeconds, ModemSpeed, strDownloadTime, AppendString
Dim intYears, intWeeks, intDays
Dim intHours, intMinutes, intSeconds
intYears = 0
intWeeks = 0
intDays = 0
intHours = 0
intMinutes = 0
intSeconds = 0
strDownloadTime = ""
Select Case strModemType
Case "Cable"
ModemSpeed = 400000
Case "56kbps"
ModemSpeed = 7000
Case "33.6kbps"
ModemSpeed = 4200
Case "28.8kbps"
ModemSpeed = 3600
End Select
TimeInSeconds = int(intFileSize / ModemSpeed)
'year maths added 1/4 of a day. 1 exact orbit of the sub is 365.25 days.
If (Int(TimeInSeconds / 31471200) <> 0) Then intYears = Int(TimeInSeconds / 31449600)
If ((Int(TimeInSeconds / 604800) Mod 52) <> 0) Then intWeeks = Int(TimeInSeconds / 604800) Mod 52
If ((Int(TimeInSeconds / 86400) Mod 7) <> 0) Then intDays = Int(TimeInSeconds / 86400) Mod 7
If TimeInSeconds >= 3600 Then intHours = Int(TimeInSeconds / 3600) Mod 24
If TimeInSeconds >= 60 Then intMinutes = Int(TimeInSeconds / 60) Mod 60
If TimeInSeconds >= 0 Then intSeconds = Int(TimeInSeconds) Mod 60
If intYears <> 0 Then
If intYears = 1 Then AppendString = "" Else AppendString = "s"
strDownloadTime = strDownloadTime & intYears & " year" & AppendString & ", "
End If
If intWeeks <> 0 Then
If intWeeks = 1 Then AppendString = "" Else AppendString = "s"
strDownloadTime = strDownloadTime & intWeeks & " week" & AppendString & ", "
End If
If intDays <> 0 Then
If intDays = 1 Then AppendString = "" Else AppendString = "s"
strDownloadTime = strDownloadTime & intDays & " day" & AppendString & ", "
End If
If intHours <> 0 Then
If intHours = 1 Then AppendString = "" Else AppendString = "s"
strDownloadTime = strDownloadTime & intHours & " hour" & AppendString & ", "
End If
If intMinutes <> 0 Then
If intMinutes = 1 Then AppendString = "" Else AppendString = "s"
strDownloadTime = strDownloadTime & intMinutes & " minute" & AppendString
End If
If ((intYears = 0) And (intWeeks = 0) And (intDays = 0) And (intHours = 0)) Then
If intSeconds = 1 Then AppendString = "" Else AppendString = "s"
If intMinutes > 0 Then
strDownloadTime = strDownloadTime & ", " & intSeconds & " second" & AppendString
Else
strDownloadTime = strDownloadTime & intSeconds & " second" & AppendString
End If
End If
DownloadTime = strDownloadTime
End Function


五、在ASP中判断SQL语句是否执行成功


Code:
sql="insert into table(f1,f2) values('v1','v2')"
    conn.execute sql
    if err.number<>0 then 
        response.write "出错了:"& err.description err.clear
    else 
        response.write "OK"
    end if 



六、 转换字符串单词的第一个字母为大写

Code:
Function PCase(strInput)
iPosition = 1
Do While InStr(iPosition, strInput, " ", 1) <> 0
iSpace = InStr(iPosition, strInput, " ", 1)
strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
strOutput = strOutput & LCase(Mid(strInput, iPosition + 1, iSpace - iPosition))
iPosition = iSpace + 1
Loop
strOutput = strOutput & UCase(Mid(strInput, iPosition, 1))
strOutput = strOutput & LCase(Mid(strInput, iPosition + 1))
PCase = strOutput
End Function



七、获得ASP的中文日期字符串

Code:
<%
Function Date2Chinese(iDate)
    Dim num(10)
    Dim iYear
    Dim iMonth
    Dim iDay

    num(0) = "〇"
    num(1) = "一"
    num(2) = "二"
    num(3) = "三"
    num(4) = "四"
    num(5) = "五"
    num(6) = "六"
    num(7) = "七"
    num(8) = "八"
    num(9) = "九"

    iYear = Year(iDate)
    iMonth = Month(iDate)
    iDay = Day(iDate)
    Date2Chinese = num(iYear \ 1000) + _
        num((iYear \ 100) Mod 10) + num((iYear _
        \ 10) Mod 10) + num(iYear Mod _
         10) + "年"
    If iMonth >= 10 Then
        If iMonth = 10 Then
            Date2Chinese = Date2Chinese + _
             "十" + "月"
        Else
            Date2Chinese = Date2Chinese + _
            "十" + num(iMonth Mod 10) + "月"
        End If
    Else
        Date2Chinese = Date2Chinese + _
            num(iMonth Mod 10) + "月"
    End If
    If iDay >= 10 Then
        If iDay = 10 Then
            Date2Chinese = Date2Chinese + _
             "十" + "日"
        ElseIf iDay = 20 Or iDay = 30 Then
            Date2Chinese = Date2Chinese + _
            num(iDay \ 10) + "十" + "日"
        ElseIf iDay > 20 Then
            Date2Chinese = Date2Chinese + _
            num(iDay \ 10) + "十" + _
            num(iDay Mod 10) + "日"
        Else
           Date2Chinese = Date2Chinese + _
           "十" + num(iDay Mod 10) + "日"
        End If
    Else
        Date2Chinese = Date2Chinese + _
        num(iDay Mod 10) + "日"
    End If
End Function
%>
<<<< 调 用 举 例 >>>>
<%
response.write date2Chinese(date())
%>


八、统计某一字符在字符串中出现的次数
Code:
Function StrCount(Str,SubStr)        
    Dim iStrCount
    Dim iStrStart
    Dim iTemp
    iStrCount = 0
    iStrStart = 1
    iTemp = 0
    Do While iStrStart < Len(Str)
        iTemp = Instr(iStrStart,Str,SubStr,vbTextCompare)
        If iTemp <=0 Then
            iStrStart = Len(Str)
        Else
            iStrStart = iTemp + Len(SubStr)
            
            iStrCount = iStrCount + 1
        End If
        
    Loop
    StrCount = iStrCount
End Function




[本日志由 飘雪 于 2005-12-22 01:00 PM 编辑]
引用通告地址 (0):
复制引用地址http://www.pxue.com/trackback.asp?tbID=22
复制引用地址http://www.pxue.com/trackback.asp?tbID=22&CP=GBK
Tag:
引用这个评论 飘雪 于 2005-06-24 10:49 AM 发表评论: 
先做一个HTML页面,放两个输入框,一个名称为name,一个为pass,类型为password,表单提交设置为ASP文件名,如a.asp
用记事本建一个文本文档,后缀名改成asp,用记事本打开,里面写:
Code:
<%
If Request.form("Name") = "" or Request.form("pass") = "" Then
  Response.write "登陆名和密码不能为空!"
  Response.end
Else
  If Request.form("name")="admin" and Request.form("pass") = "admin888" Then
   Response.write "你已经成功登陆!"
   Response.end
  Else
   Response.write "登陆名或密码错误!"
   Response.end
   End If
End If
%>
 

引用这个评论 tedazhehua 于 2005-06-23 04:15 PM 发表评论: 
很急!!
请帮帮我!!
xs

引用这个评论 tedazhehua 于 2005-06-23 04:12 PM 发表评论: 
没了么?
能不能帮我看看这个怎么做?
用记事本编写一段具有用户登陆功能的ASP代码,要求使用到PASSWORD口令代码

发表评论
作者: 用户名: 密码:  同时注册?验证码: 验证码,看不清楚?请点击刷新验证码
评论:

禁止表情
禁止UBB
禁止图片
识别链接
识别关键字
表  情
 
COPYRIGHT © 飘雪工作室 WWW.PXUE.COM ALLRIGHTS RESERVED Processed in 0.109375 second(s) , 15 queries
粤ICP备05001034号