Results 1 to 6 of 6

Thread: list data

  1. #1

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    list data

    VB Code:
    1. If List1.List(0) = List1.List(1) And List1.List(1) = List1.List(2) And List1.List(2) = List1.List(3) And List1.List(3) = List1.List(4) Then
    2. fivekind.Enabled = True
    3. End If
    In this code, you can see that if five bits of data in a list are the same, a button named "fivekind" is enabled.

    This is my problem: how would I get the program to check that only 4 bits of data are the same? I tried it just now and it looked like i needed, if anything, too many lines of code to do that using the method above.

    Is there a simpler way of doing this?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: list data

    VB Code:
    1. dim matches() as integer
    2. redim matches(list1.listcount-1)
    3. for a = 0 to list1.listcount-1
    4.   matches(a) = 1
    5.   for b = 0 to list1.listcount-1
    6.     if a = b then GoTo NextB
    7.     if list1.list(a) = list1.list(b) then
    8.        matches(a) = matches(a)+1
    9.     end if
    10. NextB:
    11.   next b
    12. next a
    Last edited by Atheist; Dec 2nd, 2005 at 01:04 PM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: list data

    So for example if the word "Cat" is on listindex nr 7 in your list, just type this:
    VB Code:
    1. msgbox matches(7)
    and you'll get the number of times the line "Cat" was found in the list
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: list data

    oops found some small errors in there. Ive edited the code, its working alright now
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: list data

    but if the list item is a number, and if i wanted for it to check if any of the numbers appear 4 times, how would i do that?

  6. #6
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: list data

    just use my code and add this:

    VB Code:
    1. for a = 0 to ubound(matches)
    2.     if matches(a) = 4 then
    3.         msgbox list1.list(a) & " appears 4 times."
    4.     end if
    5. next a
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

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