PDA

View Full Version : how to calculate the value


petertran123
10-01-2002, 07:52 PM
Hello all,

I have the form and wanted to calculate the value in the form, and here is the field

If PriorYearA > 0, then AppDel = D and DeclineCode= 01, else AppDel = A and DeclineCode =00

Can i write a script to calculate those fields above. Thank you much

whammy
10-02-2002, 01:20 AM
You're trying to get the length of a string without using the Len() function, and a lot more things are wrong with your If/Then statements... example... you have:

If PriorYearA > 0, then AppDel = D and DeclineCode= 01, else AppDel = A and DeclineCode =00

Which should probably be:

If Len(PriorYearA) > 0, Then
AppDel = "D"
DeclineCode = 1
Else
AppDel = "A"
DeclineCode = 0
End If

Although, I'm not sure since you didn't post the rest of the code...

petertran123
10-02-2002, 03:03 PM
i'm sorry, here is the code

this is a sample code of my form.

<form name="form" method="post" action="submit.asp">
<input type="hidden" name="EFIN" value="<%= Request.Form("PriorYearA") %>">
<input type="hidden" name="PrimarySSN" value="<%= Request.Form("AppDel") %>">
<input type="hidden" name="SpouseSSN" value="<%= Request.Form("DeclineCode") %>">

<table border="0" width="100%">
<tr>
<td width="70%" align="right"><font size="2" face="Arial"><b>Prior Year Income/Loss:</b></font></td>
<td width="30%"><input type="text" value="" name="PriorYearA" Size="10" maxlength="10" ></td>
</tr>

<tr>
<td width="70%" align="right"><font size="2" face="Arial"><b>Current Year Income/Loss:</b></font></td>
<td width="30%"><input type="text" value="" name="CurrYearA" Size="10" maxlength="10" ></td>
</tr>

<form>

on the form when someone enter amount greater than 0 then they will receive code AppDel=A and DeclineCode=00, if they are not enter anything, then they will receive different code like this AppDel = D and DeclineCode= 01

*******this is a code i want to calculate************
If PriorYearA > 0, then AppDel = D and DeclineCode= 01, else AppDel = A and DeclineCode =00

If CurrYearA > 0, then AppDel = D and DeclineCode= 01, else AppDel = A and DeclineCode =00


From this particular scripts i wanted to validate a field

AppDel

If AppDel="D" then redirect to Decline.asp
If AppDel="A" then redirect to Approval.asp

Thank you for your kindness

whammy
10-03-2002, 01:02 AM
I think I already answered that... :confused:

I'm really, really not trying to be mean... but you haven't even corrected the errors that I pointed out before posting your code... if I were you I'd take some basic ASP tutorials, so you will understand the correct syntax for IF THEN statements and also understand datatypes.

Also, I'm totally confused as to why you'd want to reassign variable names like this... if you're going to do that, there should be a valid reason and it shouldn't happen in your HTML output:

<input type="hidden" name="EFIN" value="<%= Request.Form("PriorYearA") %>">
<input type="hidden" name="PrimarySSN" value="<%= Request.Form("AppDel") %>">
<input type="hidden" name="SpouseSSN" value="<%= Request.Form("DeclineCode") %>">

That can only lead to confusion (for you and whoever might have to update the application in the future!).

It seems to me (and again, I'm not trying to be mean, just honest) that you are really confused, and need to take a step back and learn the basics of programming and/or ASP.

You might want to take a look at a very basic "email contact form" I created as an example of "clean ASP coding" to get some ideas:


<% @Language="VBScript" %>
<% Option Explicit %>
<%
' Dimension the form variables
Dim Name, Email, Subject, Message

' Dimension variables used in the application
Dim Pass, Complete, objMail

Function ValidEmail(email) ''''''''''''''''''''''
Dim veRegEx
Set veRegEx = New RegExp
veRegEx.Pattern = "^[\w\.-]+@[\w\.-]+\.[a-zA-Z]{2,}$"
ValidEmail = veRegEx.Test(email)
End Function ''''''''''''''''''''''''''''''''''''

Function RemoveSpaces(str) ''''''''''''''''''''''
If IsNull(str) Then str = ""
Dim rsRegEx
Set rsRegEx = New RegExp
rsRegEx.Pattern = "\s"
rsRegEx.Global = True
RemoveSpaces = rsRegEx.Replace(str,"")
End Function ''''''''''''''''''''''''''''''''''''

' Get our variables from the previous form

Name = Trim(Request.Form("Name"))
Email = Trim(RemoveSpaces(Request.Form("Email")))
Subject = Trim(Request.Form("Subject"))
Message = Trim(Request.Form("Message"))
Pass = Request.Form("Pass")

'''''''''''''''''''''''''''''''''''' MAIN PROGRAM

Pass = Pass + 1

If Name = "" OR ValidEmail(Email) = False OR Subject = "" OR Message = "" Then
DisplayForm()
Else
SendEmail()
End If

'''''''''''''''''''''''''''''''' END MAIN PROGRAM
%>

<% Sub DisplayForm() '''''''''''''''''''''''''''' %>
<html>
<head>
<title>Contact Support</title>
<style type="text/css">
<!--
.error{
color: #ff0000
}
-->
</style>
</head>

<body>

<h1>Contact Support</h1>

<form name="emailform" action="email.asp" method="post">

<table>
<tr>
<td valign="top"<% If Pass > 1 AND Name = "" Then Response.Write(" class=""error""") %>>Name: </td>
<td><input type="text" name="Name" value="<% = Server.HTMLEncode(Name) %>" /></td>
</tr>
<tr>
<td valign="top"<% If Pass > 1 AND ValidEmail(Email) = False Then Response.Write(" class=""error""") %>>Email: </td>
<td><input type="text" name="Email" value="<% = Server.HTMLEncode(Email) %>" /></td>
</tr>
<tr>
<td valign="top"<% If Pass > 1 AND Subject = "" Then Response.Write(" class=""error""") %>>Message Subject: </td>
<td><input type="text" name="Subject" value="<% = Server.HTMLEncode(Subject) %>" /></td>
</tr>
<tr>
<td valign="top"<% If Pass > 1 AND Message = "" Then Response.Write(" class=""error""") %>>Message: </td>
<td><textarea rows="15" cols="20" name="Message"><% = Server.HTMLEncode(Message) %></textarea></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="hidden" name="Pass" value="<% = Pass %>" />
<input type="submit" value="Submit" />
</td>
</tr>
</table>

</form>

</body>
</html>
<% End Sub '''''''''''''''''''''''''''''''''''''' %>

<% Sub SendEmail() ''''''''''''''''''''''''''''''
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.To = "support@solidscripts.com"
objMail.From = """" & Name & """" & " <" & Email & ">"
objMail.cc = ""
objMail.bcc = ""
objMail.Subject = Subject
objMail.Body = Message
objMail.Send
Set objMail = Nothing
' We'll insert some HTML below to make this a Thank You page. %>
<html>
<head>
<title>Thank you!</title>
<meta http-equiv="refresh" content="4;URL=email.asp">
</head>

<body>

<h1>Thank you!</h1>

<p>Thank you for contacting us. We will get back to you as soon as possible.</p>

</body>
</html>
<% End Sub '''''''''''''''''''''''''''''''''''''' %>


:)