系列数字提取函数
时 间:2011-03-04 00:00:00
作 者:羽扇子君 ID:15117 城市:铁岭
摘 要:类似于Office打印中的页范围提取
如:"20405,7,1-3,20304-20306"分析结果为:20405,20407,20401,20402,20403,20304,20305,20306
正 文:
Function theNumsAnalysis(TempString As String) As Variant '数字分析
'作用: 分析 TempString 的内容,以方便处理有关系或连续的数字 (类似于Office打印中的页范围)
'参数: TempString 以“,”、“-”分隔的字符串.如:"20405,7,1-3,20304-20306"分析结果为:20405,20407,20401,20402,20403,20304,20305,20306
'返回值:- Null 没有内容时,返回null
' - 下标从0开始的1维数组
Dim theTemp As Variant, theTemp1 As Variant, theTemp2 As Variant, varitm As Variant, i As Integer, j As Long, FirstLen As Byte
Dim Temp1 As String, Temp2 As String, MinusLen As Byte
If Isnull(TempString) Then 'Null值情况
theNumsAnalysis = Null
Exit Function
End If
theTemp = Split(TempString, ",")
If InStr(theTemp(0), "-") > 0 Then '如果包含"-"
theTemp1 = Trim(Left(theTemp(0), InStr(theTemp(0), "-") - 1)) '取出"-"前面的内容
Else
theTemp1 = theTemp(0)
End If
FirstLen = Len(theTemp1)
For Each varitm In theTemp
If InStr(varitm, "-") > 0 Then
MinusLen = InStr(varitm, "-") '得到"-"位置
Temp2 = Trim(Right(varitm, Len(varitm) - MinusLen))
Temp1 = Right(Trim(Left(varitm, MinusLen - 1)), Len(Temp2))
For j = Val(Temp1) To Val(Temp2)
If i = 0 Then
theTemp2 = Left(theTemp1, FirstLen - Len(Temp2)) & j
Else
theTemp2 = theTemp2 & "," & Left(theTemp1, Abs(FirstLen - Len(Temp2))) & j
End If
i = i + 1
Next j
Else
If i = 0 Then
theTemp2 = Left(theTemp1, Len(theTemp1) - Len(varitm)) & varitm
Else
theTemp2 = theTemp2 & "," & Left(theTemp1, Len(theTemp1) - Len(varitm)) & varitm
End If
End If
i = i + 1
Next varitm
theNumsAnalysis = Split(theTemp2, ",")
End Function
调用试例:
Function a()
Dim theTemp1 As Variant
theTemp1 = theNumsAnalysis("20405,7,1-3,20304-20306")
MsgBox Join(theTemp1, "、")
End Function
Access软件网QQ交流群 (群号:54525238) Access源码网店
常见问答:
技术分类:
源码示例
- 【源码QQ群号19834647...(12.17)
- Access对子窗体数据进行批...(10.30)
- 最精简的组合框行来源数据快速输...(10.25)
- Access仿平台的多值选择器...(10.24)
- 【Access日期区间段查询】...(10.22)
- 【Access源码示例】VBA...(10.12)
- Access累乘示例,Acce...(10.09)
- 数值8.88,把整数8去掉,转...(10.08)
- 【Access自定义函数】一个...(09.30)
- 【Access选项卡示例】Ac...(09.09)
学习心得
最新文章
- Access快速开发平台--对上传...(11.22)
- Access快速开发平台企业版--...(11.18)
- 不会用多表联合查询,多表查询没结果...(11.16)
- 【案例分享】主键字段值含有不间断空...(11.16)
- Access快速开发平台--后台D...(11.14)
- 微软Access邀测新Monaco...(11.12)
- Access列表框左右互选、列表框...(11.11)
- 高效率在导入数据前删除记录(11.10)
- Access报价单转订单示例代码(11.08)
- Access系统自带的日期选择器不...(11.08)