【Access自定义函数】字符串中数字相关的几个自定义函数
时 间:2013-02-06 05:52:28
作 者:网行者 ID:12122 城市:江门
摘 要:字符串中数字相关的几个函数
正 文:
Public Function IsNumbersOnly(chkStr As String) As Boolean
'检测字符串是否全部由数字组成
Dim i As Long
Const AllNumbers = "0123456789"
IsNumbersOnly = True
For i = 1 To Len(chkStr)
If InStr(AllNumbers, Mid(chkStr, i, 1)) = 0 Then
IsNumbersOnly = False
Exit Function
End If
Next i
End Function
Public Function NumberPos(chkStr As String) As Long
'检测字符串中第一个数字的位置
'函数值为0时,表示字符串中不包含数字
Dim i As Long
For i = 1 To Len(chkStr)
If Mid(chkStr, i, 1) Like "[0-9]" Then
NumberPos = i
Exit Function
End If
Next i
End Function
Public Function NoNumbers(chkStr As String) As Boolean
' 检测字符串中是否不含数字
Dim i As Long
NoNumbers = True
For i = 1 To Len(chkStr)
If Mid(chkStr, i, 1) Like "[0-9]" Then
NoNumbers = False
Exit Function
End If
Next i
End Function
Public Function NumberGet(chkStr As String) As String
'从字符串中提取数字
Dim i As Integer
For i = 1 To Len(chkStr)
If Mid(chkStr, i, 1) Like "[0-9]" Then
NumberGet = NumberGet & Mid(chkStr, i, 1)
End If
Next i
NumberGet = NumberGet
End Function
Public Function CutStr(chkStr As String) As String
'截取字符串中第一个数字前的字符
Dim i As Long
For i = 1 To Len(chkStr)
If Mid(chkStr, i, 1) Like "[0-9]" Then
CutStr = Left(chkStr, i - 1)
Exit Function
End If
Next i
CutStr = chkStr
End Function
Public Function CutN(chkStr As String) As String
'剔除字符串中的数字
Dim ObjStr As String
Dim LngStr As Long
Dim i As Long
For i = 1 To Len(chkStr)
LngStr = Asc(Mid(chkStr, i, 1))
If LngStr < 48 or LngStr > 57 Then
CutN = CutN + Mid(chkStr, i, 1)
End If
Next i
End Function
Public Function SortNumber_1(MyString As String) As String
'提取不重复数字并从小到大排列
Dim i As Integer
Dim Str As String
For i = 0 To 9
If InStr(1, MyString, i) > 0 Then
Str = Str & i
End If
Next
SortNumber_1 = Str
End Function
Public Function SortNumber_2(MyString As String) As Double
'提取不重复数字并从大到小排列
Dim i As Integer
Dim Str As String
For i = 9 To 0 Step -1
If InStr(1, MyString, i) > 0 Then
Str = Str & i
End If
Next
SortNumber_2 = Str
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)