Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I can't find the bug in this script...

    This is a comic script and till today its worked without problem, but now its not working as it should, here is the code to the page I use it in:

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    .content {
    font-family: verdana, arial, "ms sans serif", sans-serif;
    font-size: 11px;
    color: #101842;
    background-color: #B5B5B5;
    padding-right: 0px;
    padding-left: 0px;
    }
    }
    -->
    </style>
    </head>

    <body bgcolor="#B5B5B5" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <td colspan=2 class="content">
    <table border=0 width="100%" cellspacing="0" cellpadding="0" align="center">
    <tr valign="top">
    <td colspan=2 class="content">
    <div align="center">

    <script language="JavaScript">
    <!--

    function SymError()
    {
    return true;
    }

    window.onerror = SymError;

    var SymRealWinOpen = window.open;

    function SymWinOpen(url, name, attributes)
    {
    return (new Object());
    }

    window.open = SymWinOpen;

    //-->
    </script>

    <script language="JavaScript"><!--
    var today=new Date();var thismonth=today.getMonth()+1;var thisyear=today.getYear();var thisday=today.getDate();
    function comicwrite(year,month,day,name) {
    var tempmonth;var shortyear;
    if(year<1900) {year=year+1900;}
    if(year>2000) {shortyear ="0"+(year-2000);}
    else {shortyear=""+(year-1900);}
    var montharray=new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    if(month>1) {tempmonth=month-1;} else {tempmonth=12;}
    var maxdays=montharray[tempmonth-1];
    if(tempmonth==2) {if(year % 100 == 0) {if(year % 400 == 0) { maxdays=29; }}
    else {if((year%4)==0) {maxdays=29;}}}
    if(day>1) {day--;}
    else {if(month>1) {month--;day=maxdays;} else {month=12;year--;day=maxdays;}}
    if(day < 10) {day ="0"+day;}
    else {day = ""+day;}
    if(month < 10) {month="0"+month;}
    else {month = ""+month;}
    document.write("<p><img src=http://images.ucomics.com/comics/"+name+"/"+year+"/"+name+shortyear+month+day+".gif border=0></p>");
    }
    comicwrite(thisyear,thismonth,thisday,"ga");
    // --></script>
    </div>
    </td>
    </tr>
    </table>

    </td>
    </body>

    <script language="JavaScript">
    <!--

    window.open = SymRealWinOpen;

    //-->
    </script>

    </html>

    The problem lies in the producing of the file name with the dates. For today, the end part should be 030301.gif instead it is 030229.gif so it doesn't show up

    Any help is appreciated
    AgaBoogaBoo
    _____________________
    ankygupta@hotmail.com

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    It's being cause by the incorrectly handing the leap year. The code is too compressed for me to read though.

  • #3
    Regular Coder Skyzyx's Avatar
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't say for sure, because this code was impossible to read, but you could try this:

    Code:
    function SymError() { return true; }
    window.onerror = SymError;
    
    var SymRealWinOpen = window.open;
    function SymWinOpen(url, name, attributes) { return (new Object()); }
    window.open = SymWinOpen;
    
    var today=new Date();
    var thismonth=today.getMonth()+1;
    var thisyear=today.getYear();
    var thisday=today.getDate();
    
    function comicwrite(year,month,day,name)
    {
    	var tempmonth;
    	var shortyear;
    
    	if (year<1900) year+=1900;
    	if (year>2000) shortyear ="0"+(year-2000);
    	else shortyear=""+(year-1900);
    
    	var montharray=new Array(31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    
    	if(month>1) tempmonth=month-1;
    	else tempmonth=12;
    
    	var maxdays=montharray[tempmonth-1];
    	if(tempmonth==2)
    	{
    		if (((thisYear%4 == 0) && !(thisYear%100 == 0)) || (thisYear%400 == 0)) maxdays = 29;
    	}
    
    	if(day>1) day--;
    	else
    	{
    		if(month>1)
    		{
    			month--;
    			day=maxdays;
    		}
    		else
    		{
    			month=12;year--;
    			day=maxdays;
    		}
    	}
    
    	if(day < 10) day ="0"+day;
    	else day=""+day;
    
    	if(month < 10) month="0"+month;
    	else month=""+month;
    
    	document.write("<p><img src=http://images.ucomics.com/comics/"+name+"/"+year+"/"+name+shortyear+month+day+".gif border=0></p>");
    }
    comicwrite(thisyear,thismonth,thisday,"ga");
    Also, the [ code ] and [ /code ] tags make it infinitely easier to read code...

    Creator of SimplePie and Tarzan AWS, co-founder of WarpShare, co-built the Y! Messenger website, usability-focused, and an INFJ personality.

  • #4
    New Coder
    Join Date
    Feb 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That didn't seem to work
    AgaBoogaBoo
    _____________________
    ankygupta@hotmail.com

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Atlanta, GA.
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts
    var montharray=new Array(31, 28 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  • #6
    New Coder
    Join Date
    Feb 2003
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much!
    AgaBoogaBoo
    _____________________
    ankygupta@hotmail.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •