adding time values from two textbox

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 6884 Views - Last Post: 11 October 2012 - 11:48 AM Rate Topic: -----

#16 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding time values from two textbox

Posted 11 October 2012 - 10:10 AM

is this right?
Dim timein1 As DateTime = CDate(TimeInTextBox.Text)
Dim timeout1 As DateTime = CDate(TimeOutTextBox.Text)
Was This Post Helpful? 0
  • +
  • -

#17 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding time values from two textbox

Posted 11 October 2012 - 10:19 AM

or this one?
Dim SDate1 As DateTime = DateTime.Parse(TimeInTextBox.Text)
Dim SDate2 As DateTime = DateTime.Parse(TimeOutTextBox.Text)
Was This Post Helpful? 0
  • +
  • -

#18 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1065
  • View blog
  • Posts: 4,170
  • Joined: 02-July 08

Re: adding time values from two textbox

Posted 11 October 2012 - 10:23 AM

I would use DateTime.TryParse when getting info from textboxes.
Was This Post Helpful? 0
  • +
  • -

#19 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding time values from two textbox

Posted 11 October 2012 - 10:34 AM

View Post_HAWK_, on 11 October 2012 - 10:23 AM, said:

I would use DateTime.TryParse when getting info from textboxes.

Dim SDate1 As DateTime = DateTime.TryParse(TimeInTextBox.Text)
there is an error saying overload resolution failed because no accessible 'Try Parse' accepts this number of arguments
Was This Post Helpful? 0
  • +
  • -

#20 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1623
  • View blog
  • Posts: 5,196
  • Joined: 25-September 09

Re: adding time values from two textbox

Posted 11 October 2012 - 10:52 AM

It's asking for more arguments
But...

Tryparse returns a boolean true upon success, the parameters are what you are trying to parse and what variable do you want to use upon success.

Dim myDate as DateTime
If DateTime.TryParse("05/05/2012", myDate) Then
  'Parse Successful do something with the variable
End if


So upon success myDate which you defined to be datetime now holds an actual date of 5/5/2012

This post has been edited by CharlieMay: 11 October 2012 - 10:52 AM

Was This Post Helpful? 0
  • +
  • -

#21 jhedonghae  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 119
  • Joined: 29-March 12

Re: adding time values from two textbox

Posted 11 October 2012 - 11:03 AM

View PostCharlieMay, on 11 October 2012 - 10:52 AM, said:

It's asking for more arguments
But...

Tryparse returns a boolean true upon success, the parameters are what you are trying to parse and what variable do you want to use upon success.

Dim myDate as DateTime
If DateTime.TryParse("05/05/2012", myDate) Then
  'Parse Successful do something with the variable
End if


So upon success myDate which you defined to be datetime now holds an actual date of 5/5/2012


but i don't want to assign a fixed date... what happens to the textbox?

i also tried this but i didn't get the right result

Dim SDate1 As DateTime = DateTime.Parse(TimeInTextBox.Text)
        Dim SDate2 As DateTime = DateTime.Parse(TimeOutTextBox.Text)
        TotalOTTextBox.Text = Val(SDate1) - Val(SDate2)
        TotalHWTextBox.Text = Val(SDate1) + Val(SDate2)

This post has been edited by AdamSpeight2008: 11 October 2012 - 11:39 AM

Was This Post Helpful? 0
  • +
  • -

#22 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 769
  • Joined: 19-October 11

Re: adding time values from two textbox

Posted 11 October 2012 - 11:17 AM

Instead of fixed date from example of CharlieMay, use .Text property of your TextBox.
Was This Post Helpful? 0
  • +
  • -

#23 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,498
  • Joined: 29-May 08

Re: adding time values from two textbox

Posted 11 October 2012 - 11:48 AM

View Postjhedonghae, on 11 October 2012 - 07:03 PM, said:

Dim SDate1 As DateTime = DateTime.Parse(TimeInTextBox.Text)
        Dim SDate2 As DateTime = DateTime.Parse(TimeOutTextBox.Text)
        TotalOTTextBox.Text = Val(SDate1) - Val(SDate2)
        TotalHWTextBox.Text = Val(SDate1) + Val(SDate2)

Why are using Val(SDate1) ? I is a date, and it has a - operator defined, to do the difference.

I think you should go back and learn the basics, and syntax. What a function is? What a type is? What an Object is? Controls and GUI are an advanced for a beginner, start with Console applications. As it focuses you on the design of the algorithm since there no controls.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2