Senin, 22 Agustus 2016

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

 

Hi Doyce


I'm not sure what format you want your output in, but you can use an array to count the digits and return the result in whatever format you like - for example:

Public Function CountDigits(ByVal Number As Long) As String
Dim aDigits(0 To 9) As Integer
Dim iDigit As Integer
Dim sResult As String
  Do
    iDigit = Abs(Number Mod 10)
    aDigits(iDigit) = aDigits(iDigit) + 1
    Number = Number \ 10
  Loop Until Number = 0
  For iDigit = 0 To 9
    If aDigits(iDigit) <> 0 Then
      sResult = sResult & aDigits(iDigit) & "x" & iDigit & ", "
    End If
  Next
  CountDigits = Left(sResult, Len(sResult) - 2)
End Function

Best wishes,
Graham [Access MVP 1996-2015]


---In MS_Access_Professionals@yahoogroups.com, <winberry.doyce@...> 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: graham@mandeno.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (4)

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:

Poskan Komentar