Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 16th, 2006, 08:09 AM
Registered User
 
Join Date: Jan 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hi Can anyone help please?

I have a form which is writing to a Access Database. I have 3 Fields called cost code 1, 2 and 3. What I want to do is make a calculation, so if cost code 1 is entered then the feild next to it called Allocation 1 would automatically show = 100%. If costcode 2 is entered then Allocation 2 would show = 50%. I simple term 100% is divided equally between the 3 feilds if all 3 costcode feilds are completed.

 
Old January 16th, 2006, 06:54 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

<%

dim ccOne,ccTwo,ccThree,divideBy,percentRate
ccOne = false
ccTwo = false
ccThree = false
divideby = 0
percentRate = 0

'NOTE the divideBy variable tells us how many have been entered
'therefore how much to divide 100% by

if trim(request.form("costCode1")) <> "" then
'costCode1 has been entered
ccOne = true
divideBy = divideBy + 1
elseif trim(request.form("costCode2")) <> "" then
'costCode2 has been entered
ccTwo = true
divideBy = divideBy + 1
elseif trim(request.form("costCode3")) <> "" then
'costCode3 has been entered
ccThree = true
divideBy = divideBy + 1
end if

divideBy = 3
'cant divide by 0 so check is greater than zero
if cint(divideBy) > 0 then
percentRate = (100 / cint(divideBy))
end if

'Your sql statement
sql = "INSERT INTO [tbleName] ( someIntField "
if ccOne = true then sql = sql & " ,costCode1, Allocation2" end if
if ccTwo = true then sql = sql & " ,costCode2, Allocation2" end if
if ccThree = true then sql = sql & " ,costCode3, Allocation3" end if

'use cInt here to truncate the .333 from percentRate if value has been divided by three
'NOTE: I have assumed your allocation fields are intergers - they should be for future stats etc
sql = sql & ") VALUES (" & someIntValue & ""
if ccOne = true then sql = sql & " ,'" & trim(request.form("costCode1")) & "'," & cint(percentRate) end if
if ccTwo = true then sql = sql & " ,'" & trim(request.form("costCode1")) & "'," & cint(percentRate) end if
if ccThree = true then sql = sql & " ,'" & trim(request.form("costCode1")) & "'," & cint(percentRate) end if
sql = sql & ");"
%>

Wind is your friend
Matt









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.