1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Code for calculating Time difference

Discussion in 'Visual Basic ( VB )' started by viv345, Feb 22, 2010.

  1. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    I am making a chart for calculating time difference in VB (Form with textboxes is attached for your perusal) how i write code for calculating time difference.
     

    Attached Files:

  2. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    convert hours to minutes and add the minutes for both start and end
    then subtract and convert back to hours.

    for example
    start 10:34 end 12:12
    start-->10*60+34=694minutes end-->12*60+12=732minutes
    timediff=end-start=732-694=38---->0 hours 38 minutes.

    things to consider
    ================
    1) time must be in 24hr format
    2) end time must be after start time -->error message
    or you assume it belongs to the next day. (start=23:50 end=00:10) (in this case you must add 24 hours to hours)
     
  3. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Srry. I am new bee in coding but then also I have writing code like this:
    Private Sub Text14_Click()
    Text2.Text = "h"
    Text3.Text = "n"
    Text4.Text = "h"
    Text5.Text = "n"
    Text2.Text = 10 * 60 + 34 = 694
    Text4.Text = 12 * 60 + 12 = 732
    Text14.Text = timediff = Text4.Text - Text2.Text
    End Sub
     
  4. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    please correct it if their is any mistake
     
  5. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    from the code you posted i assume you are talking about
    visual basic 6.


    i made you a simple project to see how it's done.

    for questions post here.
     

    Attached Files:

  6. viv345

    viv345 New Member

    Joined:
    Feb 22, 2010
    Messages:
    76
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for your help.
     

Share This Page