[thelist] ASP help
David.Cantrell at Gunter.AF.mil
David.Cantrell at Gunter.AF.mil
Tue Sep 10 10:47:01 CDT 2002
>I'm trying to get these tables to write to a page only if the condition is
True. The information stored in varSub1 and
>varSub2 are only dispalyed when True but the table itself always appears
regardless of condition. Why is this and is there a >way around it. Thanks
Maybe I don't quite understand your problem. I added the two blnSub and
varSub variables and it worked just fine -- varSub1 was displayed when
blnSub1 was true, and vice-versa.
BTW much better to rewrite this code to be more modular -- right now there's
a lot of duplication.
Also, without seeing the rest of your code, the variable names blnSub# and
varSub# seem to be very generic names. You may want to consider renaming
them as well?
Try this code: (watch for wrapping)
<%
blnSub1 = False
blnSub2 = True
varSub1 = 1
varSub2 = 2
If blnSub1 then
DisplayTip varSub1
ElseIf blnSub2 then
DisplayTip varSub2
End If
Sub DisplayTip( s )
'Displays a tip table.
'Accepts: s. String to display.
With Response
.Write "<table border='0' cellspacing='1' cellpadding='4'
style='background-color: #ccc; width: 150px;'>"
.Write "<tr>"
.Write "<td style='background-color: #56428b; font-size: 11px;
font-weight: bold; color: white; text-align: center;'>Tip</td>"
.Write "</tr>"
.Write "<tr>"
.Write "<td style='background-color: #fff; font-size: 11px;
font-weight: bold; color: #ff400; text-align: left;'>"
.Write s
.Write "</td>"
.Write "</tr>"
.Write "</table>"
End With
End Sub
%>
The point is to encapsulate the "grunt-work" logic (the subroutine) and keep
your working logic at as high a level of abstraction as possible so the code
is more understandable and maintainable. Call it "at-a-glance" coding. :)
HTH,
-dave
More information about the thelist
mailing list