Access快速开发基础教程
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

分解特殊字符:“123456789012345678-80/95”

时 间:2017-08-03 14:56:22
作 者:易勋   ID:35404  城市:上海
摘 要:分解特殊字符:“123456789012345678-80/95”
123456789012345678
123456789012345679
123456789012345680
123456789012345695
正 文:

函数:
Public Function SplitInCo(strChar As String) As String
    Dim strInvoiceNumber As String
    Dim strInvoiceCode As String
    Dim intS As Integer
    Dim intLen As Integer
    Dim inti As Integer
    Dim strInv As String
    Dim strTemp As String
    Dim strType As String
    Dim arrInvoice() As String
    Dim intArr As Integer
    Dim strInvoice As String
    Dim lngInv As Long
    Dim strFormat As String
    intLen = Len(strChar)
    
    Select Case intLen
    Case Is < 18
        SplitInCo = ""
    Case Is = 18
        If Not strChar Like "*-*" And Not strChar Like "/" Then
            SplitInCo = strChar
            strInvoiceCode = Left(strChar, 10)
            strInvoiceNumber = Right(strChar, 8)
        Else
            SplitInCo = ""
        End If
    Case 19
        SplitInCo = ""
    Case Is > 19
        If Mid(strChar, 19, 1) = "-" or Mid(strChar, 19, 1) = "/" Then
            strInvoice = Left(strChar, 18)
            intArr = 0
            inti = 0
            strType = Mid(strChar, 19, 1)
            
            For intS = 20 To intLen
                strTemp = Mid(strChar, intS, 1)
                strInv = strInv & strTemp
                If strTemp = "-" or strTemp = "/" or intS = intLen Then
                    If intS <> intLen Then
                        strInv = Left(strInv, Len(strInv) - 1)
                    End If
                    
                    Select Case strType
                    Case "-"
                        For inti = 1 To Len(strInv)
                            strFormat = strFormat & "0"
                        Next
                        If Val(Right(Split(strInvoice, "|")(intArr), Len(strInv))) < Val(strInv) Then
                            For lngInv = Val(Right(Split(strInvoice, "|")(intArr), Len(strInv))) + 1 To Val(strInv)
                                strInvoice = strInvoice & "|" & Left((Split(strInvoice, "|")(intArr)), 18 - Len(strInv)) & Format(lngInv, strFormat)
                                intArr = intArr + 1
                            Next
                        End If
                        strFormat = ""
                    Case "/"
                        If Len(strInv) <= 8 Then
                            strInvoice = strInvoice & "|" & Left((Split(strInvoice, "|")(intArr)), 18 - Len(strInv)) & strInv
                            intArr = intArr + 1
                        Else
                            strInvoice = strInvoice & "|" & strInv
                            intArr = intArr + 1
                        End If
'                    Case Else
'                        strInvoice = strInvoice & "|Error"
                    End Select
                    strInv = ""
                    strType = strTemp
                End If
            Next
            SplitInCo = intArr + 1
            SplitInCo = strInvoice
        Else
            SplitInCo = ""
        End If
    End Select
    

End Function
用法:
SplitInCo("123456789012345678-80/95")


Access软件网官方交流QQ群 (群号:312594938)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助