The purpose of this article is to show how the calculator for predicting salmonella growth on tomatoes was written in ASP. I would like to encourage lecturers and students to learn how to programme. While ASP is being replaced by ASP.NET the basic premises using in ASP coding can be applied to other languages and even if you decide to learn PHP which is a particularly versatile web language or other language (probably good idea) you will be able to apply the concepts learned.

There are several programming languages used to construct models that will run on web servers. These include Perl, PHP, Python, Classic ASP, JavaScript and ASP.Net. These languages can be used with appropriate databases to develop powerful web-based applications.

PHP has become particularly popular and is fairly easy to learn. Classic ASP is even easier to learn but is increasingly being replaced by ASP.NET. Virtually anyone who can put a spreadsheet together is capable of learning a basic web programming language such as ASP or PHP.

Constructing the data entry form

The HTML and ASP code used to construct the data entry form is shown below. For simplicity web page header information, value information in ASP and some form security information has not been shown. Nevertheless the form and script below will work on a PC or webserver that supports ASP without amendment.

The input form was constructed by writing the code for a table in HTML and adding in HTML text boxes to allow initial number (no), temperature (t) and incubation time (hr) to be entered.

 <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> ' A standard HTML header could be used instead

<form id="form1" name="form1" method="post" action="sam1.asp">

<table width="75%" border="1" cellspacing="0" cellpadding="1">
<tr>
<th colspan="2" scope="col">Predict the growth of salmonella in cut tomatoes at 10&deg;C to 35&deg;C</th>
</tr>
<tr>
<td width="41%">Initial number of salmonella / gram</td>
<td width="59%"><input name="no" type="text" id="no" value="<%=no%>" /></td>
</tr>
<tr>
<td>Temperature, &deg;C</td>
<td><input name="t" type="text" id="t" value="<%=t%>" /></td>
</tr>
<tr>
<td height="20">Incubation time, hours</td>
<td><input name="hr" type="text" id="hr" value="<%=hr%>" /></td>
</tr>
<tr>
<td height="20" colspan="2"><div align="center">
<input type="submit" name="Predict number of samonella" id="Predict number of samonella" value="Predict number of salmonella" />
</div></td>
</tr>
</table>
<p>&nbsp;</p>
</form>

Writing the data processing script

A simplified, but fully working, version of the processing script is given below. The notes which are preceded by a ' explain how the script works.

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


<% Option Explicit
'Use of option explicit will ensure that error messages are displayed if there are coding problems. These are helpful in finding solutions. %>

<%


'List variables

Dim no
Dim t
Dim hr

'no, t and hr are values that have been entered on the form
Dim r
Dim g
Dim gen
Dim pop

'r,g,gen, pop are the products of calculations that will be undertaken

'We will now obtain the information from the entry form to perform the calculation

no=CSng(Request.form("no"))
t=CSng(Request.form("t"))
hr=CSng(Request.form("hr"))


'Taking information from the form we will calculate r,g, gen and pop. This could easily be done in one calculation. The calculation has been broken down into its component parts so that it can be followed more easily.

'For an explanation of the calculation please see http://www.dairyscience.info/index.php/food-model/258-predict.html
 
r=0.026*(t)-0.1065
g=1/(r*r)  'note r is the square root of the growth rate, we need to obtain the growth rate by multiplying r by r
gen=hr/g
pop = no*2^gen

'We next need to provide the results of the calculation for pop which is the total number of salmonella after growth at the temperature chosen for the time inputted.

If t >9.99 AND t <35.01 THEN ' basic validation to ensure that the results are within the temperature parameters modelled

'The  'If Statement' is used to make a decision to execute code if some condition is True.
 
response.write ("The predicted number of samonella after" & "&nbsp;" & (hr)& "&nbsp;" & "hours has been calculated as" & "&nbsp;" & round(pop,0) & "&nbsp;" & "CFU/g.")
 END IF

'END IF is used to indicate the end of code execution


IF t < 10 THEN
Response.Write ("&nbsp; Caution. This model as not been validated at temperatures <10&deg;C.")
END IF

IF t > 35 THEN
Response.Write ("&nbsp; Caution. This model as not been validated at temperatures >35&deg;C")
END IF
%>

Using the scripts

The simplest way of using the scripts is to copy each using a simple text editor e.g. Notepad on a PC or its equivalent on a Mac or Linux machine. Save the form script using whatever "name" you want as name.htm or name.asp. The data processing script must be saved as sam.asp since sam.asp is the name of the script in the input form that has been designated to process the data.

These scripts will work on a Windows web server or a Windows PC running Microsoft's free IIS or PWS components. 

Qualifications/Disclaimer

The scripts  have been provided free and are not warranted in any way. They are intended for educational use only. They can easily be adapted to work using PHP or JavaScript. Users use the code provided at their own risk. 

Acknowledgements

I learned ASP, how to use Access Databases and HTML from a former colleague Dr Raymond Martin. Raymond generously helped me correct concatenation and many other errors and though his help I gradually learned how to write quite sophisticated data-base driven ASP applications. I gratefully acknowledge Raymond's help over many years.


How to cite this article

Mullan, W.M.A. (2015). [On-line]. Available from: https://www.dairyscience.info/index.php/technology/260-asp.html . Accessed: 19 April, 2024. Updated December 2019.