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 4 of 4
  1. #1
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts

    Script Causing Internet Explorer To Run Slowly

    Hello -

    I have this script that reads through a text file and retrieves the desired data from it and then does some calculations and generates a little report. Problem is when it gets to the end of the month the file gets extremly large and will prompt the user asking them if they would like to abort the script. . .it will eventually finish if they allow it to, it's not that big of a deal because there is only one person using the tool, but if there is any one who knows what I could do to prevent it from asking to stop I would appreciate it. The code is below, if any one trying to fix this for me requires the text file please let me know and I can eMail it to you, it's not somthing I can recreate or publicly present.

    Code:
    <html>
    	<head>
    		<style>
    		body
    		{
    		text-align:center;
    		}
    		.text
    		{
    		width:105px;
    		}
    		table
    		{
    		text-align:center;
    		}
    		.file
    		{
    			width:150px;
    		}
    		</style>
    		<script type="text/javascript">
    var sfo=new ActiveXObject('scripting.FileSystemObject');
    var myData=new Array();
    var finalData=new Array();
    var supList=new Array();
    var monthlyData=new Array();
    function breakLines()
    {
    	var dfile=document.getElementById('daily').value;
    	var myFile=sfo.OpenTextFile(dfile);
    	var str=myFile.readall();
    	myFile.close();
    	var cut=str.split('\n');
    	weedOut(cut)
    }
    mystuff="";
    mystuff2="";
    //found on some website a while back and can't recall where - ->
    function replaceSubstring(inputString, fromString, toString) {
       // Goes through the inputString and replaces every occurrence of fromString with toString
       var temp = inputString;
       if (fromString == "") {
          return inputString;
       }
       if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
          while (temp.indexOf(fromString) != -1) {
             var toTheLeft = temp.substring(0, temp.indexOf(fromString));
             var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
             temp = toTheLeft + toString + toTheRight;
          }
       } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
          var midStrings = new Array("~", "`", "_", "^", "#");
          var midStringLen = 1;
          var midString = "";
          // Find a string that doesn't exist in the inputString to be used
          // as an "inbetween" string
          while (midString == "") {
             for (var i=0; i < midStrings.length; i++) {
                var tempMidString = "";
                for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
                if (fromString.indexOf(tempMidString) == -1) {
                   midString = tempMidString;
                   i = midStrings.length + 1;
                }
             }
          } // Keep on going until we build an "inbetween" string that doesn't exist
          // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
          while (temp.indexOf(fromString) != -1) {
             var toTheLeft = temp.substring(0, temp.indexOf(fromString));
             var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
             temp = toTheLeft + midString + toTheRight;
          }
          // Next, replace the "inbetween" string with the "toString"
          while (temp.indexOf(midString) != -1) {
             var toTheLeft = temp.substring(0, temp.indexOf(midString));
             var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
             temp = toTheLeft + toString + toTheRight;
          }
       } // Ends the check to see if the string being replaced is part of the replacement string or not
       return temp; // Send the updated string back to the user
    } // Ends the "replaceSubstring" function
    
    
    function getSups()
    {
    	var supFile=document.getElementById('supervisor').value;
    	var myFile2=sfo.OpenTextFile(supFile);
    	var str2=myFile2.readall();
    	myFile2.close();
    	var spots=str2.indexOf('Include ACD Assignment information for:');
    	var theList=str2.substring(spots,str2.length)
    	byLine=theList.split('\par');
    	var pace=0;
    	for(f=0;f<byLine.length;f++)
    	{
    		var id2=byLine[f].substring('5','12');
    		var superv1=byLine[f].substring('47','75');
    		var xsup=superv1.indexOf(' ');
    		var superv2=superv1.substring(xsup,superv1.length);
    		var supID=superv1.substring('0',xsup);
    		var fixSupID=replaceSubstring(supID," ","");
    		var fixID=replaceSubstring(id2," ","");	
    		var fixSuper=replaceSubstring(superv2," ","");
    		supList[pace]=new Array(fixID,fixSuper,fixSupID);
    		pace++;
    	}
    }
    
    function weedOut(cut)
    {
    	var j=0;
    	
    	for(i=0;i<cut.length;i++)
    	{
    		if(cut[i].indexOf('Date:')!=-1||cut[i].indexOf('Break')!=-1||cut[i].indexOf('Lunch')!=-1&&cut[i].indexOf('\par Break')==-1&&cut[i].indexOf('\par Lunch')==-1)
    		{
    			myData[j]=cut[i];
    			j++;
    		}
    	}
    	nextRecord();
    }
    
    function hourToMinutes(times)
    {
    	var slice=times.split(':');
    	var hour=slice[0]*60;
    	total=parseFloat(slice[1])+hour;
    }
    
    function nextRecord()
    {
    mu=0;
    	for(i=0;i<myData.length;i++)
    	{
    		var ty=i+1;
    		if(myData[i].indexOf('Date')!=-1)
    		{
    			sEnd=myData[i].indexOf('                     ');
    			var pID=myData[i].substring('5',sEnd);
    			var k=0;
    			var l=0;
    			var m=0;
    			var n=0;
    			var scheduledLunch=new Array();
    			var scheduledBreak=new Array();
    			var actualLunch=new Array();
    			var actualBreak=new Array();
    			var occur=0;
    			var totalOverage=0;
    			
    			while(myData[ty]!=null&&myData[ty].indexOf('Date')==-1)
    			{	
    				var schedule=myData[ty].substring('50','55');
    				var scheduledTime=myData[ty].substring('20','25');
    				
    				switch(schedule)
    				{
    					case "Break":
    					hourToMinutes(scheduledTime);
    					scheduledBreak[k]=total;
    					k++
    					break
    					
    					case "Lunch":
    					hourToMinutes(scheduledTime);
    					scheduledLunch[l]=total;
    					l++
    					break
    				}
    				
    				var actual=myData[ty].substring('71','76');
    				var actualTime=myData[ty].substring('43','48');
    				
    				switch(actual)
    				{
    					case "Break":
    					hourToMinutes(actualTime);
    					actualBreak[m]=total;
    					m++
    					break
    					
    					case "Lunch":
    					hourToMinutes(actualTime);
    					actualLunch[n]=total;
    					n++
    					break
    				}
    					
    				ty++;
    			}
    			
    			function zeroIt(ery)
    			{
    				for(v=0;v<ery.length;v++)
    				{
    					if(ery[v]==undefined)
    					{
    						ery[v]=0;
    					}
    				}
    			}
    
    			zeroIt('actualBreak');
    			zeroIt('actualLunch');
    			zeroIt('scheduledBreak');
    			zeroIt('scheduledLunch');
    		
    			function calcEqualLunch()
    			{
    				for(d=0;d<actualLunch.length;d++)
    				{
    					var overage=actualLunch[d]-scheduledLunch[d];
    					if(overage>=5)
    					{
    						occur++;
    						totalOverage=totalOverage+overage;
    					}
    					
    					else if(overage>0&&overage<5)
    					{
    						totalOverage=totalOverage+overage;
    					}
    				}
    			}
    			
    			function calcEqualBreak()
    			{
    				for(d=0;d<actualBreak.length;d++)
    				{
    					var overage=actualBreak[d]-scheduledBreak[d];
    					if(overage>=5)
    					{
    						occur++;
    						totalOverage=totalOverage+overage;
    					}
    					
    					else if(overage>0&&overage<5)
    					{
    						totalOverage=totalOverage+overage;
    					}
    				}
    			}
    				
    			function calcUnevenLunch()
    			{
    				if(actualLunch.length>scheduledLunch.length)
    				{
    					for(r=0;r<scheduledLunch.length;r++)
    					{
    						overage=actualLunch[r]-scheduledLunch[r];	
    						if(overage>=5)
    						{
    							occur++;
    						}
    							
    					}
    						
    					function addEm1()
    					{
    						actTotal=0;
    						
    						for(w=0;w<actualLunch.length;w++)
    						{
    							actTotal=actTotal+actualLunch[w];
    						}
    					}
    					
    					function addEm2()
    					{
    						schTotal=0;
    						
    						for(w=0;w<scheduledLunch.length;w++)
    						{
    							schTotal=schTotal+scheduledLunch[w];
    						}
    					}
    						
    					addEm1();
    					addEm2();		
    					var overage=actTotal-schTotal;	
    					if(overage>0)
    					{
    						totalOverage=overage+totalOverage;
    					}
    					else
    					{
    						for(t=0;t<actualLunch.length;t++)
    						{
    							var overage=actualLunch[t]-scheduledLunch[t];
    								
    							if(overage>=5)
    							{
    								occur++;
    							}		
    						}	
    					}
    				}		
    			}
    			
    			function calcUnevenBreak()
    			{	
    				if(actualBreak.length>scheduledBreak.length)
    				{
    					for(r=0;r<scheduledBreak.length;r++)
    					{
    						overage=actualBreak[r]-scheduledBreak[r];
    							
    						if(overage>=5)
    						{
    							occur++;
    						}
    							
    					}
    						
    					function addEm3()
    					{
    						actTotal=0;
    						
    						for(w=0;w<actualBreak.length;w++)
    						{
    							actTotal=actTotal+actualBreak[w];
    						}
    					}
    					
    					function addEm4()
    					{
    						schTotal=0;
    						
    						for(w=0;w<scheduledBreak.length;w++)
    						{
    							schTotal=schTotal+scheduledBreak[w];
    						}
    					}
    						
    					addEm3();
    					addEm4();		
    					var overage=actTotal-schTotal;	
    					if(overage>0)
    					{
    						totalOverage=overage+totalOverage;
    					}
    					else
    					{
    						for(t=0;t<actualBreak.length;t++)
    						{
    							var overage=actualBreak[t]-scheduledBreak[t];
    								
    							if(overage>=5)
    							{
    								occur++;
    							}		
    						}	
    					}
    				}		
    			}
    
    			if(actualLunch.length==scheduledLunch.length)
    			{
    				calcEqualLunch();
    			}
    			
    			else
    			{
    				calcUnevenLunch()
    			}
    			
    			if(actualBreak.length==scheduledBreak.length)
    			{
    				calcEqualBreak();
    			}
    			
    			else
    			{
    				calcUnevenBreak();
    			}
    			getID=pID.indexOf(' ');
    			tID=pID.substring('0',getID);
    			getSups();
    			for(wk=0;wk<supList.length;wk++)
    			{
    				if(supList[wk][0]==tID)
    				{
    					pSuper=supList[wk][1];
    					pSupID=supList[wk][2];
    				}
    			}
    			tName=pID.substring(getID,pID.length);
    			finalData[mu]=(tID+"|"+tName+"|"+pSupID+"|"+pSuper+"|"+occur+"|"+totalOverage+"\n");
    			monFile=document.getElementById('monthly').value;
    			
    			if(monFile!=null&&monFile!="")
    			{
    				var mnFile=sfo.OpenTextFile(monFile);
    				var str3=mnFile.readAll();
    				mnFile.close();
    				slice3=str3.split('\n');
    				
    				for(p=0;p<slice3.length;p++)
    				{
    					var slice4=slice3[p].split('|');
    					
    					if(slice4[0]==tID)
    					{
    						tMins1=slice4[4];
    						toccur=slice4[3];
    						p=slice3.length;
    					}
    					else
    					{
    						tMins1=0;
    						toccur=0;
    					}
    				}
    				var mOccur=parseFloat(toccur)+parseFloat(occur);
    				var mMins=parseFloat(tMins1)+parseFloat(totalOverage);
    				monthlyData[mu]=(tID+"|"+tName+"|"+pSupID+"|"+pSuper+"|"+mOccur+"|"+mMins+"\n");
    				mystuff2+=monthlyData[mu];
    			}
    			mystuff+=finalData[mu]			
    			mu++;
    		}
    	}
    	var fileNameDaily=document.getElementById('fNameDa').value;
    	var neFile=sfo.CreateTextFile(fileNameDaily+'.txt',true);
    	neFile.WriteLine(mystuff);
    	neFile.close();
    	
    	if(monFile!=null&&monFile!="")
    	{
    		var neFile2=sfo.CreateTextFile(fileNameMonthly+'.txt',true);
    		var fileNameMonthly=document.getElementById('fNameMo').value;
    		neFile2.WriteLine(mystuff2);
    		neFile2.close();
    	}
    	alert("All Calculations Complete!!  Your Files Are Located On Your Desktop.");
    }					
    		</script>
    	</head>
    	<body>
    		<h2>6 \ 60 Report Generator</h2>
    		<form name="main">
    			<table border="1">
    				<thead>
    					<th>
    						LAN Login</th>
    					<th>
    						Daily Report</th>
    					<th>
    						Monthly File</th>
    					<th>
    						Supervisor List</th>
    				</thead>
    				<tr>
    					<td><input type="text" class="text" id="lan"></td>
    					<td><input type="file" class="file" id="daily"></td>
    					<td><input type="file" class="file" id="monthly"></td>
    					<td><input type="file" class="file" id="supervisor"></td>
    				</tr>
    				<tr>
    					<td><b>Name Your Monthly File:</b></td>
    					<td><input type="text" class="text" id="fNameMo"></td>
    					<td><b>Name Your Daily File:</b></td>
    					<td><input type="text" class="text" id="fNameDa"></td>
    				</tr>
    			</table>
    			<br>
    			<input type="button" value="GO -->" onclick="breakLines()"> <input type="reset" value="Clear">
    	</body>
    </html>
    Thanks,
    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know if there's much you can do really - it's an intensive script, processing an intensive data set.

    Simplify the data set? Clear it more regularly?
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #3
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    I figured so much - thanks for the look over anyway.

    Basscyst
    Helping to build a bigger box. - Adam Matthews

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You might get a bit of an improvement if you use do .. while instead of for - though I doubt it would be a huge difference.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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