Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old May 16th, 2011, 06: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
Reply With Quote
  #2 (permalink)  
Old May 17th, 2011, 03:56 AM
Authorized User
Points: 448, Level: 7
Points: 448, Level: 7 Points: 448, Level: 7 Points: 448, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jan 2011
Posts: 86
Thanks: 1
Thanked 12 Times in 12 Posts


in the line
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:
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..
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
synchronizing pocket pc time with desktop time bobbyrayudu83 C# 1 April 2nd, 2011 05:28 AM
Do vb exe files time out after a certain period of time? sanderson Visual Basic 2008 Essentials 0 June 11th, 2009 07:48 PM
Time Shift time in minus time out lechalas Beginning VB 6 1 August 11th, 2008 02: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

All times are GMT -4. The time now is 07:25 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.