Tracker
 ASP PHP JavaScripts MySQL MS Access MSSQL VISUAL BASIC Subjects/Titles Post Text/Content
HOME    TRACKER    Visual Basic

# Calculating The Difference Between Two Dates

## Right now my program calculates 2 dates by using the DateDiff function, but I want to only count the day if it's a week day. I have two values, Day1 and Day2 both declared as Date, and what I'm looking to do is figure out how many week days are between the two. Any thoughts?I was thinking I would have to do something where I step through each day inbetween the 2 dates, and examine the day name and if it is equal to "Saturday" or "Sunday" then to ignore them but I didn't know if there was a clean way to do this.

Calculating Difference Between 2 Dates
Good Day!!!

I need help in calculating the difference between 2 dates (the result should be like "1 year, 2 months and 15 days"). I am building an application for my team to show their tenure in the organization (LIVE TENURE FROM THE DATE OF HIRE TILL NOW). I have the formula in EXCEL but I am not able to get it converted into Visual Basic (I am only a beginner).

I am using Visual Basic 6.0 along with ADO connection.

The formula in Excel is "=YEAR(TODAY())-YEAR(E337)-IF(OR(MONTH(TODAY())<MONTH(E337),AND(MONTH(TODAY())=MONTH(E337),DAY(TODAY())<DAY(E337))),1,0)&" years, "&MONTH(TODAY())-MONTH(E337)+IF(AND(MONTH(TODAY())<=MONTH(E337),DAY(TODAY())<DAY(E337)),11,IF(AND(MONTH(TODAY())<MONTH(E337),DAY(TODAY())>=DAY(E337)),12,IF(AND(MONTH(TODAY())>MONTH(E337),DAY(TODAY())<DAY(E337)),-1)))&" months, "&TODAY()-DATE(YEAR(TODAY()),MONTH(TODAY())-IF(DAY(TODAY())<DAY(E337),1,0),DAY(E337))&" days""

I need this to be completed very soon and I appreciate any help that I can get on this question.

Looking forward to hear from you,

Thank You,

Venugopal

Calculating Time Difference
Hi Folks
I am haveing a problem calculating time differences:
I have a start time (stime) and endtime (etime), i found some code on this forum which i need to tweek to be able to calculate the time difference.
Datediff("H",stime,etime)
This works fine until say the start time (Stime) is 10pm and the end time is 2am. then the hours returned will be 20 hours.
I can't get it to recognise am and pm times or the 24 hour clock.
can anyone advise me how i can adjust this code or point me to another forum.
Thanks
nigel

Calculating Time Difference
I'm returning to a VB project after a long time away, and I've forgotten what I ever knew about times and dates. (I never knew very much, but I learned enough to develop a nice, working alarm program. Now I'm trying to add some new features.)

I need to calculate the time difference in hours and minutes between the present time and AlarmTime. Here is the existing code from which AlarmTime is derived:

Code:AlarmDisplay = Left(DataEntered, 2) & ":" & Right(DataEntered, 2) & " " & AMPM
AlarmTime = Format(AlarmDisplay, "Medium Time")

DataEntered is a string between 100 and 1259, representing a time of day. As you can see, it is used in creating AlarmDisplay, a string in the format "nn:nn AMPM", where AMPM is either "AM" or "PM", depending on previous user input.

AlarmTime is also a string. It is constantly compared with a similar string representation of the current time, and when the two are equal, the alarm goes off.

I need to know the number of hours and minutes remaining to AlarmTime.

Louis F. Sander
Pittsburgh, Pennsylvania
U.S.A.

Calculating Time Difference
I have built a small app that basically works out the difference in time between Time1 and Time2, and everything is working well except for one problem.

If Time1 is say 09:00:00 pm and Time2 is 01:00:00 am the time difference I receive is 20 hours, when it should be only 4 hours. I realise this is due to the windows system and how it handles time.

But is there a way to overcome this problem so that it will calculate correctly i.e.

If I start a 08:00:00 pm in the evening and finish at 02:00:00 am in the morning the time difference is shown as 6:00 hours and not 18:00 hours

Many thanks

Robert

Calculating With Dates?
How can I subtract a number of seconds from a certain date/time and get the resulting date?

Thanks

Calculating Dates
Hey people i seem to be having a problem with my program!

well ive made a program that by inputting a short date and adding number of days to it it calculates the result but the calculation is not correct!!!

can any1 solve the problem???!

Calculating Dates
Dear Friends,

i am using Vb 6

and i have 2 text box on a form and both are dates

and the code is :

Code:
Public date1 As Date
Public date2 As Date

Text1.Text = Format(Date, "dd-mmm-yy")
Text2.Text = Format(Date + 2, "dd-mmm-yy")

End Sub

Private Sub Text1_LostFocus()
date2 = Format(date1, "dd-mmm-yy") + 2
Text2.Text = date2

End Sub

actully what i want is, that IF Text1Box change the date Text2Box should add 1 day into it!

thanks

Calculating Between 2 Dates
Hi everyone,
i'm working with msaccess forms.
I have 2 dates: date1 - date2
For example, date1= #01/01/2003# and date2= #03/01/2004#
I used dateresult= -datediff("y",[date2],[date1]) and it's just gives me dateresult = 1
I want to get as a result the number of years, the number of months and number of days.

Calculating Dates
Hi all,
I have a question regarding dates.
I have for example 01/02/2007. I want to check to see if this date is over 6 months from today's date.

if I do #01/31/2008# - #01/02/2007# I get the number of days that have passed. I want the  munber of months not to be greater that 6.

Can someone help me?

Thanks

Ed

Calculating The Minute Difference In ACCESS
Hi All,
Can anyone tell me How to CalCulate the Difference of Minutes of a Field Value with the Current Time. I have a Table named CallBackRequest wherein I am storing the Date and Time in separate Fields. The Date is in MM/DD/YY Foramt [field name CBDate ]and Time value is stored in HH:MM Format [Field Name CBTime]. My Purpose is to extract the records by my program [VB Application ]where the Time Difference is 15 Minutes. I am Using MS Access.

I have Tried to Use DateDiff Function but got problem as the Values of CBDate and CBTime were not combined properly.
My Idea is like :
"Select * from CallBackRequest Where DateDiff(minute, Date, cbdATE + CBTime ) = 15 "

Any help is greatly appreciated.

Rishi

--

Rishi Verma,
NetEdge Computing Solutions (p)Ltd,
Janak Puri, New Delhi.

Calculating The Dates That In A Certain Week
Hello, I'm hoping somebody can help me with this. I'm trying to do the opposite to what's been posted in this thread previously: converting a date to a weeknumber.

I've got a line of code that's attempting to do this but apparently goes off somewhere as I'm getting the wrong weeks at the start of the year.
NewDayDate is the input date and WeekNum is the output:

Code:
WeekNum = Round(((NewDayDate - DateValue("1/1/" + Str(Year(NewDayDate)))) / 7) + 1, 0)

From what I've read above I should be using one of the VB constants as a reference instead of the Jan 1st that I'm using, but I cannot figure out how to sort this in a simple way. It seems as if I'm on the right track but I cannot seem to get it working properly.

Text Box And Calculating 2 Different Dates
Greetings!

I have 2 separate questions...

I know how to display the current system date into the text box using the timer control. but my questions is how do i accept user input in the text box as a date. I mean.. in which format..

Second question is how do i calculate two different dates from two text boxes to find the month. For example, i have a payment due date text box and paid date, so i want to get information of those uses who have not paid their bill for more than 1 month or 30 days...

Hope i am able to clear my questions to you.. Your prompt advice would be highly appreciated.

Regards
Aneeliyo

AneeLiyo
THAILAND - Land of Smiles
------------------------------------------------------------------------
"I may disapprove of what you say but will defend to the death your right to say it".

Calculating Future Dates
Are there any VB gurus out there that can help me to calculate dates 30 days into the future? I want to display this future date in a Word document indicating an expiration date to be 30 days from the date the document was opened. Any advice would be greatly appreciated!

Thanks.

Calculating Number Of Days Between 2 Dates
Hi,

I've got this line of code to calculate the number of days between 2 dates.
This line works fine.
Sheets("ONE").Cells(i, "C") = DateDiff("d", Sheets("ONE").Cells(i, "E"), Date)However, the results looks weird. I need to change the data type to general manually to make it looks right. Instead of a number, it's in data format. Is there a way i can format the results using VBA?

Thanks!

Calculating Dates In SQL With ADO And An Access Database
I have a VB6 application that connects to an Access database using ADO.

One of the fields (SubscribeEndDate) is a date field.

I need the SQL statement that will return all records where "Today's date" - SubscribeEndDate < 2 months.

Nothing seems to work.......

Calculating Working Hours Between 2 Dates
I need to calculate the number of working hours between two dates. I think I have seen the code on here before. If somebody has it would they please be able to repost it.

The two dates would be in DD/MM/YY HH/MM/SS format and working hours are defined as 8:30am to 5pm.

Any help would be appreciated

Thanks

Matt Brown

Calculating Values With Dates And Percentages (this Is A Biggie)
Hi

Sorry this is big request, hope this ok.

Right - I have a worksheet. Column E is start date, Column F is end date, Column G is % of time.

then in columns I1 to BH1 i have the dates 03/01/05 to 26/12/05 (mondays)

What i need to do is show using vba coding in each column the % time where date is within start to end dates

Hope this explains it right.

Thanks very much for your time

Calculating Days/hours/minutes/seconds Between 2 Dates
Hi guys,

I have 2 dates+times and want to find out how many days, hours, minutes and seconds there are between the 2.

How can i do this as im getting some odd values (the year 1899) for example.
Thanks for any help

Difference Between Two Dates
How can I find day(s), Month(s) and year(s) between two dates?

Difference Between Two Dates
I m making a project to calculate interest.So i want to calculate the no. Of months and days between two dates.So i want to know the code to differentiat two dates.(For example If i want to differentiat between 21/3/08(dd/mm/yy) and 15/5/08(dd/mm/yy) then it should return 1 month and 24 days)

Difference Between 2 Dates
What is the easiest way to write a function which will accept two dates (with time) and will return the number of days, hours, minutes and seconds between them?

VB And Getting A Difference Between Dates
Im having a major brain freeze on how I should go about doing this. I want to compare the current date and time to a date and time from a database. If the date and time from the DB is behind the current date and time by more then an hour I want to be able to take action with code Ala email or whatever.

Getting The Difference Between Two Dates In VB6
Hi All,

I am working on an application, which uses a timer consisting of the year, month, day, hour, minute and second fields.  I need to be able to find the exact difference between the two dates (one of the dates is based on the current system date and the other is inputted by the user, but will always be in the past).

I have tried using the DateDiff function, but when it comes to the seconds it displays the total number of seconds, i.e. once it gets past 60 it just continues.  I have also tried simply subtracting the dates, i.e.

CODEl_date_diff = format (l_current_date - l_end_date, "DD/MM/YYYY HH:MM:SS")

Difference Between 2 Dates
Hi,

Using VBA in MS Access, how can I find the difference between 2 dates as X years Y months and Z days.

Nandini

Difference Between Two Dates Durations
Lets say I have a date and time that is 05-01-07 01:11:11 pm. I have another date and time that is 05-05-07 05:50:55 pm.

How can I find the duration between both dates and times down to the exact seconds?

I would like to get how many days in between and the remaining of hours, minutes and seconds.

So, in this case it would be 4 days and something hour, minutes and seconds.

Thank You

How To Find Difference Between Two Dates Using Vb6
hi,
I need to find difference between two dates which one is current date and another one which i am accessing from msaccess database.
I tried my coding is
dim a,b as date
a=Format(Date\$, "dd/mm/yyyy")
b=rs!date
msgbox datediff("d", a,b)
msgbox a-b
vijaya

Coding Problem! {difference Between Two Dates}
im using 2 textbox to that containing date value. the format is mm/dd/yyyy. actually it's for rental system so the 2 textbox is txtdatestart and txtdatereturn. what i want is to get how many day i going to borrow item but i dont know the coding is. can someone please help me by giving the coding?

Date - Working The Difference Between 2 Dates
hi

i am trying to work out the difference between two dates to see how many weeks there are between the two dates

for example if i had a date 12/4/2005 and a date 19/4/2005 it should work out that theres a week difference

thanks

angel

Calculate Time Difference Between Two Dates
Hi folks!,

I need a script which can do this:
- Calculate the difference in minutes between two date/time.

I now... you are going to say that i need to use de datediff function, but here is the trick.

I need to calculate the time based on working hours using working days and time.

For example, suppose that you work monday to friday from 9:00am to 6:00pm and you have a task and you need to know how much time have you spent on it.

The task arrived at your email at 7:00pm on Sunday... so you will start to work on it at 9:00 am on Monday.

If you finish the job on Wednesday at 10:00 you had spent 19 hours on the project... datediff will say 63 hours.

Regards. German
PS: Sorry for any grammar or syntax error, englush it's not my native language.

Difference Of Dates In Number Of Months (VB)
Hi all

I know it is not much complex, but I just stuck think over again and agan

Let me to explain my problem with this example.

Let some body paid one installment on 28-08-2005, and next is due to
01-09-2005.

So the period (difference between two dates last payment date and
current date) should be calculated as 1.

Or, let some body paid on 12-07-2005 and failed to pay in Aug-2005 and nw
in Sept-2005, period / number of installments to be paid should of
calculated as 2 (One for Aug and One for Sept)

In all, I need to calculate the total number of installments to be paid n a
current date as according to the date of last installment paid.

Kindly tell me the formula.

Sincerely yours

Rajiv Kumar (DIA)

Scientific Officer/ Programmer

National Informatics Centre

Min.of Communication & IT (GOI)

O/o Deputy Commissioner-Kullu

INDIA-175101

Difference Between Two Dates, In Days... (dd/mm/yyyy)
Tring to find the difference between 2 dates.

Was originally using CDate function, now using DateDiff, however now that the dates must be formatted to 'dd/mm/yyyy' I keep getting days with a negative difference.

Sub DisplayData()

Dim pstDateIn As Date
Dim pstDateOut As Date
Dim pstTotalDays As String

With mrsCoast
'Display the data
txtBookingNumber.Text = ![BookingNumber]
txtSurname.Text = ![Surname]
txtFirstName.Text = ![FirstName]
txtStreet.Text = ![Street]
txtSuburb.Text = ![Suburb]
txtState.Text = ![State]
txtPostCode.Text = ![PostCode]
txtPhone.Text = ![Phone]
txtEmail.Text = "" & ![Em ail]

txtCabinNumber.Text = ![CabinNumber]
txtCabinTypeCode.Text = "" & ![CabinTypeCode]
txtDailyRate.Text = "" & ![DailyRate]
txtDescription.Text = ![Description]
txtDateIn.Text = Format(!DateIn, "dd/mm/yyyy")
txtDateOut.Text = Format(!DateOut, "dd/mm/yyyy")
txtBookDate.Text = ![BookDate]
txtSpecialRequirements.Text = "" & ![SpecialRequirements]
txtDepositPaid.Text = ![DepositPaid]

lblDate.Caption = Format(Now, "dd/mm/yyyy")

End With

pstDateIn = CDate(txtDateIn.Text)
pstDateOut = CDate(txtDateOut.Text)

pstTotalDays = DateDiff("d", txtDateIn, txtDateOut)
lblTotalDays.Caption = pstTotalDays

End Sub

Edit By Shandy: Line txtEmail.Text = "" & ![Em ail] has space manually added due to bug in vbCity forums scripting. i.e. the space is not really there.

Edited by - Shandy on 4/4/2004 10:58:54 PM

Finding The Difference Between Two Dates RESOLVED
I am trying to set up a Excel application.
The form connected to the workbook is fine.

However I want to have a "Main Menu" pop up first (not the issue). On the main menu I want to have how many days left before a certain date arrives.

I had set it up in Access using VBA with no problems and it works fine and displays great on the label.

In Excel it won't display on the label I don't know if I have code in the right place or not.

here is what I have in the mainmenu form....should I have put this in the workbook code?
Code:
Option Explicit

Private Sub form_initialize() '<----this should have saidi Private Sub UserForm_Activate()
Call CheckDate
'frmGuests.Hide
End Sub

Public Function CheckDate()
Dim StartDate As Date
Dim WeddingDate As Date
Dim DaysLeft As String

WeddingDate = #2/11/2005#
StartDate = Date

DaysLeft = DateDiff("d", StartDate, WeddingDate)
lblDaysLeft.Caption = DaysLeft
'lblDaysLeft = DaysLeft
txtTest.Text = DaysLeft

End Function

thanks!

Edit: The sub name was what did it....why I don't know but since changing it to UserForm_Activate it worked. I also reduced the code to what was suggested below. I had based it on what I did in Access so thought that the subs would be the same across the board in VBA!

Thanks again

Edited by - FuzzDuckie on 1/15/2004 12:00:09 PM

Calc Difference Between 2 Dates But Excluding Weekends!
Hi everyone

I want to calculate the difference (in days) between 2 dates (user will select them from a calendar). But it should exclude weekends (Saterday & Sunday).....

Thanks

Difference In Dates, But Not Counting Weekends And Public Holidays
Please help! I need to calculate the difference between two dates (in days), but not counting weekends and Public Holidays.

Difference Between ScaleHeight And Height,difference Between CurrentX And CurX?
Hi Can any one explain me briefly about Difference between scaleHeight and Height,difference between CurrentX and CurX?

I am always confusing.

Thanks.

Difference Printer Give Difference Display
I have problem here. If I use and set Microsoft Office document image writer as printer, it works find, The output and its position is acceptable. If I set the Canon as printer, The size of output result become larger. Why it would be like this?I use same code to print out the document. And I have only one print, but I can print out the paper using both printer type.

Printer.Print
Form5.MapCompactMaps.OutputMap2 Printer.hDC, 300, 400, 5000, 5000

I Want To Read Files With The Dates From Oldest To Recent (in A Directory). The Dates Are Got From E
I want to read files with the dates from oldest to recent (in a directory). the dates are got from each specific file, that is, i need to read each file to find which date is the oldest to read first (compare or sort). please give me a bit detailed code. thanx

Change Dates Formated As Text To Dates In Excel From Vb6
I have a spreadsheet with mixed dates and dates expressed in text. From VB6 I want to programtically convert all text dates to dates. I know it shoudl be simple ... Im just not getting it ...

any help appreciated!

How Can I Calculate The No Of Days Between 2 Dates, Including The Selected Dates ?
Hi all

How can I calculate the no of days between 2 dates, including the selected dates ?

for eg : between 1st Jan & 31 Jan there is 31 days

but when I calculate like this

DTPicker1.Value = 01/01/2003
DTPicker2.Value = 31/01/2003
totaldays = DTPicker2.Value - DTPicker1.Value

The result I get is 30, but in fact it should be 31

Thanks

Peters A P

Compare Dates An Find If Dates Are A Week Apart
Hi all,
i would like to compare 2 dates an do an action if they are a week apart. I tried quite a few things to no prevail.
dim date 1 as date
dim date 2 as date
if date1 ARE A WEEK APART date2 then
do some thing
else
do other thing

thanks

Kunal

Coercing Blank Dates To Look Like Dates In Excel
I have an Access table with some date/time columns. Some of these columns have blank dates. When I export this table to Excel, since the first 10 or so records for this column has blank dates, Access/Excel thinks it's a text field and so when some dates actually appear, they are prefixed with a single quote and behave like text. Then when we import this data back into another Access database, all hell breaks loose.

The original query had Code:Non-Accrual Date AsDate: IIf([Non-Accrual Date]="00/00/0000" Or [Non-Accrual Date] Is Null,Null,DateValue([Non-Accrual Date]))

I changed it to Code:Non-Accrual Date AsDate: IIf([Non-Accrual Date]="00/00/0000" Or [Non-Accrual Date] Is Null,"",DateValue([Non-Accrual Date]))

Neither way coerces the blank/null values. Any other ideas?

Postscript
The way to fix this manually in Excel is to remove all formats, the "shake the cell" by doing F2, Enter.

Code:'02/07/2002

Solution
I couldn't coerce the Excel cells, but when I re-imported the data into another database I used Code:Expr6: IIf([Non-Accrual Date AsDate] Is Null,Null,CDate([Non-Accrual Date AsDate]))

Edited by - Geof on 4/5/2006 7:07:08 AM

Dates And Ranges Of Dates
Hi All,

I am a little stumped on how to approach a problem with dates. Any help would be greatly appreciated...

SYNOPSIS
Given a start date and end date, I need to split that into a list of start and end dates based on the users choice of a Daily, Weekly, Monthly, Quarterly, or Annual.

For example, if the start date is 1/1/2005 and the end date is 12/31/2005

If user chooses DAILY Then I should get a list of 365 start and end dates
If user chooses WEEKLY Then I should get a list of 52 start and end dates
If user chooses MONTHLY Then I should get a list of 12 start and end dates
If user chooses QUARTERLY Then I should get a list of 4 start and end dates
If user chooses ANNUALLY Then I should get a list of 1 start and end date

The list of dates can be a 2-D string array since I will use them to build SQL strings.

Here is my code

dtmStartDate = CDate(Me.txtStartDate)
dtmEndDate = CDate(Me.txtEndDate)
strStartYear = Year(dtmStartDate)
strEndYear = Year(dtmEndDate)
strStartMonth = Month(dtmStartDate)
strEndMonth = Month(dtmEndDate)
strStartDay = Day(dtmStartDate)
strEndDay = Day(dtmEndDate)

'## Get a list of Time Intervals for the date range ##

Dim NumOfTimeIntervals As Long

If TimeInterval_Index = DAILY Then
NumOfTimeIntervals = DateDiff("dd", dtmStartDate, dtmEndDate)
'DOES NOT WORK (Invalild procedure call or argument)
ElseIf TimeInterval_Index = WEEKLY Then
NumOfTimeIntervals = DateDiff("ww", dtmStartDate, dtmEndDate)
'Populate array.....
ElseIf TimeInterval_Index = MONTHLY Then
NumOfTimeIntervals = DateDiff("mm", dtmStartDate, dtmEndDate)
'DOES NOT WORK (Invalild procedure call or argument)

ElseIf TimeInterval_Index = QUARTERLY Then
NumOfTimeIntervals = DateDiff("mm", dtmStartDate, dtmEndDate) / 3
'DOES NOT WORK (Invalild procedure call or argument)

ElseIf TimeInterval_Index = ANNUALLY Then
NumOfTimeIntervals = DateDiff("yyyy", dtmStartDate, dtmEndDate)
'Populate array.....

End If

For x=0 to NumOfTimeIntervals
strStartDate=ListOfDates(x,0)
strEndDate=ListOfDates(x,1)

"FROM tblPhaseData INNER JOIN tblPhaseWorkload ON tblPhaseData.Index = tblPhaseWorkload.PH_Index " & _
"WHERE tblPhaseWorkload.People_Index = " & Resource_Index & " " & _
"AND tblPhaseData.dtmPlannedStart > " & strStartDate & " " & _
"AND tblPhaseData.dtmPlannedEnd < " & strEndDate & " "

..…do some stuff……
Next x

Regards,

aragnaz

Sql To Print Dates Between Two Given Dates
any 1 help me to write sql to print dates between two given dates. ie two dates are given for example (01-12-2006 and 05-12-2006) and want to print dates like 01-12-2006
02-12-2006
03-12-2006
04-12-2006
05-12-2006

Am I Calculating FPS Right?
Here's the code:

Before the game loop:

Code:
' Used for calculating fps
TickFPS = GetTickCount
FPS = 0
At the beginning of the game loop:

Code:
Tick = GetTickCount
At the end of the loop:

Code:
'Lock FPS
Do While GetTickCount < Tick + 20
DoEvents
Loop

' Calculate fps
If GetTickCount > TickFPS + 1000 Then
GameFPS = FPS
TickFPS = GetTickCount
FPS = 0
Else
FPS = FPS + 1
End If

Call DrawSurfaceText("FPS: " & GameFPS, 200, 2)
The code for the GetTickCount function:

Code:
Public Declare Function GetTickCount Lib "kernel32" () As Long
Am I calculating the FPS right?

For some reason it's locked at 49 on my slow computer, but on fast computers it seems to be locked at 32... Any idea why?

Calculating Tax
Hello guys i;ve created windows application form for a service station, and i have little problem finising the program.I could not calculate the tax rate and number of gallons that a user put in.

Code:
public Class Form1
Dim price As Single

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim subtotal As Single
subtotal = 0
subtotal = price
Dim txtNumberGallons As Double
txtNumberGallons = txtNumberGallons * price
Dim txtTaxRate As Double = 0.06
txtTaxRate = txtTaxRate * price

If chkOil.Checked = True Then
subtotal = subtotal + 2.35

End If
If chkWindSheildWipers.Checked = True Then
subtotal = subtotal + 12.0

End If
If chkWindSheildFluid.Checked = True Then
subtotal = subtotal + 1.56

End If
If chkCoolant.Checked = True Then
subtotal = subtotal + 1.26

End If
txtTotal.Text = subtotal.ToString("\$##,##0.00")
End Sub

This code works fine but is not adding the tax for purchase or the number of gallons of gas

example if a gallon of gas price is \$ 2.95 and a person puts in 5 is \$ 14.95 but when i hit calculate it just returning \$ 2.95 please i need your guys thanks.
Edit by moderator: Please use [vb][/vb] tags for posting code.
I've also moved this to our .NET section as opposed to legacy VB.

Calculating
Im not sure if this is in the right place and i did search but did'nt find exactly what i was looking for.

I have a number of text boxes which allow a 2 digit number to be typed in. This number is the quantity of stock. Now when a button (lets call it cmdCalc) is clicked, i want it to show the total price in a label.

For example

12 desks at \$100 each
3 chairs at \$33 each
1 pen at \$1.55 each

Total should be \$1300.55 (i think...hehehe)

How do i get it to calculate this value...at the moment im using a line of code for every object...each

if len(txtdesk.text) > 0 then
lbltotal.caption = lbltotal.caption + val(txtdesk.text) * 100
end if

wat am i doing wrong?

Calculating Age
i have a variable dateofbirth which is a date, is there anyway i can use this to work out a current age(in whole years)?

Calculating BPM
OK, I need to make this program that calculates the BPM. I have no clue where to start but what i need to do is load in this text file that looks like this:
1: 465.12
2: 358.21
3: 379.75
4: 410.96
5: 383.39
6: 401.34
7: 410.96
8: 419.58
9: 430.11
10: 380.95
...etc.
I need to discard the 1:, 2:, 3:, etc. and then i need to find the average of the the numbers. Like i said i don't know where to start. Help would be very much appreciated.

Sweyko5

Calculating RPM In VB
Hi!

I need some help with calculating RPM in VB. I have a sensor connected to the serial port. Everytime the RTS signal goes high my program raises an event.

My question is :
How can I calculate RPM? I have tried with a timer and calculate how many pulses I have got from the sensor. I have set up a timer with a interval of 1000ms, and then I count all the pulses I have gotten in the last second. Then I multiply this number with 60.

The problem is that when I got i.e 3 pulses, the result will be 180, but if it is 4, then the result will be 240. This is not accurate enough for my application.
The program must do many other things as well, so the RPM code must not take too much resources.

Anyone who can help me out?

Thanks :

Svein-Arne
Skien,Norway