Xuân Thanh > 23-12-13, 06:32 PM
Function SplitNumberString(strMyString As String) As String
    Dim strResults As String, strTemp As String
    Dim i As Integer
    For i = 1 To Len(strMyString)
        strTemp = Mid(strMyString, i, 1)
        If IsNumeric(strTemp) = True Then
            strResults = strResults & strTemp
        End If
    Next
    SplitNumberString = strResults
End Function 
Function SplitNumber(strMyString As String) As Long
    Dim strResults As String, strTemp As String
    Dim i As Integer
    For i = 1 To Len(strMyString)
        strTemp = Mid(strMyString, i, 1)
        If IsNumeric(strTemp) = True Then
            strResults = strResults & strTemp
        End If
    Next
    SplitNumber = Val(strResults)
End Function 
Xuân Thanh > 26-12-13, 07:55 PM
Function SplitNumberDecimal(strMyString As String, Optional DecimalPoint As String) As Long
    Dim strResults As String, strTemp As String
    Dim intResultsIn As Long, intResultsDe As Long
    Dim i As Integer, j As Integer, So As Integer
    For i = 1 To Len(strMyString)
        strTemp = Mid(strMyString, i, 1)
        If IsNumeric(strTemp) = True Or strTemp = DecimalPoint Then
            strResults = strResults & strTemp
        End If
    Next
    For j = 1 To Len(strResults)
        strTemp = Mid(strResults, j, 1)
        If strTemp = DecimalPoint Then
            intResultsIn = Val(Left(strResults, j - 1))
            So = Val(Len(strResults) - j)
            intResultsDe = 10 ^ (-So) * Val(Right(strResults, Len(strResults) - j))
        Else
            intResultsIn = Val(strResults)
            intResultsDe = 0
        End If
    Next
    SplitNumberDecimal = intResultsIn + intResultsDe
End Function 
pntnguyen > 01-08-15, 09:12 PM
maidinhdan > 01-08-15, 11:14 PM
(01-08-15, 09:12 PM)pntnguyen Đã viết: Hỏi: Tôi có một chuỗi ví dụ như "Nguyễn Văn A - Tài khoản ngân hàng VCB (007-201551463)"Xin đóng góp 1 code
Bây giời tôi muốn lấy ra số tài khoản có trong dấu ngoặc đơn ( )
Public Function Laysotrongdaungoac(Tencot As String) As String
' code by maidinhdan
' Khi nao can thi goi ham nhu sau: Laysotrongdaungoac([Tencot])
If Tencot Like "*(*" Then
Laysotrongdaungoac = Replace(Tencot, Left(Tencot, InStr(1, Tencot, "(") - 1), "")
Else
Laysotrongdaungoac = "Chú này không có s" & ChrW(7889) & " tài kho" & ChrW(7843) & "n"
End If
End Function 
![[Hình: Lay%20so%20trong%20ngoac.jpg]](https://sites.google.com/site/thuthuataccess2003/home/demo-hinh/Lay%20so%20trong%20ngoac.jpg)
maidinhdan > 02-08-15, 12:01 AM
(01-08-15, 09:12 PM)pntnguyen Đã viết: Hỏi: Tôi có một chuỗi ví dụ như "Nguyễn Văn A - Tài khoản ngân hàng VCB (007-201551463)"Trả lời bổ sung
Bây giời tôi muốn lấy ra số tài khoản có trong dấu ngoặc đơn ( )
Public Function Laysotrongdaungoac2(Tencot As String) As String
' code by maidinhdan
If Tencot Like "*(*" Then
Laysotrongdaungoac2 = Mid(Tencot, InStr(1, Tencot, "(") + 1, (InStr(1, Tencot, ")") - InStr(1, Tencot, "(")) - 1)
Else
Laysotrongdaungoac2 = "Chú này không có s" & ChrW(7889) & " tài kho" & ChrW(7843) & "n"
End If
End Function 
![[Hình: Lay%20so%20trong%20ngoacII.jpg]](https://sites.google.com/site/thuthuataccess2003/home/demo-hinh/Lay%20so%20trong%20ngoacII.jpg)
Xuân Thanh > 15-08-15, 11:34 AM
ledangvan > 21-08-15, 11:59 AM
(26-12-13, 07:55 PM)Xuân Thanh Đã viết: 3a/ Có bạn lại hỏi tôi : Tôi muốn tách lấy số để tính toán bao gồm cả số thập phân nữa thì làm sao? Ví dụ tách trong dãy số "abnd 12345.567 ghj" để lấy số 12345.567 sử dụng trong tính toán
3b/ Hàm SplitNumberDecimal sau đây sẽ xử lý việc đó
Mã PHP:Function SplitNumberDecimal(strMyString As String, Optional DecimalPoint As String) As Double
Dim strResults As String, strTemp As String
Dim intResultsIn As Double, intResultsDe As Double
Dim i As Integer, j As Integer, So As Integer
For i = 1 To Len(strMyString)
strTemp = Mid(strMyString, i, 1)
If IsNumeric(strTemp) = True Or strTemp = DecimalPoint Then
strResults = strResults & strTemp
End If
Next
For j = 1 To Len(strResults)
strTemp = Mid(strResults, j, 1)
If strTemp = DecimalPoint Then
intResultsIn = Val(Left(strResults, j - 1))
So = Val(Len(strResults) - j)
intResultsDe = 10 ^ (-So) * Val(Right(strResults, Len(strResults) - j))
Else
intResultsIn = Val(strResults)
intResultsDe = 0
End If
Next
SplitNumberDecimal = intResultsIn + intResultsDe
End Function
Hàm này bao trùm cả hàm ở 2a + 2b
Thân mến
ongke0711 > 21-08-15, 12:29 PM
paulsteigel > 21-08-15, 02:16 PM
(21-08-15, 12:29 PM)ongke0711 Đã viết: .....
Function GetOnlyNumber(InputText As String, Optional InputPattern As String = "[\D]") As String
    Dim regObj As Object
    Set regObj = CreateObject("VBScript.RegExp")
    With regObj
        .Global = True
        .MultiLine = False
        .IgnoreCase = False
        .Pattern = InputPattern
        If .Test(InputText) Then GetOnlyNumber = .Replace(InputText, "")
    End With
    Set regObj = Nothing
End Functionongke0711 > 21-08-15, 04:45 PM