...

View Full Version : I can't find the bug in this script...



AgaBoogaBoo
03-01-2003, 06:02 PM
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

arnyinc
03-01-2003, 06:15 PM
It's being cause by the incorrectly handing the leap year. The code is too compressed for me to read though.

Skyzyx
03-01-2003, 06:27 PM
I can't say for sure, because this code was impossible to read, but you could try this:



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...

AgaBoogaBoo
03-01-2003, 09:34 PM
That didn't seem to work

RoyW
03-01-2003, 09:41 PM
var montharray=new Array(31, 28 , 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

AgaBoogaBoo
03-01-2003, 10:42 PM
Thank you so much!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum