22 Replies - 1444 Views - Last Post: 11 October 2012 - 11:48 AM
#1
adding time values from two textbox
Posted 11 October 2012 - 03:01 AM
Replies To: adding time values from two textbox
#4
Re: adding time values from two textbox
Posted 11 October 2012 - 06:32 AM
Public Shared Function CalculateWorkingHours(ByVal StartTime As String, ByVal EndTime As String) As String
Dim Result As String = ""
Dim StartSplit As String()
Dim EndSplit As String()
Dim StartHour As Integer
Dim StartMin As Integer
Dim EndHour As Integer
Dim EndMin As Integer
Dim WorkingHour As String
Dim WorkingMin As String
If StartTime.Contains(" am") = True Then
StartSplit = StartTime.Replace(" am", "").Split(":")
StartHour = CInt(StartSplit(0))
StartMin = CInt(StartSplit(1))
ElseIf StartTime.Contains(" pm") = True Then
StartSplit = StartTime.Replace(" pm", "").Split(":")
StartHour = CInt(StartSplit(0) + 12)
StartMin = CInt(StartSplit(1))
End If
If EndTime.Contains(" am") = True Then
EndSplit = EndTime.Replace(" am", "").Split(":")
EndHour = CInt(EndSplit(0))
EndMin = CInt(EndSplit(1))
ElseIf EndTime.Contains(" pm") = True Then
EndSplit = EndTime.Replace(" pm", "").Split(":")
EndHour = CInt(EndSplit(0) + 12)
EndMin = CInt(EndSplit(1))
End If
WorkingHour = EndHour - StartHour
WorkingMin = EndMin - StartMin
If WorkingHour.Length = 1 Then
WorkingHour = "0" & WorkingHour
End If
If WorkingMin.Length = 1 Then
WorkingMin = "0" & WorkingMin
End If
Result = WorkingHour & ":" & WorkingMin
Return Result
End Function
#5
Re: adding time values from two textbox
Posted 11 October 2012 - 07:01 AM
jhedonghae, on 11 October 2012 - 03:01 AM, said:
My first question would be "How did the times get into the TextBoxes?" If you used Now() to generate the text to go into your TextBoxes, why not change it to place the Now() values into DateTime variables. It then becomes easy to do a TimeSpan calculation using those variables. You can use Format to place the text into the TextBoxes.
Alternatively, you can create the DateTime variables on the fly and convert the TextBox text into them, then use the TimeSpan.
#6
Re: adding time values from two textbox
Posted 11 October 2012 - 08:01 AM
lar3ry, on 11 October 2012 - 07:01 AM, said:
jhedonghae, on 11 October 2012 - 03:01 AM, said:
My first question would be "How did the times get into the TextBoxes?" If you used Now() to generate the text to go into your TextBoxes, why not change it to place the Now() values into DateTime variables. It then becomes easy to do a TimeSpan calculation using those variables. You can use Format to place the text into the TextBoxes.
Alternatively, you can create the DateTime variables on the fly and convert the TextBox text into them, then use the TimeSpan.
when the user clicks the log in button the date will be added to the datetextbox and timein will be added to the timeintextbox, and when log out is click timeout will be added to the timeouttextbox.. i had attach an image so that you can understand me more..
now what i want is to fill the totalhourswork by adding the timeintextbox and timeouttextbox and subtract 1 hour for the break time
and for the overtime by subtracting the timeintextbox and timeouttextbox and subtract 1 hour for the break time
hope you understand me..please help!
lar3ry, on 11 October 2012 - 07:01 AM, said:
jhedonghae, on 11 October 2012 - 03:01 AM, said:
My first question would be "How did the times get into the TextBoxes?" If you used Now() to generate the text to go into your TextBoxes, why not change it to place the Now() values into DateTime variables. It then becomes easy to do a TimeSpan calculation using those variables. You can use Format to place the text into the TextBoxes.
Alternatively, you can create the DateTime variables on the fly and convert the TextBox text into them, then use the TimeSpan.
when the user clicks the log in button the date will be added to the datetextbox and timein will be added to the timeintextbox, and when log out is click timeout will be added to the timeouttextbox.. i had attach an image so that you can understand me more..
now what i want is to fill the totalhourswork by adding the timeintextbox and timeouttextbox and subtract 1 hour for the break time
and for the overtime by subtracting the timeintextbox and timeouttextbox and subtract 1 hour for the break time
hope you understand me..please help!
Attached image(s)
This post has been edited by jhedonghae: 11 October 2012 - 08:00 AM
#7
Re: adding time values from two textbox
Posted 11 October 2012 - 08:17 AM
research how you can convert or parse a string into a DateTime object. Remembering to think are all of possible values a string can have, are all of them convertable into time? If not how are you going to handle that?
#8
Re: adding time values from two textbox
Posted 11 October 2012 - 08:26 AM
AdamSpeight2008, on 11 October 2012 - 08:17 AM, said:
research how you can convert or parse a string into a DateTime object. Remembering to think are all of possible values a string can have, are all of them convertable into time? If not how are you going to handle that?
can you suggest me any idea to solve my problem? should i not use textbox? what should i use instead?
#9
Re: adding time values from two textbox
Posted 11 October 2012 - 08:35 AM
Stop thinking in terms of Control, there is more to programming than just controls.
Research, Experiment and make mistakes.
This post has been edited by AdamSpeight2008: 11 October 2012 - 08:49 AM
#10
Re: adding time values from two textbox
Posted 11 October 2012 - 08:44 AM
#11
Re: adding time values from two textbox
Posted 11 October 2012 - 09:25 AM
#12
Re: adding time values from two textbox
Posted 11 October 2012 - 09:38 AM
#13
Re: adding time values from two textbox
Posted 11 October 2012 - 09:42 AM
please help me
#14
Re: adding time values from two textbox
Posted 11 October 2012 - 09:42 AM
#15
Re: adding time values from two textbox
Posted 11 October 2012 - 09:54 AM
jhedonghae, on 11 October 2012 - 09:25 AM, said:
1. You don't want to add the times. 2 o'clock + 4 o'clock is meaningless.
You want to find the difference between the two times. That's best handled with a TimeSpan.
A TimeSpan works using two variables of type DateTime.
2. A TextBox is a control. You cannot calculate a difference between two controls.
3. The .Text property of TextBox contains a string.
You cannot add or subtract with a string.
You must convert a string to a number to use it in calculations.
The best form of a number to use for calculations is a DateTime variable.
I can assure you that AdamSpeight2008, CharlieMay, lucky3 and myself, have all fully understood what you are trying to do. It's just that you are insisting on trying to do something with a control that just can't be done without doing some conversions or changing the way you store the Time In and Time Out.
Please re-read what we have said. Look up the link you were given. Everything is there to point you in the right direction. Don't be afraid to try stuff. You won't break your computer with code.
|
|

New Topic/Question
Reply



MultiQuote






|