<%@ Language=VBScript %> VBScript Demo - Temperatures (With Program)

VBScript Demonstration - Temperatures Using Subs and Functions

 

<% 'use globals to work with data dim cent dim fahr dim answer sub runcalc() cent = request.form("cent") fahr = request.form("fahr") if trim(cent) <> "" and trim(fahr) <> "" then fahr = "" cent = "" answer = "Try again, you had two entries." elseif trim(cent) <> "" or trim(fahr) <> "" then if cent <> "" then fahr = c2f(cent) else cent = f2c(fahr) end if else answer = "You need to enter a value to convert!" end if end sub function c2f(tcent) if isnumeric(tcent) then c2f = formatnumber((tcent * 1.8) + 32,2) else c2f = "Not a Number!" end if end function function f2c(tfahr) if isnumeric(tfahr) then f2c = formatnumber((tfahr - 32) * (5/9),2) else f2c = "Not a Number!" end if end function runcalc 'this runs the program %>

Enter Temperature in Fahrenheit:

or

Enter Temperature in Centigrade:

<% if answer <> "" then response.write("

" & answer & "") %>