Writing out array values

Discussion in 'ASP General' started by JP SIngh, Jul 20, 2004.

  1. JP SIngh

    JP SIngh Guest

    Please help me with this

    I have an array which has days of the month stored in it. For example at one
    time it might have the values

    1,2,3,6,7,8,9

    at another time it might have the value

    4,5,12,14,19,25

    These are days of the month that have been selected and read into an array.
    What i would like to do is to write them out and put a "X" where the days
    were selected

    Somthing like this

    For i = 1 to 31
    if i is found in the array
    response.write "X"
    else
    response.write "-"
    end if
    Next
    I cannot figure out how to search an array for the values

    for example the output of the first example should be

    1 2 3 4 5 6 7 8 9 10 11 12 ......
    X X X - - X X X X - - -
    JP SIngh, Jul 20, 2004
    #1
    1. Advertising

  2. JP SIngh

    Catalyst Guest

    "JP SIngh" <> wrote in
    news::

    > Please help me with this
    >
    > I have an array which has days of the month stored in it. For example
    > at one time it might have the values
    >
    > 1,2,3,6,7,8,9
    >
    > at another time it might have the value
    >
    > 4,5,12,14,19,25
    >
    > These are days of the month that have been selected and read into an
    > array. What i would like to do is to write them out and put a "X"
    > where the days were selected
    >
    > Somthing like this
    >
    > For i = 1 to 31
    > if i is found in the array
    > response.write "X"
    > else
    > response.write "-"
    > end if
    > Next
    > I cannot figure out how to search an array for the values
    >
    > for example the output of the first example should be
    >
    > 1 2 3 4 5 6 7 8 9 10 11 12 ......
    > X X X - - X X X X - - -
    >
    >
    >


    Are you set on doing this with two arrays?. If so you'll have to search
    through the entire array 31 times, which is slow.

    I would recommend using something else like a dictionary object or even
    a single array.

    Try creating an array with 31 values and initialize each value to false
    with a quick loop. Then you can set individual values to true if they're
    selected, like

    ary(27) = true

    for each selected day. This will make it easy to check if a day is
    selected, all you need to do is

    For i = 1 to 31
    if ary(i) then
    response.write "X"
    else
    response.write "-"
    end if
    Next

    --
    Catalyst
    www.webforumz.com
    Free Web Design and Development Help, Discussions, tips and Critique!
    ASP, VB, .NET, SQL, CSS, HTML, Javascript, Flash, XML, SEO !
    Catalyst, Jul 20, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HNguyen
    Replies:
    4
    Views:
    2,384
    HNguyen
    Dec 21, 2004
  2. Replies:
    1
    Views:
    456
  3. shrutisunder
    Replies:
    0
    Views:
    464
    shrutisunder
    Mar 11, 2009
  4. Noname

    getting Values out of <Array>

    Noname, Aug 3, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    56
    Charles DeRykus
    Aug 4, 2004
  5. Replies:
    11
    Views:
    173
    Zvt.Fred
    Apr 13, 2009
Loading...

Share This Page