Professional Web Applications Themes

Newbie List question - Macromedia Director Basics

Hi, I've created a movie during the process of which a list is created. AnswersList = ["H10", "A05", "H10"] Now all I want to do is count how many times a specific answer is given, so in this case I'd like to count how many times "H10" is listed. I know of the count command, but that only seems to count the number of items in the list, which is not what I want to do. Can anyone help ?...

  1. #1

    Default Newbie List question

    Hi,

    I've created a movie during the process of which a list is created.

    AnswersList = ["H10", "A05", "H10"]

    Now all I want to do is count how many times a specific answer is given, so
    in this case I'd like to count how many times "H10" is listed.
    I know of the count command, but that only seems to count the number of
    items in the list, which is not what I want to do.

    Can anyone help ?


    Somnifer Guest

  2. #2

    Default Re: Newbie List question

    You will need to go through the items in the list, one at a time and
    try and match the item in the list with the string that you have for
    comparison. Something like this might work:

    on countInstances theList,theString
    thisManyItems = theList.count
    tempCounter = 0
    repeat with n = 1 to thisManyItems
    if theList[n] = theString then
    tempCounter = tempCounter + 1
    end if
    end repeat
    return tempCounter
    end

    then you could call that function like this:

    on mouseUp me
    itemCount = countInstances(AnswersList,"H10")
    end

    --
    Rob
    _______
    Rob Dillon
    Team Macromedia
    [url]http://www.ddg-designs.com[/url]
    412-243-9119

    [url]http://www.macromedia.com/software/trial/[/url]
    Rob Dillon Guest

  3. #3

    Default Re: Newbie List question

    To check for items in the list you'll have to compare each item in the list to the answer you're looking for. You can do this fairly easily with a repeat loop. Something like this:

    answerCount = 0 -- a variable to count the answers with
    repeat with anAnswer in AnswerList
    if anAnswer = "H10" then
    answerCount = answerCount + 1
    end if
    end repeat

    You could also make this a function so you could check for any answer, or modify it to make a tally of each type of answer.

    Another way to tally the "H10" answers would be to increment a variable every time it gets added to the list. Doing it this way would mean you wouldn't have to loop through the list when you're done

    Let me know if this helps, or if you have any questions. Thanks

    Nathan
    Nathan Friesen Guest

  4. #4

    Default Re: Newbie List question

    Thanks a lot (both of you) ! This did the trick !


    "Rob Dillon" <robddg-designs.com> schreef in bericht
    news:301220030941138898%robddg-designs.com...
    > You will need to go through the items in the list, one at a time and
    > try and match the item in the list with the string that you have for
    > comparison. Something like this might work:
    >
    > on countInstances theList,theString
    > thisManyItems = theList.count
    > tempCounter = 0
    > repeat with n = 1 to thisManyItems
    > if theList[n] = theString then
    > tempCounter = tempCounter + 1
    > end if
    > end repeat
    > return tempCounter
    > end
    >
    > then you could call that function like this:
    >
    > on mouseUp me
    > itemCount = countInstances(AnswersList,"H10")
    > end
    >
    > --
    > Rob
    > _______
    > Rob Dillon
    > Team Macromedia
    > [url]http://www.ddg-designs.com[/url]
    > 412-243-9119
    >
    > [url]http://www.macromedia.com/software/trial/[/url]

    Somnifer Guest

Similar Threads

  1. Newbie needs help with list box population
    By Rigga in forum PHP Development
    Replies: 4
    Last Post: November 17th, 01:52 PM
  2. [newbie] list elements
    By Guest1 in forum PERL Miscellaneous
    Replies: 13
    Last Post: September 5th, 08:19 PM
  3. [PHP] Looping through a list - Newbie question
    By Javier Tacon in forum PHP Development
    Replies: 2
    Last Post: August 27th, 03:45 PM
  4. Looping through a list - Newbie question
    By Jean-Christian Imbeault in forum PHP Development
    Replies: 0
    Last Post: August 27th, 04:17 AM
  5. list question (creating one list out of many)
    By Rob Dillon in forum Macromedia Director Lingo
    Replies: 0
    Last Post: August 4th, 01:29 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139