最近写的几个函数

'判断值是否是整数
Function IsInt(intNum)
 On Error Resume Next
 IsInt = False
 If Not Len(intNum) > 0 OR intNum = "" Then IsInt = False : Exit Function
 If Not IsNumeric(intNum) Then IsInt = False : Exit Function
 If Instr(1,intNum,".") > 0 Then IsInt = False : Exit Function
 'If Not intNum < 65536 Then IsInt = False : Exit Function
 IsInt = True
End Function

'获得文章的指定长度
Function gotTopic(str,strlen)
 On Error Resume Next
 Dim errMsg
 Dim l,t,c,i
 errMsg = "SERVER ERROR"
 If Not Len(str) > 0 OR str = "" Then gotTopic = errMsg &"00001" : Exit Function
 If Not IsInt(strlen) Then gotTopic = errMsg &"00002" : Exit Function '判断是否为整数
 l=len(str)
 t=0
 For i=1 to l
  c=Abs(Asc(Mid(str,i,1)))
  If c>255 Then
   t=t+2
  Else
   t=t+1
  End If
  If t>=strlen*2 Then
   gotTopic=Left(str,i)&"..."
   Exit For
  Else
   gotTopic=str
  End If
 Next
End Function

'----------------------------------------------------------
'Desc: 验证URL地址...
'  url为空转到默认链接defaultURL;
'       url为http://也转到defaultURL;
'     如果url没有带http://则需要在url前面加上http://
'Author: Poon
'Create Data: 200605012
'Last Modified: 20060602
'----------------------------------------------------------
Function CheckURL(byVal url,byVal defaultURL)
 On error resume Next
 Dim errMsg
 errMsg = "SERVER ERROR"
 If Not Len(defaultURL) > 0 OR defaultURL = "" Then CheckURL = errMsg &"00001" : Exit Function
 If Not Len(url) > 0 OR url = "" Then CheckURL = defaultURL : Exit Function
 If Not Instr(1,url,"http://") > 0 Then
  CheckURL = "http://"& url
 Else
  CheckURL = url
 End If
End Function

'----------------------------------------
'Desc:指定长度返回随机字符串或者数字
'Parameter: intLen>0 int 需要生成随机数的长度
'   rndType  1 产生随机的数字 0~9
'      2 产生随机的字符串 A~Z
'CreateBy: Poon@060602
'----------------------------------------
Function GetRndDigits(intLen,rndType)
    Dim i
    Dim intNum
    Dim intUpper
    Dim intLower
    Dim intRand
    Dim strPartPass
    Dim tmpPassword
 tmpPassword = ""
 Select Case rndType
  Case 1
   intLower = 48
   intUpper = 57
  Case 2
   intLower = 65
   intUpper = 90
 End Select
    '生成随机种子,Rnd将产生0~1之间的随机数
    Randomize
    For i = 1 To intLen
   intNum = Int((intUpper-intLower+1) * Rnd + intLower) '随机产生48~57的整数
   strPartPass = Chr(intNum) '将整数转换成ASCII 0~9字符
   tmpPassword = tmpPassword & strPartPass
    Next
    GetRndDigits = CStr(tmpPassword)
End Function

'------------------------------------------------------------
'Desc: 获得数组的指定值
'Parameter:str   数组
'   splitSign 截取数组的字符串
'   intNum > 0  数组的位置
'CreateBy: Poon@060601
'Example: GetFstar("a,b,c,d",",",1) 返回值为:b
'-----------------------------------------------------------
Function GetFstar(str,splitSign,intNum)
 On Error Resume Next
 Dim errMsg
 Dim splitSTR
 errMsg = "SERVER ERROR"
 If Not Len(intNum) > 0 OR intNum = "" Then GetFstar = errMsg &"00001" : Exit Function
 If Len(str) < intNum OR intNum < 0 Then GetFstar = errMsg &"00002" : Exit Function
 splitSTR = Split(str,splitSign)
 GetFstar = splitSTR(intNum)
End Function

'------------------------------------------------------------------------------------------------------
'Desc: 判断URL的完整程度,来替换或者插入相应的字符
'Parameter:zLink   数据库的URL值   如:www.lingdt.com
'   zDefaultLink 替换或插入的字符  如:http://
'Returns:返回处理的URL的值
'CreateBy: Poon@060601
'Example:GetLinkURL("www.lingdt.com","http://") 返回值为:http://www.lingdt.com
'    GetLinkURL('lingdt.asp","http://www.lingdt.net/") 返回值:http://www.lingdt.net/lingdt.asp
'------------------------------------------------------------------------------------------------------
Function GetLinkURL(zLink,zDefaultLink)
 On Error Resume Next
 Dim errMsg
 errMsg = "SERVER ERROR"
 If Not Len(zDefaultLink) > 0 OR zDefaultLink = "" Then GetLinkURL = errMsg &"00001" : Exit Function
 If Not Len(zLink) > 0 OR zLink = "" Then GetLinkURL = zDefaultLink : Exit Function
 If Instr(1,zLink,zDefaultLink) > 0 Then
  GetLinkURL = zLink
 Else
  GetLinkURL = zDefaultLink & zLink
 End If 
End Function

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值