Professional Web Applications Themes

Simple Question: Converting lists to strings - Macromedia Director Basics

Is there a way to use a list in a case statement? Can I substitute myList = [1, 4, 6, 9, 11] in the case statement below? case(myVar) of 1, 4, 6, 9, 11: put "hello" end case Thanks for your help....

  1. #1

    Default Simple Question: Converting lists to strings

    Is there a way to use a list in a case statement? Can I substitute myList =
    [1, 4, 6, 9, 11] in the case statement below?



    case(myVar) of

    1, 4, 6, 9, 11:

    put "hello"

    end case



    Thanks for your help.



    lingo smith Guest

  2. #2

    Default Re: Simple Question: Converting lists to strings

    You can use:

    case (myVar) of
    [1,4,6,11]:
    put "hello"
    end case

    I hope this helps

    Rapha



    "lingo smith" <owieurosieuroxiuerl.com> wrote in message
    news:w7Zfc.2743$L31.676nwrddc01.gnilink.net...
    Is there a way to use a list in a case statement? Can I substitute myList =
    [1, 4, 6, 9, 11] in the case statement below?



    case(myVar) of

    1, 4, 6, 9, 11:

    put "hello"

    end case



    Thanks for your help.




    Raphael Hamzagic Guest

  3. #3

    Default Re: Simple Question: Converting lists to strings

    "Raphael Hamzagic" <raphael_carvalhouol.com.br> wrote in message
    news:c5pnpp$fut$1forums.macromedia.com...
    > You can use:
    >
    > case (myVar) of
    > [1,4,6,11]:
    > put "hello"
    > end case
    Hmm, I thought this was some interesting syntax that I hadn't come across
    before, but it turns out that you are wrong and the above does not compile
    (it doesn't even indent correctly). That's unless it works in MX04, which I
    haven't tried, but it seems unlikely that it would be any different.

    Question is, what is the OP trying to do:

    if( myVar = [1,4,6,11] ) then put "Hello"

    Or:

    if( [1,4,6,11].getPos( myVar ) ) then put "Hello"

    Either way, looks like you need an IF statement. There's no great need to
    use case statements anyway, they are just a way to write certain types of IF
    structure in a way that looks a bit neater, but sometimes they look worse
    anyway, or as in this case, are not very effective (C-style switch
    statements are slightly more flexible, btw).

    - Robert


    Robert Tweed Guest

  4. #4

    Default Re: Simple Question: Converting lists to strings

    The way you are using it will allow the put statement to execute when myVar
    is any one of the values. If you use the list itself, I'm assuming the put
    will execute only when myVar = [1, 4, 6, 9, 11]

    If you want to execute something when a certain value is in the list it
    would probably be better to use a list handler:

    myList = [1, 4, 6, 9, 11]
    if myList.getOne (myVar) <> 0 then
    put "hello"
    end if

    if myVar is any value in that list, the condition will be true
    --
    Craig Wollman
    Word of Mouth Productions

    "lingo smith" <owieurosieuroxiuerl.com> wrote in message
    news:w7Zfc.2743$L31.676nwrddc01.gnilink.net...
    > Is there a way to use a list in a case statement? Can I substitute myList
    =
    > [1, 4, 6, 9, 11] in the case statement below?
    >
    >
    >
    > case(myVar) of
    >
    > 1, 4, 6, 9, 11:
    >
    > put "hello"
    >
    > end case
    >
    >
    >
    > Thanks for your help.
    >
    >
    >

    Word of Mouth Productions Guest

  5. #5

    Default Re: Simple Question: Converting lists to strings

    Robert,

    Shame on you. I thought it would be the day the New York City roaches ruled
    the world that I had one up on you.

    Many things that DON'T work in a case statement without parenthesis will
    work with them. Just put them around the list and it will work.

    A somewhat little known alternative and very useful way of using a case
    statement is

    case TRUE of
    (any expression):

    (another expression):

    (maybe even a list):

    end case

    The cynic in me says that Raphael didn't test his code and wouldn't know it
    wouldn't work the way it was listed.

    My question is, is Mr. smith trying to determine if an item is in the list
    or if his list matches on in the case statement.

    Thanks for the oportunity, Robert.
    --
    Craig Wollman
    Word of Mouth Productions


    "Robert Tweed" <robertNOSPAMkillingmoon.com> wrote in message
    news:c5pp61$ha2$1forums.macromedia.com...
    > "Raphael Hamzagic" <raphael_carvalhouol.com.br> wrote in message
    > news:c5pnpp$fut$1forums.macromedia.com...
    > > You can use:
    > >
    > > case (myVar) of
    > > [1,4,6,11]:
    > > put "hello"
    > > end case
    >
    > Hmm, I thought this was some interesting syntax that I hadn't come across
    > before, but it turns out that you are wrong and the above does not compile
    > (it doesn't even indent correctly). That's unless it works in MX04, which
    I
    > haven't tried, but it seems unlikely that it would be any different.
    >
    > Question is, what is the OP trying to do:
    >
    > if( myVar = [1,4,6,11] ) then put "Hello"
    >
    > Or:
    >
    > if( [1,4,6,11].getPos( myVar ) ) then put "Hello"
    >
    > Either way, looks like you need an IF statement. There's no great need to
    > use case statements anyway, they are just a way to write certain types of
    IF
    > structure in a way that looks a bit neater, but sometimes they look worse
    > anyway, or as in this case, are not very effective (C-style switch
    > statements are slightly more flexible, btw).
    >
    > - Robert
    >
    >

    Word of Mouth Productions Guest

  6. #6

    Default Re: Simple Question: Converting lists to strings

    "Word of Mouth Productions" <lingoboyspamershaveforcedmetofakethisname.com>
    wrote in message news:c5pq4p$i89$1forums.macromedia.com...
    >
    > Shame on you. I thought it would be the day the New York City roaches
    > ruled the world that I had one up on you.
    I think it's happened before. Things do slip through the net from time to
    time :-)
    > Many things that DON'T work in a case statement without parenthesis will
    > work with them. Just put them around the list and it will work.
    Your right it does work, and I didn't think of trying it. I must be tired...
    or maybe the fact I've been working on too many Flash games lately is just
    turning my brain into mush.

    - Robert


    Robert Tweed Guest

  7. #7

    Default Re: Simple Question: Converting lists to strings

    Sorry gentleman....

    I forget the parenthesi as Craig said...

    case (myVar) of
    ([1,4,6,11]):
    put "hello"
    end case


    []s

    Raphael


    "Robert Tweed" <robertNOSPAMkillingmoon.com> wrote in message
    news:c5q2pb$q3t$1forums.macromedia.com...
    "Word of Mouth Productions" <lingoboyspamershaveforcedmetofakethisname.com>
    wrote in message news:c5pq4p$i89$1forums.macromedia.com...
    >
    > Shame on you. I thought it would be the day the New York City roaches
    > ruled the world that I had one up on you.
    I think it's happened before. Things do slip through the net from time to
    time :-)
    > Many things that DON'T work in a case statement without parenthesis will
    > work with them. Just put them around the list and it will work.
    Your right it does work, and I didn't think of trying it. I must be tired...
    or maybe the fact I've been working on too many Flash games lately is just
    turning my brain into mush.

    - Robert



    Raphael Hamzagic Guest

Similar Threads

  1. Simple Questions from Flex Newbie about Links and Lists
    By ggroups@kortina.cjb.net in forum Macromedia Flex General Discussion
    Replies: 0
    Last Post: October 28th, 01:42 AM
  2. SQL Stored Procedures and Lists of Strings
    By Adam72 in forum Coldfusion Database Access
    Replies: 6
    Last Post: February 28th, 03:20 AM
  3. newbie simple strings question
    By Frank in forum Mac Programming
    Replies: 3
    Last Post: October 1st, 05:29 PM
  4. Replies: 10
    Last Post: July 13th, 10:15 PM
  5. Converting Strings to SmallMoney Data Type
    By rwiethorn in forum Microsoft SQL / MS SQL Server
    Replies: 1
    Last Post: July 2nd, 01:52 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