Results 1 to 5 of 5

Thread: DateTime problem (resolved)

  1. #1

    Thread Starter
    PowerPoster SuperSparks's Avatar
    Join Date
    May 2003
    Location
    London, England
    Posts
    265

    DateTime problem (resolved)

    I just can't seem to get my head round this one:

    VB Code:
    1. Private Sub btnAlmStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlmStart.Click
    2.  
    3.         Time1 = Now                             ' Take initial time value to add HH, MM, SS to
    4.         Hours = CInt(cmbHours.Text)             ' Assign to global variables values from combo boxes
    5.         Minutes = CInt(cmbMins.Text)
    6.         Seconds = CInt(cmbSecs.Text)
    7.         Dim TS As New TimeSpan(Hours, Minutes, Seconds)     ' Create new TimeSpan value and set it
    8.         Time1.Add(TS)                                       ' Add it to the initial time to give end time

    A couple of lines of debugging coide have shown that Time1 never gets the value of TS added to it. If anyone could point out where I'm going wrong I'd be most grateful.
    Last edited by SuperSparks; Feb 23rd, 2004 at 12:08 PM.
    Nick.

  2. #2
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    where are those variables declared? ae they public or friend scope?

  3. #3

    Thread Starter
    PowerPoster SuperSparks's Avatar
    Join Date
    May 2003
    Location
    London, England
    Posts
    265
    They're global variables for the entire project at them moment, though that may change. I put a breakpoint in and checked that everything is being properly assigned. The only thing that doesn't happen is that the TimeSpan value (which is correct) is never added to the DateTime value "Time1".
    Nick.

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    ADD is a function, not a method, meaning that Add will return the result to another variable so you have to use something like Time1=Time1.Add(TS)
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  5. #5

    Thread Starter
    PowerPoster SuperSparks's Avatar
    Join Date
    May 2003
    Location
    London, England
    Posts
    265
    That works perfectly, thanks pax
    Nick.

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