Results 1 to 2 of 2

Thread: Time

  1. #1

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

    Time

    The value of TextBox1 is 10:24:23 AM and the value of TextBox2 is 11:32:54 AM.

    Dim Tim1 As Date = TextBox1.Text
    Dim Tim2 As Date = TextBox2.Text
    Dim WD As Long = DateDiff(DateInterval.Hour, Tim1, Tim2)

    But the error is;

    'DateDiff' is a namespace, and so is not a valid expression

    What's wrong with this?

  2. #2
    Lively Member flog3941's Avatar
    Join Date
    Nov 2002
    Posts
    123

    try this

    Dim tim1 as datetime
    dim tim2 as datetime
    dim wd as timespan

    'Sets the first time
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    tim1 = TimeOfDay
    TextBox1.Text=tim1
    End Sub

    'Sets the second time and returns the difference as time
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    tim2 = TimeOfDay
    TextBox2.Text= tim2
    textbox3.text = tim2.subtrct(tim1)
    End Sub

    if you want a double just use this instead of the last sub

    'Sets the second time and returns the difference as decimal
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    tim2 = TimeOfDay
    TextBox2.Text= tim2
    textbox3.text = (tim2.subtrct(tim1)).totalhours
    End Sub

    or even further to round the double to something like 0.25

    textbox3.text = math.round((tim2.subtrct(tim1)).totalhours),2)


    hope that helps!!
    Last edited by flog3941; Feb 3rd, 2003 at 01:54 PM.

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