Wrox Programmer Forums
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To 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 June 8th, 2004, 05:00 AM
Authorized User
Join Date: Apr 2004
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help me How to calculate

For example : I have 2 textbox and one Timer control(Its interval=1000)
and I code it in timer Event
and Textbox2.text="14:2:20"
When I click the button I want to it display the result
Textbox1-textbox2. But I get the Error
How can I get the correct result.
Thank for your help
In sort: How to calculate between the start time and the end time
(in Minute)

Old June 8th, 2004, 06:06 AM
Friend of Wrox
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts

You cna use timevalue() function to convert this into time format and find the difference.

Om Prakash
Old June 8th, 2004, 12:45 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts

see the documentation for the DateDiff function, like

diff = DateDiff(myFormat, text1.Text, text2.text)

Old June 8th, 2004, 03:54 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG

quote:Originally posted by minhtri
and Textbox2.text="14:2:20"
In order for this to work, both textboxes must contain datatype Date/Time. If you put

Me.TextBox1 = Now()

You cannot have Me.Textbox2 = "14:2:20" because the quotes " tell me that the value is type TEXT (a string), not Date/Time. Enter it as a real time value. Then use DateDiff("n", Me.TextBox1, Me.TextBox2) for minutes or DateDiff("s", Me.TextBox1, Me.TextBox2) for seconds to get a difference.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Old June 8th, 2004, 04:06 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts

With the DateDiff() function you may want to use the CDate() function on the value of the textbox. I haven't check it out but the text box is likely to always return a string regardless of what you enter.

DateDiff("s", CDate(Me.TextBox1.Text), CDate(Me.TextBox2.Text))

It may even be a good idea to do some validation prior to working with the date as in, IsDate(Me.TextBox1.Text) etc. to ensure that you have a valid date.

Just a thought.

Larry Asher

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate time divovsky Access 2 March 15th, 2007 03:10 PM
how to calculate bandwidth debuajm C# 2005 0 January 16th, 2007 07:40 AM
Calculate ivangr Visual Basic 2005 Basics 0 April 9th, 2006 04:39 AM
calculate 2 textboxes chriskhan2000 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 December 1st, 2005 09:11 PM
How to calculate "last year"? ihsail Linux 1 December 1st, 2005 06:03 PM

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