Re: Calculate Last Digits
- From: "Robert Morley" <rmorley@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 20 Oct 2007 22:32:41 -0400
See possible code improvement, in-line:
Private Sub UpdateCounts()
Dim Cnt(0 To 9) As Long
Dim n As Long
Dim j As Long
Dim max As Long
Dim pattern As String
For n = 1 To 6
Cnt(LastDigits(n)) = Cnt(LastDigits(n)) + 1
Next n
For n = 1 To 6
max = 0
For j = 0 To 9
If Cnt(j) > Cnt(max) Then
max = j
End If
This might work faster by adding the following line at this point:
If Cnt(j) >= 3 Then Exit For
(Or use whatever method you prefer to exit the For Loop...personally I avoid Exit For, as discussed at enormous length in older
threads <g>, but this is the easiest change given the existing code.) This works because you KNOW if your count is greater than or
equal to 3, there won't be anything higher, and you can add it to the string right away. On the other hand, the extra comparison
may end up slowing things down more than it speeds them up. Try it both ways and see.
Next j
pattern = pattern & Cnt(max)
Cnt(max) = 0
Next n
For n = 1 To UBound(Map)
If Map(n) = pattern Then
Counts(n) = Counts(n) + 1
Exit For
End If
Next n
End Sub
Rob
.
- Follow-Ups:
- Re: Calculate Last Digits
- From: Steve Gerrard
- Re: Calculate Last Digits
- References:
- Calculate Last Digits
- From: Paul Black
- Re: Calculate Last Digits
- From: Robert Morley
- Re: Calculate Last Digits
- From: Robert Morley
- Re: Calculate Last Digits
- From: Steve Gerrard
- Re: Calculate Last Digits
- From: Steve Gerrard
- Calculate Last Digits
- Prev by Date: Re: VB6 LISTBOX problem
- Next by Date: Re: OTsort of but not really, Nvidia issue that affects all apps.
- Previous by thread: Re: Calculate Last Digits
- Next by thread: Re: Calculate Last Digits
- Index(es):
Relevant Pages
|