Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 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 May 16th, 2011, 05:45 PM
Registered User
 
Join Date: May 2011
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Time Conversion

I am Having a problem with a program I am tring to get the difference between two times and display that difference into a text box


This is the code I have

Dim Duration As DateTime
Duration = Date.FromOADate(Time_OutTextBox.Text - Time_InTextBox.Text)
Time_InTextBox.Text = Convert.ToDateTime(Time_InTextBox)
Time_OutTextBox.Text = Convert.ToDateTime(Time_OutTextBox)
Total_HoursTextBox.Text = Convert.ToDateTime(Duration)
Me.Total_HoursTextBox.Text = Convert.ToDateTime(Duration)

I keep getting this when I try to run it
Coversion from string "0:00" to type 'Double' is not valid

Can anyone Help
 
Old May 17th, 2011, 02:56 AM
Authorized User
 
Join Date: Jan 2011
Posts: 86
Thanks: 1
Thanked 12 Times in 12 Posts
Default

HI,

in the line
Code:
Duration = Date.FromOADate(Time_OutTextBox.Text - Time_InTextBox.Text)
you are substracting two strings (not DateTime objects yet!) and then call the function Date.FromOADate to convert a double to a DateTime..

If you want to do DateTime arithmetics you should first convert the strings to a DateTime:
Code:
Duration = Convert.ToDateTime(Time_OutTextBox) - Convert.ToDateTime(Time_InTextBox)
Hope this helps...

By the way, this looks like vb.net and not vb6? Then, if my answer isn't exactly what you were looking after, you could be better off posting your question in one of the .NET forums to reach those experts..





Similar Threads
Thread Thread Starter Forum Replies Last Post
synchronizing pocket pc time with desktop time bobbyrayudu83 C# 1 April 2nd, 2011 04:28 AM
Do vb exe files time out after a certain period of time? sanderson Visual Basic 2008 Essentials 0 June 11th, 2009 06:48 PM
Time Shift time in minus time out lechalas Beginning VB 6 1 August 11th, 2008 01:56 PM
String to Time conversion Neal XSLT 1 March 1st, 2006 07:51 AM
String To Time Conversion? SABmore VB.NET 2002/2003 Basics 1 February 15th, 2006 09:04 PM





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