Odd function problem

Discussion in 'ASP General' started by Mike, Jan 15, 2006.

  1. Mike

    Mike Guest

    I have a function as follows:

    function docolors(Rstart,Gstart,Bstart,color,incrementer)
    r=Rstart
    g=Gstart
    b=Bstart
    response.write "<div><table><tr>"
    for color = 0 to 255
    response.write "<td style=""background-color:rgb"
    response.write "(" & r & "," & g & "," & b & ");"">"
    response.write "<a href=""#"" title=""R"
    response.write r & ":G" & g & ":B" & b & """>"
    response.write "&nbsp;&nbsp;&nbsp;</a></td>"
    color=color+incrementer
    next
    response.write "</tr></table></div>"
    end function

    When its called thus:

    docolors 0,0,0,r,9

    it increments the value of red by 9 and writes 26 table cells to the
    page gradually going from black to red (which is what I want).

    I have a form to collect user provided values for the function's
    arguments and dynamically build a call to docolors() using the form
    field values:
    <%
    sub dropdown()
    for i = 0 to 255
    response.write "<option value=""" & i & """>" & i & "</option>" &
    vbcrlf
    next
    end sub
    %>
    <form action="" method="post">
    <strong>Start Values</strong><br />
    Red:<select name="r">
    <%
    dropdown
    %>
    </select>
    Green:<select name="g">
    <%
    dropdown
    %>
    </select>
    Blue:<select name="b">
    <%
    dropdown
    %>
    </select><br /><br />
    <strong>Colour to increment value of:</strong><br />
    <input type="radio" name="c" value="r" />Red<br />
    <input type="radio" name="c" value="g" />Green<br />
    <input type="radio" name="c" value="b" />Blue<br /><br />
    <strong>Incrementer:</strong><br />
    <select name="i">
    <%
    dropdown
    %>
    </select><br />
    <input type="submit" name="submit" value="Submit" />
    </form>

    <%
    x=cint(request.form("r"))
    y=cint(request.form("g"))
    z=cint(request.form("b"))
    h=trim(cstr(request.form("c")))
    i=cint(request.form("i"))

    docolors x,y,z,h,i
    %>

    and it seems that all the values translate correctly if I
    response.write the whole lot:

    response.write "call docolors(" & x & "," & y & "," & z & "," & h & ","
    & i & ")<br />"

    but the thing fails to increment the value of h - the paramenter that
    goes where color is in the function. x,y,z,and i all work as expected.

    My logic is clearly faulty somewhere. Can anyone see where?

    TIA

    Mike
     
    Mike, Jan 15, 2006
    #1
    1. Advertising

  2. Mike

    Paxton Guest

    Dave Anderson wrote:
    > Mike wrote:
    > > function docolors(Rstart,Gstart,Bstart,color,incrementer)
    > > r=Rstart
    > > g=Gstart
    > > b=Bstart
    > > response.write "<div><table><tr>"
    > > for color = 0 to 255
    > > response.write "<td style=""background-color:rgb"
    > > response.write "(" & r & "," & g & "," & b & ");"">"
    > > response.write "<a href=""#"" title=""R"
    > > response.write r & ":G" & g & ":B" & b & """>"
    > > response.write "&nbsp;&nbsp;&nbsp;</a></td>"
    > > color=color+incrementer
    > > next
    > > response.write "</tr></table></div>"
    > > end function

    >
    > ...
    >
    > > but the thing fails to increment the value of h - the
    > > paramenter that goes where color is in the function.
    > > x,y,z,and i all work as expected.

    >
    >
    > You are ignoring the parameter [color] and initializing it to 0 in your
    > loop.
    >
    >
    > --
    > Dave Anderson
    >


    Thank, Dave. I've rewritten it and it works as expected now:

    function docolors(Rstart,Gstart,Bstart,color,incrementer)
    dim r,g,b,i
    r=Rstart
    g=Gstart
    b=Bstart
    response.write "<div><table><tr>"
    select case color
    case "r"
    for i = r to 255
    response.write "<td style=""background-color:rgb"
    response.write "(" & i & "," & g & "," & b & ");"">"
    response.write "<a href=""#"" title=""R"
    response.write i & ":G" & g & ":B" & b & """>"
    response.write "&nbsp;&nbsp;&nbsp;</a></td>"
    i=i+incrementer
    next
    case "g"
    for i = g to 255
    response.write "<td style=""background-color:rgb"
    response.write "(" & r & "," & i & "," & b & ");"">"
    response.write "<a href=""#"" title=""R"
    response.write r & ":G" & i & ":B" & b & """>"
    response.write "&nbsp;&nbsp;&nbsp;</a></td>"
    i=i+incrementer
    next
    case "b"
    for i = b to 255
    response.write "<td style=""background-color:rgb"
    response.write "(" & r & "," & g & "," & i & ");"">"
    response.write "<a href=""#"" title=""R"
    response.write r & ":G" & g & ":B" & i & """>"
    response.write "&nbsp;&nbsp;&nbsp;</a></td>"
    i=i+incrementer
    next
    end select
    response.write "</tr></table></div>"
    end function

    Mike
     
    Paxton, Jan 17, 2006
    #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. Jake Thompson

    odd problem in called function

    Jake Thompson, Jan 6, 2006, in forum: C Programming
    Replies:
    0
    Views:
    288
    Jake Thompson
    Jan 6, 2006
  2. Jake Thompson

    Odd problem with called function in DLL

    Jake Thompson, Jan 6, 2006, in forum: C Programming
    Replies:
    0
    Views:
    321
    Jake Thompson
    Jan 6, 2006
  3. Michael Speer

    Odd behavior with odd code

    Michael Speer, Feb 16, 2007, in forum: C Programming
    Replies:
    33
    Views:
    1,159
    Richard Heathfield
    Feb 18, 2007
  4. Replies:
    8
    Views:
    328
    Richard
    Oct 5, 2007
  5. Jeff Stewart

    Odd behavior involving function.apply()

    Jeff Stewart, Jul 19, 2006, in forum: Javascript
    Replies:
    3
    Views:
    109
    Richard Cornford
    Jul 19, 2006
Loading...

Share This Page