【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)
- 统计当月之前(不含当月)的记录...(03.11)
- 【Access Inputbo...(03.03)
- 按回车键后光标移动到下一条记录...(02.12)
- 【Access Dsum示例】...(02.07)
- Access对子窗体的数据进行...(02.05)
- 【Access高效办公】上月累...(01.09)
- 【Access高效办公】上月累...(01.06)
- 【Access Inputbo...(12.23)
- 【Access Dsum示例】...(12.16)

学习心得
最新文章
- 仓库管理实战课程(9)-开发往来单...(04.02)
- 仓库管理实战课程(8)-商品信息功...(04.01)
- 仓库管理实战课程(7)-链接表(03.31)
- 仓库管理实战课程(6)-创建查询(03.29)
- 仓库管理实战课程(5)-字段属性(03.27)
- 设备装配出入库管理系统;基于Acc...(03.24)
- 仓库管理实战课程(4)-建表操作(03.22)
- 仓库管理实战课程(3)-需求设计说...(03.19)
- 仓库管理实战课程(2)-软件背景和...(03.18)
- 仓库管理实战课程(1)-讲师介绍(03.16)