Senin, 22 Agustus 2016

Re: [MS_AccessPros] Need to know how many of each digit in a series of unit numbers.



Sure wish our old pal, A.D. Tejpal, was still around - I'm sure he would have an elegant solution.

Do you want all ten counts returned in one function call, or do you want to call the function 10 times?

Simple call for each digit:

intNine = CountDigit(Me.UnitNumber, 9)

Function CountDigit(lngUnit As Long, intDigit As Integer) As Integer
Dim strUnit As String, intCount As Integer, intI As Integer

    ' Convert the input number to a string
    strUnit = Format(lngUnit, "00000")
    For intI = 1 To 5
        If Mid(strUnit, intI, 1) = intDigit Then intCount = intCount + 1
    Next intI

     ' Return the answer
     CountDigit = intCount
End Function 

John Viescas, author
Effective SQL
SQL Queries for Mere Mortals
Microsoft Office Access 2010 Inside Out
Microsoft Office Access 2007 Inside Out
Building Access Applications

On Aug 22, 2016, at 06:18, [MS_Access_Professionals] <> 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.



Posted by: John Viescas <>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.



Tidak ada komentar:

Posting Komentar