Good morning John,
For what I'm trying to do, your solution works fine. I was playing with this function and it was giving me the numbers I want in debug.print but I didn't know how to get them back to the query. I used the value of 3 because each trailer has the unit number on it in 3 places.
Public Function CountDigits(UNITID As String)
Dim D1 As Integer
Dim D2 As Integer
Dim D3 As Integer
Dim D4 As Integer
Dim D5 As Integer
Dim TL0 As Integer
Dim TL1 As Integer
Dim TL2 As Integer
Dim TL3 As Integer
Dim TL4 As Integer
Dim TL5 As Integer
Dim TL6 As Integer
Dim TL7 As Integer
Dim TL8 As Integer
Dim TL9 As Integer
D1 = Left(UNITID, 1)
D2 = Mid(UNITID, 2, 1)
D3 = Mid(UNITID, 3, 1)
D4 = Mid(UNITID, 4, 1)
D5 = Mid(UNITID, 5, 1)
TL0 = 0
TL1 = 0
TL2 = 0
TL3 = 0
TL4 = 0
TL5 = 0
TL6 = 0
TL7 = 0
TL8 = 0
TL9 = 0
Select Case D1
Case 0
TL0 = TL0 + 3
Case 1
TL1 = TL1 + 3
Case 2
TL2 = TL2 + 3
Case 3
TL3 = TL3 + 3
Case 4
TL4 = TL4 + 3
Case 5
TL5 = TL5 + 3
Case 6
TL6 = TL6 + 3
Case 7
TL7 = TL7 + 3
Case 8
TL8 = TL8 + 3
Case 9
TL9 = TL9 + 3
End Select
Select Case D2
Case 0
TL0 = TL0 + 3
Case 1
TL1 = TL1 + 3
Case 2
TL2 = TL2 + 3
Case 3
TL3 = TL3 + 3
Case 4
TL4 = TL4 + 3
Case 5
TL5 = TL5 + 3
Case 6
TL6 = TL6 + 3
Case 7
TL7 = TL7 + 3
Case 8
TL8 = TL8 + 3
Case 9
TL9 = TL9 + 3
End Select
Select Case D3
Case 0
TL0 = TL0 + 3
Case 1
TL1 = TL1 + 3
Case 2
TL2 = TL2 + 3
Case 3
TL3 = TL3 + 3
Case 4
TL4 = TL4 + 3
Case 5
TL5 = TL5 + 3
Case 6
TL6 = TL6 + 3
Case 7
TL7 = TL7 + 3
Case 8
TL8 = TL8 + 3
Case 9
TL9 = TL9 + 3
End Select
Select Case D4
Case 0
TL0 = TL0 + 3
Case 1
TL1 = TL1 + 3
Case 2
TL2 = TL2 + 3
Case 3
TL3 = TL3 + 3
Case 4
TL4 = TL4 + 3
Case 5
TL5 = TL5 + 3
Case 6
TL6 = TL6 + 3
Case 7
TL7 = TL7 + 3
Case 8
TL8 = TL8 + 3
Case 9
TL9 = TL9 + 3
End Select
Select Case D5
Case 0
TL0 = TL0 + 3
Case 1
TL1 = TL1 + 3
Case 2
TL2 = TL2 + 3
Case 3
TL3 = TL3 + 3
Case 4
TL4 = TL4 + 3
Case 5
TL5 = TL5 + 3
Case 6
TL6 = TL6 + 3
Case 7
TL7 = TL7 + 3
Case 8
TL8 = TL8 + 3
Case 9
TL9 = TL9 + 3
End Select
Debug.Print "TL0 = " & TL0
Debug.Print "TL1 = " & TL1
Debug.Print "TL2 = " & TL2
Debug.Print "TL3 = " & TL3
Debug.Print "TL4 = " & TL4
Debug.Print "TL5 = " & TL5
Debug.Print "TL6 = " & TL6
Debug.Print "TL7 = " & TL7
Debug.Print "TL8 = " & TL8
Debug.Print "TL9 = " & TL9
End Function
Thanks for your help!!
Doyce
---In MS_Access_Professionals@yahoogroups.com, <JohnV@...> wrote :
John Viescas, author
On Aug 22, 2016, at 06:18, winberry.doyce@... [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Hello Pros,
At my work, we are engaged in a project where we are replacing the unit numbers on groups of trailers. I need a function that will take the unit number and tell me how many of each digit there are, for example unit number 44095 has 1 zero, 2, fours, 1, five and 1 nine. All the unit numbers have five digits. I'm not sure how to approach this. I know how to extract each digit from the unit number and I assume I should use a select case statement to return the value. But I'm not sure how to put it together and get the totals back from the function. I appreciate all help I receive.
Doyce
Posted by: winberry.doyce@con-way.com
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (3) |
Tidak ada komentar:
Posting Komentar