Results 1 to 4 of 4

Thread: computing time

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    computing time

    Hi I have a TextBox1, TextBox2 and TextBox3 control in my VB.NET Project.

    TextBox1.Text = 9:30:33 AM
    TextBox2.Text = 10:33:22 AM

    I put this code into the Click Event of the Button1.

    Dim TimeIn As DateTime
    Dim TimeOut As DateTime

    TimeIn = TextBox1.Text
    TimeOut = TextBox2.Text

    TextBox3.Text = Format((Int(TimeOut.Subtract(TimeIn).TotalMinutes) / 60), "hh:mm:ss")


    But this code is doesn't work well!


    The TextBox3 display "hh:mm:ss" and not "1:03:11"

    What code should I write?

  2. #2
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    Well, here's what worked for me. Instead of:
    VB Code:
    1. TextBox3.Text = Format((Int(TimeOut.Subtract(TimeIn).TotalMinutes) / 60), "hh:mm:ss"),

    Try:

    VB Code:
    1. TextBox3.Text = TimeOut.Subtract(TimeIn).ToString

    That will show the time difference in hh:mm:ss format, which is 01:02:49.
    Last edited by The Phoenix; Oct 8th, 2003 at 01:01 AM.
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441
    I've to write the code;

    TextBox3.Text = Format((Int(TimeOut.Subtract(TimeIn).TotalMinutes) / 60), "hh:mm:ss")

    But the TextBox3 display "hh:mm:ss" and not the time used!

  4. #4
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    Well, you can't format that number like that. The number that results from:

    VB Code:
    1. TextBox3.Text = Format((Int(TimeOut.Subtract(TimeIn).TotalMinutes) / 60)

    is: 1.03333333333333

    That can't be formatted into "hh:mm:ss", so I think that is the problem. You HAVE to use the code you wrote? Cause if so, I don't see how it can work that way. What exactly do you want Textbox3 to display? "1.0333..." or "01:02:49"?
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width