Results 1 to 3 of 3

Thread: how to track the first digit appear the most in listbox?

  1. #1

    Thread Starter
    Lively Member Satangel's Avatar
    Join Date
    Aug 2000
    Location
    KL,Malaysia
    Posts
    85

    Lightbulb how to track the first digit appear the most in listbox?

    how to track the first digit (item)which appear the most and the least in listbox?

    i was wondering are they any function to track the first digit appear the most in the listbox data.

    Eg. like if my listbox have some item like this:

    "Listbox"

    ===========
    = 1234 =
    = 4567 =
    = 8890 =
    = 5656 =
    = 7890 =
    = 4264 =
    = 1889 =
    = 9009 =
    = 3434 =
    ===========


    When i press cmdCheckTop, the result will be
    1
    bcos the first digit appear the most is 1.
    it contains two time appear("1234" and "1889")

    How to do it?
    anybody knows?






  2. #2
    Lively Member
    Join Date
    Jul 2000
    Posts
    94

    Smile Parsing...

    Hi,

    You could try this:

    Dim ariDigits(0 To 9) As Integer
    Dim i, iHold As Integer

    For iHold = 0 To 9
    For i = 0 To lstNumbers.ListCount - 1
    If Mid$(lstNumbers.List(i),1,1) = iHold Then
    'increases number of this digit found
    ariDigits(iHold) = ariDigits(iHold) + 1
    Next i
    Next iHold

    The array ariDigits will then hold the largest number in the element that has the subscript corresponding to the most common leading digit.

    Gulliver.

  3. #3
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    To get you started, but you must ammend to make it work if two numbers have the same max count.

    Code:
    Private Sub Command1_Click()
    Dim i&
    Dim ar(1 To 10) As Byte
    Dim pos As Byte, max As Byte, maxc As Byte
    For i = 0 To List1.ListCount - 1
        pos = Left(List1.List(i), 1)
        ar(pos) = ar(pos) + 1
    Next
    For i = 1 To 10
        If ar(i) > maxc Then max = i: maxc = ar(i)
    Next
    MsgBox max
    End Sub
    
    Private Sub Form_Load()
    Me.List1.AddItem 1234
    Me.List1.AddItem 4567
    Me.List1.AddItem 8890
    Me.List1.AddItem 5656
    Me.List1.AddItem 7890
    Me.List1.AddItem 4264
    Me.List1.AddItem 1889
    Me.List1.AddItem 9009
    Me.List1.AddItem 3434
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width