Not that kind of "switch" ... but close?



  • [b]DISCLAIMER:[/b] This code was written at a very early/late hour during a ridiculous crunch time by a one-man development team. Drugs may have been involved. Prior to anonymization there was a lot more code to this one, so fill in the blanks with lots of divs and style statements. It's just way too long for the front page to bother sending in officially, and you really have to follow the whole thing to get it.

    <%
    divcounter = 1
    

    userdate = 0
    userid = 0
    switch1 = 0
    switch2 = 0
    switch3 = 0
    switch4 = 0
    switch5 = 0
    colorswitch = 0
    imageid = 1
    lastuser = userid
    lastdate = userdate

    do until DBData1.data.EOF
    switch1 = 0
    switch2 = 0
    switch3 = 0

    if userid &lt;&gt; lastuser then
    	switch1 = 1
    end if
    
    if DateDiff(&quot;d&quot;,userdate,lastdate) &lt;&gt; 0 OR lastdate = 0 then
    	switch2 = 1
    else
    	switch3 = 1
    end if
    
    if switch1 = 1 then
    	if userid &lt;&gt; 0 then
    		&apos; some HTML output
    	end if
    
    	if switch5 = 1 then
    		&apos; some HTML output
    		switch5 = 0
    	end if
    
    	if switch4 = 1 then
    		&apos; some HTML output
    		switch4 = 0
    	end if
    
    	%&gt; some HTML output &lt;%
    
    	if colorswitch = 0 then
    		colorswitch = 1
    	else
    		%&gt; some HTML output &lt;%
    		colorswitch = 0
    	end if
    	
    	%&gt; bunch o&apos; HTML &lt;%
    	
    	divcounter = divcounter + 1
    	imageid = imageid + 1
    end if
    
    if switch2 = 1 then
    	if switch5 = 1 then
    		&apos; some HTML output
    		switch5 = 0
    	end if
    
    	if switch4 = 1 then
    		&apos; some HTML output
    		switch4 = 0
    	end if
    
    	%&gt; some HTML output here... &lt;%
    
    	switch5 = 1
    
    	divcounter = divcounter + 1
    	imageid = imageid + 1
    end if
    
    if switch3 = 1 then
    	if switch4 = 1 then
    		&apos; some HTML output
    	else
    		&apos; some HTML output
    		switch4 = 1
    	end if
    
    	&apos; some HTML output
    	
    	divcounter = divcounter + 1
    	DBData1.data.MoveNext
    end if
    
    switch1 = 0
    switch2 = 0
    switch3 = 0
    lastuser = userid
    lastdate = userdate
    

    loop
    %>



  • What was the intended purpose?  After a quick review it appears to be doing alternating row colors for a user list, correct?  Not the best way to do it, but we've all been known to throw a hack-job together in the wee hours of the morning with a fast approaching deadline.



  • @Medic350 said:

    What was the intended purpose?  After a quick review it appears to be doing alternating row colors for a user list, correct?  Not the best way to do it, but we've all been known to throw a hack-job together in the wee hours of the morning with a fast approaching deadline.

    The color switching is just a minor minor part of it. That part is fine.



  • This whole thing confuses me, hopefully some code (ASP, not HTML) was removed in the anonymization process.

    Like why are switches 1, 2, and 3 initialized to zero, set to zero at the start of the loop, then again at the end of the loop? Only the one at the start of the loop is needed.

    lastdate is set to userdate, and then he compares them to see if the dates are different. I can guarantee you they won't be. Then without changing userdate anywhere in the loop, lastdate is again set to userdate. (This same logic applies to lastuser and userid apparently)

    I get a little nervous when I see the recordset MoveNext function inside an If block. I hope the guy planned the logic right, or this thing has high potential for endless loopage.

    But the part that irks me is that these "switches" are based on integers. Help make the code a little more readable and maintainable by making them booleans.

    I don't know the purpose of this thing, but there has got to be a better way.



  • @Manni said:

    This whole thing confuses me, hopefully some code (ASP, not HTML) was removed in the anonymization process.

    No logic-related ASP code was removed in the anonymization process. Some database queries were omitted from the beginning, but all I removed was display code after that.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.