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.
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">
<th colspan="2" scope="col">Predict the growth of salmonella in cut tomatoes at 10°C to 35°C</th>
<td width="41%">Initial number of salmonella / gram</td>
<td width="59%"><input name="no" type="text" id="no" value="<%=no%>" /></td>
<td><input name="t" type="text" id="t" value="<%=t%>" /></td>
<td height="20">Incubation time, hours</td>
<td><input name="hr" type="text" id="hr" value="<%=hr%>" /></td>
<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" />
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.
<% Option Explicit
'Use of option explicit will ensure that error messages are displayed if there are coding problems. These are helpful in finding solutions. %>
'no, t and hr are values that have been entered on the form
'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
'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
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
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" & " " & (hr)& " " & "hours has been calculated as" & " " & round(pop,0) & " " & "CFU/g.")
'END IF is used to indicate the end of code execution
IF t < 10 THEN
Response.Write (" Caution. This model as not been validated at temperatures <10°C.")
IF t > 35 THEN
Response.Write (" Caution. This model as not been validated at temperatures >35°C")
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.
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: 27 September, 2022. Updated December 2019.