469,286 Members | 2,442 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,286 developers. It's quick & easy.

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 "&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

Jan 15 '06 #1
2 1330
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

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.
Jan 16 '06 #2

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

Jan 17 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Kostatus | last post: by
3 posts views Thread by Jan-Henrik Grobe | last post: by
18 posts views Thread by jimfortune | last post: by
4 posts views Thread by Andy_Khosravi | last post: by
7 posts views Thread by Mike D. | last post: by
2 posts views Thread by Fernando Barsoba | last post: by
78 posts views Thread by Josiah Manson | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.