The Dairy Science and Food Technology (DSFT) website provides scientific and technological information, Cloud-based tools and consultancy services for food scientists and technologists working in industry and in colleges and universities. A discussion forum and interactive content through "On Line" calculators are also provided. Writing/citation resources including a Harvard-type reference wizard and a range of citation-wizards can also be accessed.

 The article on the "Reliability of microbial sampling in assuring food safety and calculation of prevalence following negative tests" at 

 https://www.dairyscience.info/index.php/food-model/275-sampling.html has three calculators one of which calculates the number of samples required to meet a microbiological specification. This calculator can be accessed at https://www.dairyscience.info/newcalculators/sample-no.asp .

To encourage students to learn about simple coding for the web I am providing the ASP code for the calculator. The code is in two files, one is the form for entering data and the other processes the data. ASP is old technology and .NET and PHP are now more widely used. However, it is really easy to convert the simple ASP code that I have written to PHP or .NET. The code is in a zipped file that can be downloaded using the link below.

Download the sample number calculator ASP files.

 I have also pasted the code below.

1. Data entry form

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<html>

<head>

<table width="97%" height="1030" border="0" align="left">
<tr>
<td width="1005" height="740" colspan="2" valign="top">

</p>
<p align="left"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"> <br />
</font></p>
<form id="form1" name="form1" method="post" action="sample-no1.asp">
<p>&nbsp;</p>
<table width="92%" border="1">
<tr>
<th colspan="2" scope="col"> <h1 class="style1">Calculate the number of samples required to assure the absence of a pathogen or fault-causing organism at a selected probability
</h1>
</h1>
<p class="style2">To use add your values (numerical only) to the empty fields below. </p>
<p>&nbsp;</p></th>
</tr>
<tr>
<td width="520"><font size="3" face="Verdana, Arial, Helvetica, sans-serif">Probability </font></td>
<td width="440"><label for="prob"></label>
<input name="prob" type="text" id="prob" size="10" />
Value is normally 0.95 (95%)</td>
</tr>
<tr>
<td><p><font size="3" face="Verdana, Arial, Helvetica, sans-serif">What mass (g) or volume (mL) of food should be free of the organism?</font></p></td>
<td><label for="volume"></label>
<input name="volume" type="text" id="volume" size="18" />
e.g. 500 g</td>
</tr>
<tr>
<td><font size="3" face="Verdana, Arial, Helvetica, sans-serif">Mass or volume of samples used</font></td>
<td><input name="mass" type="text" id="mass" size="18" />
e.g. 25 g</td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="calculate" type="hidden" id="calculate" value="1" />
<input type="submit" name="Submit" id="Submit" value="Calculate the number of samples" />
</div></td>
</tr>
</table>
<p class="style1">&nbsp;</p>
</form>
<h3 align="left" class="style2">&nbsp;</h3>
<font size="3" face="Verdana, Arial, Helvetica, sans-serif">
<p align="center">

</font></td>
</tr>
</table>

 

</body>
</html>

 

2. Data processing script

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<%

'Code written by Dr Michael Mullan at www.dairyscience.info

 

'Listing variables
if request.form("calculate")=1 then 'to stop remove submission



Dim prob, volume, mass, units, defects, pd, result, rounded 'variables defined




'Taking information from the form


prob=Request.form("prob")
volume=Request.form("volume")
mass=Request.form("mass")
End iF

'Validation

IF prob > 0.99999 THEN

Response.Write "<b>Probability values higher than 0.99999 are not permitted. Please enter an in-scope value.</b><br>"

Else
IF prob <> "" AND volume <> "" AND mass <> "" THEN

'Calculation of defectives and Pdect

units=Round(volume/mass,1)
defects=Round(1/units*100,2)
pd=Round(defects/100,2)

'Calculation of sample numbers
'In ASP log gives ln (natural log) so to give log10 we need to divide ln values by 2.30258509 to give log10 values
Result=Round((log(1-prob)/2.30258509)/(LOG(1-pd)/2.30258509),3)
'I rounded the calculation to 3 decimals to show the result of the calculation
'Next we need to round to next whole number. ASP does not have the Ceiling function of Excel so we need a work around as below. I have used rounded insted of result so that I can show two different values, the actual calculation value and rounded to next whole number
'Thanks to Dr Raymond Martin for sharing the work around

rounded=(log(1-prob)/2.30258509)/(LOG(1-pd)/2.30258509)

If rounded <> Int(rounded) then
rounded = Int(rounded+1)
end if

 

ELSE
Response.Write "<p> There has been a data-entry error. Please note the error message(s) below and ammend your data entry:</p>"
IF prob <> "" THEN
ELSE
Response.Write "<b>The probability has not been given.</b><br>"
END IF
IF volume <> "" THEN
ELSE
Response.Write "<b> You have not entered the mass or volume of food.</b><br>"
END IF
IF mass <> "" THEN
ELSE
Response.Write "<b> A value for the weight or volume of the samples used has not been entered.</b><br>"
END IF

 

End IF

End IF

%>

<html>
<head>

</head>

<body>
<table width="97%" height="1030" border="0" align="left">
<tr>
<td width="1005" height="740" colspan="2" valign="top">
<p align="left"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<font size="3" face="Verdana, Arial, Helvetica, sans-serif"> <br />
</font></p>
<form id="form1" name="form1" method="post" action="">
<div align="center">
<table width="75%" height="407" border="1">
<tr>
<th colspan="2" scope="col"> <h1 class="style1">Results of the calculation to determine the number of samples required</font></h1>
<p>&nbsp;</p></th>
</tr>
<tr>
<td colspan="2" align="center"> <h2 align="left">1.Calculation of % defects and P<sub>def</sub></h2></td>
</tr>
<tr>
<td width="281">Organism should be absent in </td>
<td width="464"><%=volume%>&nbsp;mL or g</td>
</tr>
<tr>
<td>Mass or volume of samples, g or mL</td>
<td><%=mass%>&nbsp;</td>
</tr>
<tr>
<td>Number of sample units in <% Response.write" "&volume&" mL or g " %>&nbsp;</td>
<td><%=units%>&nbsp;</td>
</tr>
<tr>
<td>% Defects</td>
<td><%=defects%>&nbsp;</td>
</tr>
<tr>
<td>P<sub>def</sub></td>
<td><%=pd%>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><h2>2.Calculation of number of samples</h2></td>
</tr>
<tr>
<td>Probability selected</td>
<td><%=prob%>&nbsp;</td>
</tr>
<tr>
<td>Number of samples required</td>
<td><%=result%>&nbsp;</td>
</tr>
<tr>
<td>Sample number rounded to next whole number</td>
<td><%=rounded%>&nbsp;</td>
</tr>
<tr>
<td colspan="2"><div align="left">
<p> <%
If request.form("calculate")=1 AND prob <> "" AND volume <> "" AND mass <> "" THEN
response.write (" "&rounded&" samples of "&mass&" g or mL are required to detect a homogenously distributed organism in a food at a concentration of "&volume&" CFU/L or Kg at a probability of "&prob&". Because of the high probability of clusters being present it is better to take a greater number of smaller samples.")
End IF
%>

</p>
</div></td>
</tr>
</table>
</div>
<p>&nbsp;</p>
</form>
<h3 align="center" class="style2"><a href="/sample-no.asp">Perform another calculation</a></h3>
<h3 align="left" class="style2"><font color="#000000" size="3" face="Verdana, Arial, Helvetica, sans-serif">
</font></h3>
<font size="3" face="Verdana, Arial, Helvetica, sans-serif">
<p align="center">

</font></td>
</tr>
<tr>
<td height="55" colspan="2" bgcolor="#CCCCCC"><div class="style2">
<div id="mainblock">
<div id="main-body">
<div id="maincol">
<div>
<div>
<div>
<div id="maincontent-block">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" align="middle"></td>
</tr>
<tr>
<td valign="top" align="middle"></td>
</tr>
</tbody>
</table>

<div id="bottom">
<div>
<div>
<div class="style2"><a href="http://www.dairyscience.info/index.php/93-articles/notices/115-copyright-legal.html">Copyright &copy; 2015. Dairy Science and Food Technology. All Rights Reserved. Privacy and cookies</a></div>
</div>
</div>
</div>
</div></td>
</tr>
</table>
</body>
</html>