【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)
- Access制作的RGB转CM...(09.22)
- Access制作的RGB调色板...(09.15)
- Access制作的快速车牌输入...(09.13)
- 【Access高效办公】统计当...(06.30)
- 【Access高效办公】用复选...(06.24)
- 根据变化的日期来自动编号的示例...(06.20)
- 【Access高效办公】按日期...(06.12)
- 合并列数据到一个文本框的示例;...(05.06)
 
  学习心得
最新文章
- 【Access高效办公】上一年度累...(10.30)
- Access做的一个《中华经典论语...(10.25)
- Access快速开发平台--加载事...(10.20)
- 【Access有效性规则示例】两种...(10.10)
- EXCEL表格扫描枪数据录入智能处...(10.09)
- Access快速开发平台--多行文...(09.28)
- 关于从Excel导入长文本数据到A...(09.24)
- Access制作的RGB转CMYK...(09.22)
- 关于重装系统后Access开发的软...(09.17)
- Access制作的RGB调色板示例(09.15)
 

 
  
.gif)

 
            