|
楼主 |
发表于 2010-4-29 08:52
|
显示全部楼层
为了报答大家的厚爱又来个自定义函数!!!
本函数是一个综合分离函数!希望给大家有所帮助和启示!!
'本函数的关节点是运用了默认参数,当缺省时就用默认值.
'第二点是充分运用了ASCⅡ码来判断.
Function fenli(a As String, Optional x As Integer = 0, Optional f As Boolean = True)
Dim b As String
Dim i As Integer
Dim j As Integer
Dim c As String
i = Len(a)
Select Case x
Case 1
If f Then
For j = 1 To i
b = Mid(a, j, 1)
If Asc(b) >= 48 And Asc(b) <= 57 Then c = c + b
Next j
Else
For j = i To 1 Step -1
b = Mid(a, j, 1)
If Asc(b) >= 48 And Asc(b) <= 57 Then c = c + b
Next j
End If
fenli = Val(Trim(c))
Case 2
If f Then
For j = 1 To i
b = Mid(a, j, 1)
If (Asc(b) >= 65 And Asc(b) <= 90) Or (Asc(b) >= 97 And Asc(b) <= 122) Then c = c + b
Next j
Else
For j = i To 1 Step -1
b = Mid(a, j, 1)
If (Asc(b) >= 65 And Asc(b) <= 90) Or (Asc(b) >= 97 And Asc(b) <= 122) Then c = c + b
Next j
End If
fenli = Trim(c)
Case Else
If f Then
For j = 1 To i
b = Mid(a, j, 1)
If Asc(b) < 0 Then c = c + b
Next j
Else
For j = i To 1 Step -1
b = Mid(a, j, 1)
If Asc(b) < 0 Then c = c + b
Next j
End If
fenli = Trim(c)
End Select
End Function |
|