Odd function problem | | |
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 " </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 | | | | re: Odd function problem
Mike wrote:[color=blue]
> 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 " </a></td>"
> color=color+incrementer
> next
> response.write "</tr></table></div>"
> end function[/color]
....
[color=blue]
> 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.[/color]
You are ignoring the parameter [color] and initializing it to 0 in your
loop.
--
Dave Anderson
Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting. | | | | re: Odd function problem
Dave Anderson wrote:[color=blue]
> Mike wrote:[color=green]
> > 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 " </a></td>"
> > color=color+incrementer
> > next
> > response.write "</tr></table></div>"
> > end function[/color]
>
> ...
>[color=green]
> > 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.[/color]
>
>
> You are ignoring the parameter [color] and initializing it to 0 in your
> loop.
>
>
> --
> Dave Anderson
>[/color]
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 " </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 " </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 " </a></td>"
i=i+incrementer
next
end select
response.write "</tr></table></div>"
end function
Mike |  | Similar ASP / Active Server Pages bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|