Forums
This topic is locked
Calculate my recordset fields
Posted 30 Apr 2007 01:21:23
1
has voted
30 Apr 2007 01:21:23 Zizo Alshabrawi posted:
<font face='Verdana'>Hi,I'm trying to calculate some of my recordset fields like the following:
(rsDaily.Fields.Item("break_time".Value) / (rsDaily.Fields.Item("stuff_time".Value)*3600
but always get Type missmatch error also if i assigned it to varable or convert it to integer CInt or CLng i get another error(overflow)
Please if anybody can help me to calculate these fields as general or just give me an iedia to convert it to the right format.
Regards
</font id='Verdana'>
Replies
Replied 16 May 2007 22:39:05
16 May 2007 22:39:05 dave blohm replied:
These are datetime fields, yes? What, exactly, are you trying to calculate with this?
- Doc
Progress is made by the discontent.
- Doc
Progress is made by the discontent.
Replied 19 May 2007 01:07:43
19 May 2007 01:07:43 Zizo Alshabrawi replied:
These are Integer fields
So I want to convert these seconds to minutes first then divided it by another recordset field
So I want to convert these seconds to minutes first then divided it by another recordset field
Replied 20 May 2007 01:34:26
20 May 2007 01:34:26 Mike Leslie replied:
i would assign the recordset values to a variable then do the math with variables, then you could change to minutes then divide by any field.
Dim Brktim, Stftime, BrkTimMin, StfTimMin, BreakAllowed, TimeAtBreak
BreakAllowed = 10 'set to 10 minutes or whatever your break time is
BrkTim = (rsDaily.Fields.Item("break_time".Value)
StfTim = (rsDaily.Fields.Item("stuff_time".Value)
BrkTimMin = BrkTim / 60
StfTimMin = StfTim / 60
TimeAtBreak = BreakAllowed - BrkTimMin 'if a negative number will indicate over break time
This will give you minutes if the BrkTim and StfTim are in seconds, then multiply the varibles by whatever be sure to enclose the dim in the proper tag and ad more variables to finish your calculations.
Dim Brktim, Stftime, BrkTimMin, StfTimMin, BreakAllowed, TimeAtBreak
BreakAllowed = 10 'set to 10 minutes or whatever your break time is
BrkTim = (rsDaily.Fields.Item("break_time".Value)
StfTim = (rsDaily.Fields.Item("stuff_time".Value)
BrkTimMin = BrkTim / 60
StfTimMin = StfTim / 60
TimeAtBreak = BreakAllowed - BrkTimMin 'if a negative number will indicate over break time
This will give you minutes if the BrkTim and StfTim are in seconds, then multiply the varibles by whatever be sure to enclose the dim in the proper tag and ad more variables to finish your calculations.
Replied 20 May 2007 02:42:45
20 May 2007 02:42:45 dave blohm replied:
Is it possible that you have a null or zero value in the stuff_time field? Division by null and division by zero are no no's.
- Doc
Progress is made by the discontent.
Edited by - daveblohm on 09 Feb 2008 17:16:24
- Doc
Progress is made by the discontent.
Edited by - daveblohm on 09 Feb 2008 17:16:24
Replied 09 Feb 2008 15:21:43
09 Feb 2008 15:21:43 Andrew Turner replied:
I have used the contents of this post and tried to adapt it for my own problem. I am trying to add a number of fields together and get a total. Not sure if is working yet but at least I do not get an error. However once I have the total in a variable how can I display it on the page?
Here is my attempt at the code, with PL_Total being the variable I want to hold the total and display on the page.
Dim PL_Asia, PL_Distressed, PL_Europe_1, PL_Europe_2, PL_Europe_3, PL_Japan, PL_Macro, PL_Team, PL_US_1, PL_US_3, PL_US_5, PL_Total
PL_Asia = (rsPL_Flash.Fields.Item("PL_Asia".Value)
PL_Distressed = (rsPL_Flash.Fields.Item("PL_Distressed".Value)
PL_Europe_1 = (rsPL_Flash.Fields.Item("PL_Europe_1".Value)
PL_Europe_2 = (rsPL_Flash.Fields.Item("PL_Europe_2".Value)
PL_Europe_3 = (rsPL_Flash.Fields.Item("PL_Europe_3".Value)
PL_Japan = (rsPL_Flash.Fields.Item("PL_Japan".Value)
PL_Macro = (rsPL_Flash.Fields.Item("PL_Macro".Value)
PL_Team = (rsPL_Flash.Fields.Item("PL_Team".Value)
PL_US_1 = (rsPL_Flash.Fields.Item("PL_US_1".Value)
PL_US_3 = (rsPL_Flash.Fields.Item("PL_US_3".Value)
PL_US_5 = (rsPL_Flash.Fields.Item("PL_US_5".Value)
PL_Total = PL_Asia + PL_Distressed + PL_Europe_1 + PL_Europe_2 + PL_Europe_3 + PL_Japan + PL_Macro + PL_Team + PL_US_1 + PL_US_3 + PL_US_5
Here is my attempt at the code, with PL_Total being the variable I want to hold the total and display on the page.
Dim PL_Asia, PL_Distressed, PL_Europe_1, PL_Europe_2, PL_Europe_3, PL_Japan, PL_Macro, PL_Team, PL_US_1, PL_US_3, PL_US_5, PL_Total
PL_Asia = (rsPL_Flash.Fields.Item("PL_Asia".Value)
PL_Distressed = (rsPL_Flash.Fields.Item("PL_Distressed".Value)
PL_Europe_1 = (rsPL_Flash.Fields.Item("PL_Europe_1".Value)
PL_Europe_2 = (rsPL_Flash.Fields.Item("PL_Europe_2".Value)
PL_Europe_3 = (rsPL_Flash.Fields.Item("PL_Europe_3".Value)
PL_Japan = (rsPL_Flash.Fields.Item("PL_Japan".Value)
PL_Macro = (rsPL_Flash.Fields.Item("PL_Macro".Value)
PL_Team = (rsPL_Flash.Fields.Item("PL_Team".Value)
PL_US_1 = (rsPL_Flash.Fields.Item("PL_US_1".Value)
PL_US_3 = (rsPL_Flash.Fields.Item("PL_US_3".Value)
PL_US_5 = (rsPL_Flash.Fields.Item("PL_US_5".Value)
PL_Total = PL_Asia + PL_Distressed + PL_Europe_1 + PL_Europe_2 + PL_Europe_3 + PL_Japan + PL_Macro + PL_Team + PL_US_1 + PL_US_3 + PL_US_5
Replied 09 Feb 2008 17:11:28
09 Feb 2008 17:11:28 dave blohm replied:
Response.Write PL_Total
- Doc
Progress is made by the discontent.
- Doc
Progress is made by the discontent.
Replied 11 Feb 2008 15:21:44
11 Feb 2008 15:21:44 Vince Baker replied:
There is a really annoyihg bug in asp that for some reason confuses the field type.
One way I have used to get round this simply is to just divide your value by 1. Simple, annoying but affective.
((rsDaily.Fields.Item("break_time".Value)/1) / ((rsDaily.Fields.Item("stuff_time".Value)/1)*3600
I have added the divide to your code above.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
One way I have used to get round this simply is to just divide your value by 1. Simple, annoying but affective.
((rsDaily.Fields.Item("break_time".Value)/1) / ((rsDaily.Fields.Item("stuff_time".Value)/1)*3600
I have added the divide to your code above.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]